![]() ![]() | ![]() |
Change desgin in abuotme,sylabus,simplepage
1: # The LearningOnline Network with CAPA 2: # a pile of common routines 3: # 4: # $Id: loncommon.pm,v 1.755 2009/02/25 13:25:52 neumanie Exp $ 5: # 6: # Copyright Michigan State University Board of Trustees 7: # 8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA). 9: # 10: # LON-CAPA is free software; you can redistribute it and/or modify 11: # it under the terms of the GNU General Public License as published by 12: # the Free Software Foundation; either version 2 of the License, or 13: # (at your option) any later version. 14: # 15: # LON-CAPA is distributed in the hope that it will be useful, 16: # but WITHOUT ANY WARRANTY; without even the implied warranty of 17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18: # GNU General Public License for more details. 19: # 20: # You should have received a copy of the GNU General Public License 21: # along with LON-CAPA; if not, write to the Free Software 22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23: # 24: # /home/httpd/html/adm/gpl.txt 25: # 26: # http://www.lon-capa.org/ 27: # 28: 29: # Makes a table out of the previous attempts 30: # Inputs result_from_symbread, user, domain, course_id 31: # Reads in non-network-related .tab files 32: 33: # POD header: 34: 35: =pod 36: 37: =head1 NAME 38: 39: Apache::loncommon - pile of common routines 40: 41: =head1 SYNOPSIS 42: 43: Common routines for manipulating connections, student answers, 44: domains, common Javascript fragments, etc. 45: 46: =head1 OVERVIEW 47: 48: A collection of commonly used subroutines that don't have a natural 49: home anywhere else. This collection helps remove 50: redundancy from other modules and increase efficiency of memory usage. 51: 52: =cut 53: 54: # End of POD header 55: package Apache::loncommon; 56: 57: use strict; 58: use Apache::lonnet; 59: use GDBM_File; 60: use POSIX qw(strftime mktime); 61: use Apache::lonmenu(); 62: use Apache::lonenc(); 63: use Apache::lonlocal; 64: use Apache::lonnet(); 65: use HTML::Entities; 66: use Apache::lonhtmlcommon(); 67: use Apache::loncoursedata(); 68: use Apache::lontexconvert(); 69: use Apache::lonclonecourse(); 70: use LONCAPA qw(:DEFAULT :match); 71: use DateTime::TimeZone; 72: use DateTime::Locale::Catalog; 73: 74: # ---------------------------------------------- Designs 75: use vars qw(%defaultdesign); 76: 77: my $readit; 78: 79: 80: ## 81: ## Global Variables 82: ## 83: 84: 85: # ----------------------------------------------- SSI with retries: 86: # 87: 88: =pod 89: 90: =head1 Server Side include with retries: 91: 92: =over 4 93: 94: =item * &ssi_with_retries(resource,retries form) 95: 96: Performs an ssi with some number of retries. Retries continue either 97: until the result is ok or until the retry count supplied by the 98: caller is exhausted. 99: 100: Inputs: 101: 102: =over 4 103: 104: resource - Identifies the resource to insert. 105: 106: retries - Count of the number of retries allowed. 107: 108: form - Hash that identifies the rendering options. 109: 110: =back 111: 112: Returns: 113: 114: =over 4 115: 116: content - The content of the response. If retries were exhausted this is empty. 117: 118: response - The response from the last attempt (which may or may not have been successful. 119: 120: =back 121: 122: =back 123: 124: =cut 125: 126: sub ssi_with_retries { 127: my ($resource, $retries, %form) = @_; 128: 129: 130: my $ok = 0; # True if we got a good response. 131: my $content; 132: my $response; 133: 134: # Try to get the ssi done. within the retries count: 135: 136: do { 137: ($content, $response) = &Apache::lonnet::ssi($resource, %form); 138: $ok = $response->is_success; 139: if (!$ok) { 140: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message); 141: } 142: $retries--; 143: } while (!$ok && ($retries > 0)); 144: 145: if (!$ok) { 146: $content = ''; # On error return an empty content. 147: } 148: return ($content, $response); 149: 150: } 151: 152: 153: 154: # ----------------------------------------------- Filetypes/Languages/Copyright 155: my %language; 156: my %supported_language; 157: my %cprtag; 158: my %scprtag; 159: my %fe; my %fd; my %fm; 160: my %category_extensions; 161: 162: # ---------------------------------------------- Thesaurus variables 163: # 164: # %Keywords: 165: # A hash used by &keyword to determine if a word is considered a keyword. 166: # $thesaurus_db_file 167: # Scalar containing the full path to the thesaurus database. 168: 169: my %Keywords; 170: my $thesaurus_db_file; 171: 172: # 173: # Initialize values from language.tab, copyright.tab, filetypes.tab, 174: # thesaurus.tab, and filecategories.tab. 175: # 176: BEGIN { 177: # Variable initialization 178: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db"; 179: # 180: unless ($readit) { 181: # ------------------------------------------------------------------- languages 182: { 183: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}. 184: '/language.tab'; 185: if ( open(my $fh,"<$langtabfile") ) { 186: while (my $line = <$fh>) { 187: next if ($line=~/^\#/); 188: chomp($line); 189: my ($key,$two,$country,$three,$enc,$val,$sup)=(split(/\t/,$line)); 190: $language{$key}=$val.' - '.$enc; 191: if ($sup) { 192: $supported_language{$key}=$sup; 193: } 194: } 195: close($fh); 196: } 197: } 198: # ------------------------------------------------------------------ copyrights 199: { 200: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}. 201: '/copyright.tab'; 202: if ( open (my $fh,"<$copyrightfile") ) { 203: while (my $line = <$fh>) { 204: next if ($line=~/^\#/); 205: chomp($line); 206: my ($key,$val)=(split(/\s+/,$line,2)); 207: $cprtag{$key}=$val; 208: } 209: close($fh); 210: } 211: } 212: # ----------------------------------------------------------- source copyrights 213: { 214: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}. 215: '/source_copyright.tab'; 216: if ( open (my $fh,"<$sourcecopyrightfile") ) { 217: while (my $line = <$fh>) { 218: next if ($line =~ /^\#/); 219: chomp($line); 220: my ($key,$val)=(split(/\s+/,$line,2)); 221: $scprtag{$key}=$val; 222: } 223: close($fh); 224: } 225: } 226: 227: # -------------------------------------------------------------- default domain designs 228: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors'; 229: my $designfile = $designdir.'/default.tab'; 230: if ( open (my $fh,"<$designfile") ) { 231: while (my $line = <$fh>) { 232: next if ($line =~ /^\#/); 233: chomp($line); 234: my ($key,$val)=(split(/\=/,$line)); 235: if ($val) { $defaultdesign{$key}=$val; } 236: } 237: close($fh); 238: } 239: 240: # ------------------------------------------------------------- file categories 241: { 242: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}. 243: '/filecategories.tab'; 244: if ( open (my $fh,"<$categoryfile") ) { 245: while (my $line = <$fh>) { 246: next if ($line =~ /^\#/); 247: chomp($line); 248: my ($extension,$category)=(split(/\s+/,$line,2)); 249: push @{$category_extensions{lc($category)}},$extension; 250: } 251: close($fh); 252: } 253: 254: } 255: # ------------------------------------------------------------------ file types 256: { 257: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}. 258: '/filetypes.tab'; 259: if ( open (my $fh,"<$typesfile") ) { 260: while (my $line = <$fh>) { 261: next if ($line =~ /^\#/); 262: chomp($line); 263: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4); 264: if ($descr ne '') { 265: $fe{$ending}=lc($emb); 266: $fd{$ending}=$descr; 267: if ($mime ne 'unk') { $fm{$ending}=$mime; } 268: } 269: } 270: close($fh); 271: } 272: } 273: &Apache::lonnet::logthis( 274: "<span style='color:yellow;'>INFO: Read file types</span>"); 275: $readit=1; 276: } # end of unless($readit) 277: 278: } 279: 280: ############################################################### 281: ## HTML and Javascript Helper Functions ## 282: ############################################################### 283: 284: =pod 285: 286: =head1 HTML and Javascript Functions 287: 288: =over 4 289: 290: =item * &browser_and_searcher_javascript() 291: 292: X<browsing, javascript>X<searching, javascript>Returns a string 293: containing javascript with two functions, C<openbrowser> and 294: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt> 295: tags. 296: 297: =item * &openbrowser(formname,elementname,only,omit) [javascript] 298: 299: inputs: formname, elementname, only, omit 300: 301: formname and elementname indicate the name of the html form and name of 302: the element that the results of the browsing selection are to be placed in. 303: 304: Specifying 'only' will restrict the browser to displaying only files 305: with the given extension. Can be a comma separated list. 306: 307: Specifying 'omit' will restrict the browser to NOT displaying files 308: with the given extension. Can be a comma separated list. 309: 310: =item * &opensearcher(formname,elementname) [javascript] 311: 312: Inputs: formname, elementname 313: 314: formname and elementname specify the name of the html form and the name 315: of the element the selection from the search results will be placed in. 316: 317: =cut 318: 319: sub browser_and_searcher_javascript { 320: my ($mode)=@_; 321: if (!defined($mode)) { $mode='edit'; } 322: my $resurl=&escape_single(&lastresurl()); 323: return <<END; 324: // <!-- BEGIN LON-CAPA Internal 325: var editbrowser = null; 326: function openbrowser(formname,elementname,only,omit,titleelement) { 327: var url = '$resurl/?'; 328: if (editbrowser == null) { 329: url += 'launch=1&'; 330: } 331: url += 'catalogmode=interactive&'; 332: url += 'mode=$mode&'; 333: url += 'inhibitmenu=yes&'; 334: url += 'form=' + formname + '&'; 335: if (only != null) { 336: url += 'only=' + only + '&'; 337: } else { 338: url += 'only=&'; 339: } 340: if (omit != null) { 341: url += 'omit=' + omit + '&'; 342: } else { 343: url += 'omit=&'; 344: } 345: if (titleelement != null) { 346: url += 'titleelement=' + titleelement + '&'; 347: } else { 348: url += 'titleelement=&'; 349: } 350: url += 'element=' + elementname + ''; 351: var title = 'Browser'; 352: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1'; 353: options += ',width=700,height=600'; 354: editbrowser = open(url,title,options,'1'); 355: editbrowser.focus(); 356: } 357: var editsearcher; 358: function opensearcher(formname,elementname,titleelement) { 359: var url = '/adm/searchcat?'; 360: if (editsearcher == null) { 361: url += 'launch=1&'; 362: } 363: url += 'catalogmode=interactive&'; 364: url += 'mode=$mode&'; 365: url += 'form=' + formname + '&'; 366: if (titleelement != null) { 367: url += 'titleelement=' + titleelement + '&'; 368: } else { 369: url += 'titleelement=&'; 370: } 371: url += 'element=' + elementname + ''; 372: var title = 'Search'; 373: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1'; 374: options += ',width=700,height=600'; 375: editsearcher = open(url,title,options,'1'); 376: editsearcher.focus(); 377: } 378: // END LON-CAPA Internal --> 379: END 380: } 381: 382: sub lastresurl { 383: if ($env{'environment.lastresurl'}) { 384: return $env{'environment.lastresurl'} 385: } else { 386: return '/res'; 387: } 388: } 389: 390: sub storeresurl { 391: my $resurl=&Apache::lonnet::clutter(shift); 392: unless ($resurl=~/^\/res/) { return 0; } 393: $resurl=~s/\/$//; 394: &Apache::lonnet::put('environment',{'lastresurl' => $resurl}); 395: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl}); 396: return 1; 397: } 398: 399: sub studentbrowser_javascript { 400: unless ( 401: (($env{'request.course.id'}) && 402: (&Apache::lonnet::allowed('srm',$env{'request.course.id'}) 403: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}. 404: '/'.$env{'request.course.sec'}) 405: )) 406: || ($env{'request.role'}=~/^(au|dc|su)/) 407: ) { return ''; } 408: return (<<'ENDSTDBRW'); 409: <script type="text/javascript" language="Javascript" > 410: var stdeditbrowser; 411: function openstdbrowser(formname,uname,udom,roleflag,ignorefilter) { 412: var url = '/adm/pickstudent?'; 413: var filter; 414: if (!ignorefilter) { 415: eval('filter=document.'+formname+'.'+uname+'.value;'); 416: } 417: if (filter != null) { 418: if (filter != '') { 419: url += 'filter='+filter+'&'; 420: } 421: } 422: url += 'form=' + formname + '&unameelement='+uname+ 423: '&udomelement='+udom; 424: if (roleflag) { url+="&roles=1"; } 425: var title = 'Student_Browser'; 426: var options = 'scrollbars=1,resizable=1,menubar=0'; 427: options += ',width=700,height=600'; 428: stdeditbrowser = open(url,title,options,'1'); 429: stdeditbrowser.focus(); 430: } 431: </script> 432: ENDSTDBRW 433: } 434: 435: sub selectstudent_link { 436: my ($form,$unameele,$udomele)=@_; 437: if ($env{'request.course.id'}) { 438: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'}) 439: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}. 440: '/'.$env{'request.course.sec'})) { 441: return ''; 442: } 443: return "<a href='".'javascript:openstdbrowser("'.$form.'","'.$unameele. 444: '","'.$udomele.'");'."'>".&mt('Select User')."</a>"; 445: } 446: if ($env{'request.role'}=~/^(au|dc|su)/) { 447: return "<a href='".'javascript:openstdbrowser("'.$form.'","'.$unameele. 448: '","'.$udomele.'",1);'."'>".&mt('Select User')."</a>"; 449: } 450: return ''; 451: } 452: 453: sub authorbrowser_javascript { 454: return <<"ENDAUTHORBRW"; 455: <script type="text/javascript"> 456: var stdeditbrowser; 457: 458: function openauthorbrowser(formname,udom) { 459: var url = '/adm/pickauthor?'; 460: url += 'form='+formname+'&roledom='+udom; 461: var title = 'Author_Browser'; 462: var options = 'scrollbars=1,resizable=1,menubar=0'; 463: options += ',width=700,height=600'; 464: stdeditbrowser = open(url,title,options,'1'); 465: stdeditbrowser.focus(); 466: } 467: 468: </script> 469: ENDAUTHORBRW 470: } 471: 472: sub coursebrowser_javascript { 473: my ($domainfilter,$sec_element,$formname)=@_; 474: 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'); 475: my $output = ' 476: <script type="text/javascript"> 477: var stdeditbrowser;'."\n"; 478: $output .= <<"ENDSTDBRW"; 479: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,crstype) { 480: var url = '/adm/pickcourse?'; 481: var domainfilter = ''; 482: var formid = getFormIdByName(formname); 483: if (formid > -1) { 484: var domid = getIndexByName(formid,udom); 485: if (domid > -1) { 486: if (document.forms[formid].elements[domid].type == 'select-one') { 487: domainfilter=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value; 488: } 489: if (document.forms[formid].elements[domid].type == 'hidden') { 490: domainfilter=document.forms[formid].elements[domid].value; 491: } 492: } 493: } 494: if (domainfilter != null) { 495: if (domainfilter != '') { 496: url += 'domainfilter='+domainfilter+'&'; 497: } 498: } 499: url += 'form=' + formname + '&cnumelement='+uname+ 500: '&cdomelement='+udom+ 501: '&cnameelement='+desc; 502: if (extra_element !=null && extra_element != '') { 503: if (formname == 'rolechoice' || formname == 'studentform') { 504: url += '&roleelement='+extra_element; 505: if (domainfilter == null || domainfilter == '') { 506: url += '&domainfilter='+extra_element; 507: } 508: } 509: else { 510: if (formname == 'portform') { 511: url += '&setroles='+extra_element; 512: } 513: } 514: } 515: if (multflag !=null && multflag != '') { 516: url += '&multiple='+multflag; 517: } 518: if (crstype == 'Course/Group') { 519: if (formname == 'cu') { 520: crstype = document.cu.crstype.options[document.cu.crstype.selectedIndex].value; 521: if (crstype == "") { 522: alert("$crs_or_grp_alert"); 523: return; 524: } 525: } 526: } 527: if (crstype !=null && crstype != '') { 528: url += '&type='+crstype; 529: } 530: var title = 'Course_Browser'; 531: var options = 'scrollbars=1,resizable=1,menubar=0'; 532: options += ',width=700,height=600'; 533: stdeditbrowser = open(url,title,options,'1'); 534: stdeditbrowser.focus(); 535: } 536: 537: function getFormIdByName(formname) { 538: for (var i=0;i<document.forms.length;i++) { 539: if (document.forms[i].name == formname) { 540: return i; 541: } 542: } 543: return -1; 544: } 545: 546: function getIndexByName(formid,item) { 547: for (var i=0;i<document.forms[formid].elements.length;i++) { 548: if (document.forms[formid].elements[i].name == item) { 549: return i; 550: } 551: } 552: return -1; 553: } 554: ENDSTDBRW 555: if ($sec_element ne '') { 556: $output .= &setsec_javascript($sec_element,$formname); 557: } 558: $output .= ' 559: </script>'; 560: return $output; 561: } 562: 563: sub setsec_javascript { 564: my ($sec_element,$formname) = @_; 565: my $setsections = qq| 566: function setSect(sectionlist) { 567: var sectionsArray = new Array(); 568: if ((sectionlist != '') && (typeof sectionlist != "undefined")) { 569: sectionsArray = sectionlist.split(","); 570: } 571: var numSections = sectionsArray.length; 572: document.$formname.$sec_element.length = 0; 573: if (numSections == 0) { 574: document.$formname.$sec_element.multiple=false; 575: document.$formname.$sec_element.size=1; 576: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false) 577: } else { 578: if (numSections == 1) { 579: document.$formname.$sec_element.multiple=false; 580: document.$formname.$sec_element.size=1; 581: document.$formname.$sec_element.options[0] = new Option('Select','',true,true); 582: document.$formname.$sec_element.options[1] = new Option('No section','',false,false) 583: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false); 584: } else { 585: for (var i=0; i<numSections; i++) { 586: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false) 587: } 588: document.$formname.$sec_element.multiple=true 589: if (numSections < 3) { 590: document.$formname.$sec_element.size=numSections; 591: } else { 592: document.$formname.$sec_element.size=3; 593: } 594: document.$formname.$sec_element.options[0].selected = false 595: } 596: } 597: } 598: |; 599: return $setsections; 600: } 601: 602: 603: sub selectcourse_link { 604: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype)=@_; 605: return "<a href='".'javascript:opencrsbrowser("'.$form.'","'.$unameele. 606: '","'.$udomele.'","'.$desc.'","'.$extra_element.'","'.$multflag.'","'.$selecttype.'");'."'>".&mt('Select Course')."</a>"; 607: } 608: 609: sub selectauthor_link { 610: my ($form,$udom)=@_; 611: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'. 612: &mt('Select Author').'</a>'; 613: } 614: 615: sub check_uncheck_jscript { 616: my $jscript = <<"ENDSCRT"; 617: function checkAll(field) { 618: if (field.length > 0) { 619: for (i = 0; i < field.length; i++) { 620: field[i].checked = true ; 621: } 622: } else { 623: field.checked = true 624: } 625: } 626: 627: function uncheckAll(field) { 628: if (field.length > 0) { 629: for (i = 0; i < field.length; i++) { 630: field[i].checked = false ; 631: } 632: } else { 633: field.checked = false ; 634: } 635: } 636: ENDSCRT 637: return $jscript; 638: } 639: 640: sub select_timezone { 641: my ($name,$selected,$onchange,$includeempty)=@_; 642: my $output='<select name="'.$name.'" '.$onchange.'>'."\n"; 643: if ($includeempty) { 644: $output .= '<option value=""'; 645: if (($selected eq '') || ($selected eq 'local')) { 646: $output .= ' selected="selected" '; 647: } 648: $output .= '> </option>'; 649: } 650: my @timezones = DateTime::TimeZone->all_names; 651: foreach my $tzone (@timezones) { 652: $output.= '<option value="'.$tzone.'"'; 653: if ($tzone eq $selected) { 654: $output.=' selected="selected"'; 655: } 656: $output.=">$tzone</option>\n"; 657: } 658: $output.="</select>"; 659: return $output; 660: } 661: 662: sub select_datelocale { 663: my ($name,$selected,$onchange,$includeempty)=@_; 664: my $output='<select name="'.$name.'" '.$onchange.'>'."\n"; 665: if ($includeempty) { 666: $output .= '<option value=""'; 667: if ($selected eq '') { 668: $output .= ' selected="selected" '; 669: } 670: $output .= '> </option>'; 671: } 672: my (@possibles,%locale_names); 673: my @locales = DateTime::Locale::Catalog::Locales; 674: foreach my $locale (@locales) { 675: if (ref($locale) eq 'HASH') { 676: my $id = $locale->{'id'}; 677: if ($id ne '') { 678: my $en_terr = $locale->{'en_territory'}; 679: my $native_terr = $locale->{'native_territory'}; 680: my @languages = &Apache::lonlocal::preferred_languages(); 681: if (grep(/^en$/,@languages) || !@languages) { 682: if ($en_terr ne '') { 683: $locale_names{$id} = '('.$en_terr.')'; 684: } elsif ($native_terr ne '') { 685: $locale_names{$id} = $native_terr; 686: } 687: } else { 688: if ($native_terr ne '') { 689: $locale_names{$id} = $native_terr.' '; 690: } elsif ($en_terr ne '') { 691: $locale_names{$id} = '('.$en_terr.')'; 692: } 693: } 694: push (@possibles,$id); 695: } 696: } 697: } 698: foreach my $item (sort(@possibles)) { 699: $output.= '<option value="'.$item.'"'; 700: if ($item eq $selected) { 701: $output.=' selected="selected"'; 702: } 703: $output.=">$item"; 704: if ($locale_names{$item} ne '') { 705: $output.=" $locale_names{$item}</option>\n"; 706: } 707: $output.="</option>\n"; 708: } 709: $output.="</select>"; 710: return $output; 711: } 712: 713: =pod 714: 715: =item * &linked_select_forms(...) 716: 717: linked_select_forms returns a string containing a <script></script> block 718: and html for two <select> menus. The select menus will be linked in that 719: changing the value of the first menu will result in new values being placed 720: in the second menu. The values in the select menu will appear in alphabetical 721: order unless a defined order is provided. 722: 723: linked_select_forms takes the following ordered inputs: 724: 725: =over 4 726: 727: =item * $formname, the name of the <form> tag 728: 729: =item * $middletext, the text which appears between the <select> tags 730: 731: =item * $firstdefault, the default value for the first menu 732: 733: =item * $firstselectname, the name of the first <select> tag 734: 735: =item * $secondselectname, the name of the second <select> tag 736: 737: =item * $hashref, a reference to a hash containing the data for the menus. 738: 739: =item * $menuorder, the order of values in the first menu 740: 741: =back 742: 743: Below is an example of such a hash. Only the 'text', 'default', and 744: 'select2' keys must appear as stated. keys(%menu) are the possible 745: values for the first select menu. The text that coincides with the 746: first menu value is given in $menu{$choice1}->{'text'}. The values 747: and text for the second menu are given in the hash pointed to by 748: $menu{$choice1}->{'select2'}. 749: 750: my %menu = ( A1 => { text =>"Choice A1" , 751: default => "B3", 752: select2 => { 753: B1 => "Choice B1", 754: B2 => "Choice B2", 755: B3 => "Choice B3", 756: B4 => "Choice B4" 757: }, 758: order => ['B4','B3','B1','B2'], 759: }, 760: A2 => { text =>"Choice A2" , 761: default => "C2", 762: select2 => { 763: C1 => "Choice C1", 764: C2 => "Choice C2", 765: C3 => "Choice C3" 766: }, 767: order => ['C2','C1','C3'], 768: }, 769: A3 => { text =>"Choice A3" , 770: default => "D6", 771: select2 => { 772: D1 => "Choice D1", 773: D2 => "Choice D2", 774: D3 => "Choice D3", 775: D4 => "Choice D4", 776: D5 => "Choice D5", 777: D6 => "Choice D6", 778: D7 => "Choice D7" 779: }, 780: order => ['D4','D3','D2','D1','D7','D6','D5'], 781: } 782: ); 783: 784: =cut 785: 786: sub linked_select_forms { 787: my ($formname, 788: $middletext, 789: $firstdefault, 790: $firstselectname, 791: $secondselectname, 792: $hashref, 793: $menuorder, 794: ) = @_; 795: my $second = "document.$formname.$secondselectname"; 796: my $first = "document.$formname.$firstselectname"; 797: # output the javascript to do the changing 798: my $result = ''; 799: $result.="<script type=\"text/javascript\">\n"; 800: $result.="var select2data = new Object();\n"; 801: $" = '","'; 802: my $debug = ''; 803: foreach my $s1 (sort(keys(%$hashref))) { 804: $result.="select2data.d_$s1 = new Object();\n"; 805: $result.="select2data.d_$s1.def = new String('". 806: $hashref->{$s1}->{'default'}."');\n"; 807: $result.="select2data.d_$s1.values = new Array("; 808: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } )); 809: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') { 810: @s2values = @{$hashref->{$s1}->{'order'}}; 811: } 812: $result.="\"@s2values\");\n"; 813: $result.="select2data.d_$s1.texts = new Array("; 814: my @s2texts; 815: foreach my $value (@s2values) { 816: push @s2texts, $hashref->{$s1}->{'select2'}->{$value}; 817: } 818: $result.="\"@s2texts\");\n"; 819: } 820: $"=' '; 821: $result.= <<"END"; 822: 823: function select1_changed() { 824: // Determine new choice 825: var newvalue = "d_" + $first.value; 826: // update select2 827: var values = select2data[newvalue].values; 828: var texts = select2data[newvalue].texts; 829: var select2def = select2data[newvalue].def; 830: var i; 831: // out with the old 832: for (i = 0; i < $second.options.length; i++) { 833: $second.options[i] = null; 834: } 835: // in with the nuclear 836: for (i=0;i<values.length; i++) { 837: $second.options[i] = new Option(values[i]); 838: $second.options[i].value = values[i]; 839: $second.options[i].text = texts[i]; 840: if (values[i] == select2def) { 841: $second.options[i].selected = true; 842: } 843: } 844: } 845: </script> 846: END 847: # output the initial values for the selection lists 848: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed()\">\n"; 849: my @order = sort(keys(%{$hashref})); 850: if (ref($menuorder) eq 'ARRAY') { 851: @order = @{$menuorder}; 852: } 853: foreach my $value (@order) { 854: $result.=" <option value=\"$value\" "; 855: $result.=" selected=\"selected\" " if ($value eq $firstdefault); 856: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n"; 857: } 858: $result .= "</select>\n"; 859: my %select2 = %{$hashref->{$firstdefault}->{'select2'}}; 860: $result .= $middletext; 861: $result .= "<select size=\"1\" name=\"$secondselectname\">\n"; 862: my $seconddefault = $hashref->{$firstdefault}->{'default'}; 863: 864: my @secondorder = sort(keys(%select2)); 865: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') { 866: @secondorder = @{$hashref->{$firstdefault}->{'order'}}; 867: } 868: foreach my $value (@secondorder) { 869: $result.=" <option value=\"$value\" "; 870: $result.=" selected=\"selected\" " if ($value eq $seconddefault); 871: $result.=">".&mt($select2{$value})."</option>\n"; 872: } 873: $result .= "</select>\n"; 874: # return $debug; 875: return $result; 876: } # end of sub linked_select_forms { 877: 878: =pod 879: 880: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height) 881: 882: Returns a string corresponding to an HTML link to the given help 883: $topic, where $topic corresponds to the name of a .tex file in 884: /home/httpd/html/adm/help/tex, with underscores replaced by 885: spaces. 886: 887: $text will optionally be linked to the same topic, allowing you to 888: link text in addition to the graphic. If you do not want to link 889: text, but wish to specify one of the later parameters, pass an 890: empty string. 891: 892: $stayOnPage is a value that will be interpreted as a boolean. If true, 893: the link will not open a new window. If false, the link will open 894: a new window using Javascript. (Default is false.) 895: 896: $width and $height are optional numerical parameters that will 897: override the width and height of the popped up window, which may 898: be useful for certain help topics with big pictures included. 899: 900: =cut 901: 902: sub help_open_topic { 903: my ($topic, $text, $stayOnPage, $width, $height) = @_; 904: $text = "" if (not defined $text); 905: $stayOnPage = 0 if (not defined $stayOnPage); 906: if ($env{'browser.interface'} eq 'textual') { 907: $stayOnPage=1; 908: } 909: $width = 350 if (not defined $width); 910: $height = 400 if (not defined $height); 911: my $filename = $topic; 912: $filename =~ s/ /_/g; 913: 914: my $template = ""; 915: my $link; 916: 917: $topic=~s/\W/\_/g; 918: 919: if (!$stayOnPage) { 920: $link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))"; 921: } else { 922: $link = "/adm/help/${filename}.hlp"; 923: } 924: 925: # Add the text 926: if ($text ne "") { 927: $template.="<a style=\"background-color:#3333AA;\" target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;\">$text</span></a>"; 928: } 929: 930: # Add the graphic 931: my $title = &mt('Online Help'); 932: my $helpicon=&lonhttpdurl("/adm/help/help.png"); 933: $template .= <<"ENDTEMPLATE"; 934: <a target="_top" href="$link" title="$title"><img src="$helpicon" border="0" alt="(Help: $topic)" /></a> 935: ENDTEMPLATE 936: 937: return $template; 938: 939: } 940: 941: # This is a quicky function for Latex cheatsheet editing, since it 942: # appears in at least four places 943: sub helpLatexCheatsheet { 944: my ($topic,$text,$not_author) = @_; 945: my $out; 946: my $addOther = ''; 947: if ($topic) { 948: $addOther = &Apache::loncommon::help_open_topic($topic,$text, 949: undef, undef, 600). 950: '</td><td>'; 951: } 952: $out = '<table><tr><td>'. 953: $addOther . 954: &Apache::loncommon::help_open_topic("Greek_Symbols",&mt('Greek Symbols'), 955: undef,undef,600). 956: '</td><td>'. 957: &Apache::loncommon::help_open_topic("Other_Symbols",&mt('Other Symbols'), 958: undef,undef,600). 959: '</td>'; 960: unless ($not_author) { 961: $out .= '<td>'. 962: &Apache::loncommon::help_open_topic("Authoring_Output_Tags",&mt('Output Tags'), 963: undef,undef,600). 964: '</td>'; 965: } 966: $out .= '</tr></table>'; 967: return $out; 968: } 969: 970: sub general_help { 971: my $helptopic='Student_Intro'; 972: if ($env{'request.role'}=~/^(ca|au)/) { 973: $helptopic='Authoring_Intro'; 974: } elsif ($env{'request.role'}=~/^cc/) { 975: $helptopic='Course_Coordination_Intro'; 976: } elsif ($env{'request.role'}=~/^dc/) { 977: $helptopic='Domain_Coordination_Intro'; 978: } 979: return $helptopic; 980: } 981: 982: sub update_help_link { 983: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_; 984: my $origurl = $ENV{'REQUEST_URI'}; 985: $origurl=~s|^/~|/priv/|; 986: my $timestamp = time; 987: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) { 988: $$datum = &escape($$datum); 989: } 990: 991: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage"; 992: my $output .= <<"ENDOUTPUT"; 993: <script type="text/javascript"> 994: banner_link = '$banner_link'; 995: </script> 996: ENDOUTPUT 997: return $output; 998: } 999: 1000: # now just updates the help link and generates a blue icon 1001: sub help_open_menu { 1002: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text) 1003: = @_; 1004: $stayOnPage = 0 if (not defined $stayOnPage); 1005: # only use pop-up help (stayOnPage == 0) 1006: # if environment.remote is on (using remote control UI) 1007: if ($env{'browser.interface'} eq 'textual' || 1008: $env{'environment.remote'} eq 'off' ) { 1009: $stayOnPage=1; 1010: } 1011: my $output; 1012: if ($component_help) { 1013: if (!$text) { 1014: $output=&help_open_topic($component_help,undef,$stayOnPage, 1015: $width,$height); 1016: } else { 1017: my $help_text; 1018: $help_text=&unescape($topic); 1019: $output='<table><tr><td>'. 1020: &help_open_topic($component_help,$help_text,$stayOnPage, 1021: $width,$height).'</td></tr></table>'; 1022: } 1023: } 1024: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage); 1025: return $output.$banner_link; 1026: } 1027: 1028: sub top_nav_help { 1029: my ($text) = @_; 1030: $text = &mt($text); 1031: my $stay_on_page = 1032: ($env{'browser.interface'} eq 'textual' || 1033: $env{'environment.remote'} eq 'off' ); 1034: my $link = ($stay_on_page) ? "javascript:helpMenu('display')" 1035: : "javascript:helpMenu('open')"; 1036: my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page); 1037: 1038: my $title = &mt('Get help'); 1039: 1040: return <<"END"; 1041: $banner_link 1042: <a href="$link" title="$title">$text</a> 1043: END 1044: } 1045: 1046: sub help_menu_js { 1047: my ($text) = @_; 1048: 1049: my $stayOnPage = 1050: ($env{'browser.interface'} eq 'textual' || 1051: $env{'environment.remote'} eq 'off' ); 1052: 1053: my $width = 620; 1054: my $height = 600; 1055: my $helptopic=&general_help(); 1056: my $details_link = '/adm/help/'.$helptopic.'.hlp'; 1057: my $nothing=&Apache::lonhtmlcommon::javascript_nothing(); 1058: my $start_page = 1059: &Apache::loncommon::start_page('Help Menu', undef, 1060: {'frameset' => 1, 1061: 'js_ready' => 1, 1062: 'add_entries' => { 1063: 'border' => '0', 1064: 'rows' => "110,*",},}); 1065: my $end_page = 1066: &Apache::loncommon::end_page({'frameset' => 1, 1067: 'js_ready' => 1,}); 1068: 1069: my $template .= <<"ENDTEMPLATE"; 1070: <script type="text/javascript"> 1071: // <!-- BEGIN LON-CAPA Internal 1072: // <![CDATA[ 1073: var banner_link = ''; 1074: function helpMenu(target) { 1075: var caller = this; 1076: if (target == 'open') { 1077: var newWindow = null; 1078: try { 1079: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" ) 1080: } 1081: catch(error) { 1082: writeHelp(caller); 1083: return; 1084: } 1085: if (newWindow) { 1086: caller = newWindow; 1087: } 1088: } 1089: writeHelp(caller); 1090: return; 1091: } 1092: function writeHelp(caller) { 1093: caller.document.writeln('$start_page<frame name="bannerframe" src="'+banner_link+'" /><frame name="bodyframe" src="$details_link" /> $end_page') 1094: caller.document.close() 1095: caller.focus() 1096: } 1097: // ]]> 1098: // END LON-CAPA Internal --> 1099: </script> 1100: ENDTEMPLATE 1101: return $template; 1102: } 1103: 1104: sub help_open_bug { 1105: my ($topic, $text, $stayOnPage, $width, $height) = @_; 1106: unless ($env{'user.adv'}) { return ''; } 1107: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; } 1108: $text = "" if (not defined $text); 1109: $stayOnPage = 0 if (not defined $stayOnPage); 1110: if ($env{'browser.interface'} eq 'textual' || 1111: $env{'environment.remote'} eq 'off' ) { 1112: $stayOnPage=1; 1113: } 1114: $width = 600 if (not defined $width); 1115: $height = 600 if (not defined $height); 1116: 1117: $topic=~s/\W+/\+/g; 1118: my $link=''; 1119: my $template=''; 1120: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='. 1121: &escape($ENV{'REQUEST_URI'}).'&component='.$topic; 1122: if (!$stayOnPage) 1123: { 1124: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))"; 1125: } 1126: else 1127: { 1128: $link = $url; 1129: } 1130: # Add the text 1131: if ($text ne "") 1132: { 1133: $template .= 1134: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>". 1135: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>"; 1136: } 1137: 1138: # Add the graphic 1139: my $title = &mt('Report a Bug'); 1140: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif"); 1141: $template .= <<"ENDTEMPLATE"; 1142: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a> 1143: ENDTEMPLATE 1144: if ($text ne '') { $template.='</td></tr></table>' }; 1145: return $template; 1146: 1147: } 1148: 1149: sub help_open_faq { 1150: my ($topic, $text, $stayOnPage, $width, $height) = @_; 1151: unless ($env{'user.adv'}) { return ''; } 1152: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; } 1153: $text = "" if (not defined $text); 1154: $stayOnPage = 0 if (not defined $stayOnPage); 1155: if ($env{'browser.interface'} eq 'textual' || 1156: $env{'environment.remote'} eq 'off' ) { 1157: $stayOnPage=1; 1158: } 1159: $width = 350 if (not defined $width); 1160: $height = 400 if (not defined $height); 1161: 1162: $topic=~s/\W+/\+/g; 1163: my $link=''; 1164: my $template=''; 1165: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html'; 1166: if (!$stayOnPage) 1167: { 1168: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))"; 1169: } 1170: else 1171: { 1172: $link = $url; 1173: } 1174: 1175: # Add the text 1176: if ($text ne "") 1177: { 1178: $template .= 1179: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>". 1180: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>"; 1181: } 1182: 1183: # Add the graphic 1184: my $title = &mt('View the FAQ'); 1185: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif"); 1186: $template .= <<"ENDTEMPLATE"; 1187: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a> 1188: ENDTEMPLATE 1189: if ($text ne '') { $template.='</td></tr></table>' }; 1190: return $template; 1191: 1192: } 1193: 1194: ############################################################### 1195: ############################################################### 1196: 1197: =pod 1198: 1199: =item * &change_content_javascript(): 1200: 1201: This and the next function allow you to create small sections of an 1202: otherwise static HTML page that you can update on the fly with 1203: Javascript, even in Netscape 4. 1204: 1205: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag) 1206: must be written to the HTML page once. It will prove the Javascript 1207: function "change(name, content)". Calling the change function with the 1208: name of the section 1209: you want to update, matching the name passed to C<changable_area>, and 1210: the new content you want to put in there, will put the content into 1211: that area. 1212: 1213: B<Note>: Netscape 4 only reserves enough space for the changable area 1214: to contain room for the original contents. You need to "make space" 1215: for whatever changes you wish to make, and be B<sure> to check your 1216: code in Netscape 4. This feature in Netscape 4 is B<not> powerful; 1217: it's adequate for updating a one-line status display, but little more. 1218: This script will set the space to 100% width, so you only need to 1219: worry about height in Netscape 4. 1220: 1221: Modern browsers are much less limiting, and if you can commit to the 1222: user not using Netscape 4, this feature may be used freely with 1223: pretty much any HTML. 1224: 1225: =cut 1226: 1227: sub change_content_javascript { 1228: # If we're on Netscape 4, we need to use Layer-based code 1229: if ($env{'browser.type'} eq 'netscape' && 1230: $env{'browser.version'} =~ /^4\./) { 1231: return (<<NETSCAPE4); 1232: function change(name, content) { 1233: doc = document.layers[name+"___escape"].layers[0].document; 1234: doc.open(); 1235: doc.write(content); 1236: doc.close(); 1237: } 1238: NETSCAPE4 1239: } else { 1240: # Otherwise, we need to use semi-standards-compliant code 1241: # (technically, "innerHTML" isn't standard but the equivalent 1242: # is really scary, and every useful browser supports it 1243: return (<<DOMBASED); 1244: function change(name, content) { 1245: element = document.getElementById(name); 1246: element.innerHTML = content; 1247: } 1248: DOMBASED 1249: } 1250: } 1251: 1252: =pod 1253: 1254: =item * &changable_area($name,$origContent): 1255: 1256: This provides a "changable area" that can be modified on the fly via 1257: the Javascript code provided in C<change_content_javascript>. $name is 1258: the name you will use to reference the area later; do not repeat the 1259: same name on a given HTML page more then once. $origContent is what 1260: the area will originally contain, which can be left blank. 1261: 1262: =cut 1263: 1264: sub changable_area { 1265: my ($name, $origContent) = @_; 1266: 1267: if ($env{'browser.type'} eq 'netscape' && 1268: $env{'browser.version'} =~ /^4\./) { 1269: # If this is netscape 4, we need to use the Layer tag 1270: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>"; 1271: } else { 1272: return "<span id='$name'>$origContent</span>"; 1273: } 1274: } 1275: 1276: =pod 1277: 1278: =item * &viewport_geometry_js 1279: 1280: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser. 1281: 1282: =cut 1283: 1284: 1285: sub viewport_geometry_js { 1286: return <<"GEOMETRY"; 1287: var Geometry = {}; 1288: function init_geometry() { 1289: if (Geometry.init) { return }; 1290: Geometry.init=1; 1291: if (window.innerHeight) { 1292: Geometry.getViewportHeight = function() { return window.innerHeight; }; 1293: Geometry.getViewportWidth = function() { return window.innerWidth; }; 1294: Geometry.getHorizontalScroll = function() { return window.pageXOffset; }; 1295: Geometry.getVerticalScroll = function() { return window.pageYOffset; }; 1296: } 1297: else if (document.documentElement && document.documentElement.clientHeight) { 1298: Geometry.getViewportHeight = 1299: function() { return document.documentElement.clientHeight; }; 1300: Geometry.getViewportWidth = 1301: function() { return document.documentElement.clientWidth; }; 1302: 1303: Geometry.getHorizontalScroll = 1304: function() { return document.documentElement.scrollLeft; }; 1305: Geometry.getVerticalScroll = 1306: function() { return document.documentElement.scrollTop; }; 1307: } 1308: else if (document.body.clientHeight) { 1309: Geometry.getViewportHeight = 1310: function() { return document.body.clientHeight; }; 1311: Geometry.getViewportWidth = 1312: function() { return document.body.clientWidth; }; 1313: Geometry.getHorizontalScroll = 1314: function() { return document.body.scrollLeft; }; 1315: Geometry.getVerticalScroll = 1316: function() { return document.body.scrollTop; }; 1317: } 1318: } 1319: 1320: GEOMETRY 1321: } 1322: 1323: =pod 1324: 1325: =item * &viewport_size_js() 1326: 1327: Provides a javascript function to set values of two form elements - width and height (elements are passed in as arguments to the javascript function) to the dimensions of the user's browser window. 1328: 1329: =cut 1330: 1331: sub viewport_size_js { 1332: my $geometry = &viewport_geometry_js(); 1333: return <<"DIMS"; 1334: 1335: $geometry 1336: 1337: function getViewportDims(width,height) { 1338: init_geometry(); 1339: width.value = Geometry.getViewportWidth(); 1340: height.value = Geometry.getViewportHeight(); 1341: return; 1342: } 1343: 1344: DIMS 1345: } 1346: 1347: =pod 1348: 1349: =item * &resize_textarea_js() 1350: 1351: emits the needed javascript to resize a textarea to be as big as possible 1352: 1353: creates a function resize_textrea that takes two IDs first should be 1354: the id of the element to resize, second should be the id of a div that 1355: surrounds everything that comes after the textarea, this routine needs 1356: to be attached to the <body> for the onload and onresize events. 1357: 1358: =back 1359: 1360: =cut 1361: 1362: sub resize_textarea_js { 1363: my $geometry = &viewport_geometry_js(); 1364: return <<"RESIZE"; 1365: <script type="text/javascript"> 1366: $geometry 1367: 1368: function getX(element) { 1369: var x = 0; 1370: while (element) { 1371: x += element.offsetLeft; 1372: element = element.offsetParent; 1373: } 1374: return x; 1375: } 1376: function getY(element) { 1377: var y = 0; 1378: while (element) { 1379: y += element.offsetTop; 1380: element = element.offsetParent; 1381: } 1382: return y; 1383: } 1384: 1385: 1386: function resize_textarea(textarea_id,bottom_id) { 1387: init_geometry(); 1388: var textarea = document.getElementById(textarea_id); 1389: //alert(textarea); 1390: 1391: var textarea_top = getY(textarea); 1392: var textarea_height = textarea.offsetHeight; 1393: var bottom = document.getElementById(bottom_id); 1394: var bottom_top = getY(bottom); 1395: var bottom_height = bottom.offsetHeight; 1396: var window_height = Geometry.getViewportHeight(); 1397: var fudge = 23; 1398: var new_height = window_height-fudge-textarea_top-bottom_height; 1399: if (new_height < 300) { 1400: new_height = 300; 1401: } 1402: textarea.style.height=new_height+'px'; 1403: } 1404: </script> 1405: RESIZE 1406: 1407: } 1408: 1409: =pod 1410: 1411: =head1 Excel and CSV file utility routines 1412: 1413: =over 4 1414: 1415: =cut 1416: 1417: ############################################################### 1418: ############################################################### 1419: 1420: =pod 1421: 1422: =item * &csv_translate($text) 1423: 1424: Translate $text to allow it to be output as a 'comma separated values' 1425: format. 1426: 1427: =cut 1428: 1429: ############################################################### 1430: ############################################################### 1431: sub csv_translate { 1432: my $text = shift; 1433: $text =~ s/\"/\"\"/g; 1434: $text =~ s/\n/ /g; 1435: return $text; 1436: } 1437: 1438: ############################################################### 1439: ############################################################### 1440: 1441: =pod 1442: 1443: =item * &define_excel_formats() 1444: 1445: Define some commonly used Excel cell formats. 1446: 1447: Currently supported formats: 1448: 1449: =over 4 1450: 1451: =item header 1452: 1453: =item bold 1454: 1455: =item h1 1456: 1457: =item h2 1458: 1459: =item h3 1460: 1461: =item h4 1462: 1463: =item i 1464: 1465: =item date 1466: 1467: =back 1468: 1469: Inputs: $workbook 1470: 1471: Returns: $format, a hash reference. 1472: 1473: =cut 1474: 1475: ############################################################### 1476: ############################################################### 1477: sub define_excel_formats { 1478: my ($workbook) = @_; 1479: my $format; 1480: $format->{'header'} = $workbook->add_format(bold => 1, 1481: bottom => 1, 1482: align => 'center'); 1483: $format->{'bold'} = $workbook->add_format(bold=>1); 1484: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18); 1485: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16); 1486: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14); 1487: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12); 1488: $format->{'i'} = $workbook->add_format(italic=>1); 1489: $format->{'date'} = $workbook->add_format(num_format=> 1490: 'mm/dd/yyyy hh:mm:ss'); 1491: return $format; 1492: } 1493: 1494: ############################################################### 1495: ############################################################### 1496: 1497: =pod 1498: 1499: =item * &create_workbook() 1500: 1501: Create an Excel worksheet. If it fails, output message on the 1502: request object and return undefs. 1503: 1504: Inputs: Apache request object 1505: 1506: Returns (undef) on failure, 1507: Excel worksheet object, scalar with filename, and formats 1508: from &Apache::loncommon::define_excel_formats on success 1509: 1510: =cut 1511: 1512: ############################################################### 1513: ############################################################### 1514: sub create_workbook { 1515: my ($r) = @_; 1516: # 1517: # Create the excel spreadsheet 1518: my $filename = '/prtspool/'. 1519: $env{'user.name'}.'_'.$env{'user.domain'}.'_'. 1520: time.'_'.rand(1000000000).'.xls'; 1521: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename); 1522: if (! defined($workbook)) { 1523: $r->log_error("Error creating excel spreadsheet $filename: $!"); 1524: $r->print('<p>'.&mt("Unable to create new Excel file. ". 1525: "This error has been logged. ". 1526: "Please alert your LON-CAPA administrator"). 1527: '</p>'); 1528: return (undef); 1529: } 1530: # 1531: $workbook->set_tempdir('/home/httpd/perl/tmp'); 1532: # 1533: my $format = &Apache::loncommon::define_excel_formats($workbook); 1534: return ($workbook,$filename,$format); 1535: } 1536: 1537: ############################################################### 1538: ############################################################### 1539: 1540: =pod 1541: 1542: =item * &create_text_file() 1543: 1544: Create a file to write to and eventually make available to the user. 1545: If file creation fails, outputs an error message on the request object and 1546: return undefs. 1547: 1548: Inputs: Apache request object, and file suffix 1549: 1550: Returns (undef) on failure, 1551: Filehandle and filename on success. 1552: 1553: =cut 1554: 1555: ############################################################### 1556: ############################################################### 1557: sub create_text_file { 1558: my ($r,$suffix) = @_; 1559: if (! defined($suffix)) { $suffix = 'txt'; }; 1560: my $fh; 1561: my $filename = '/prtspool/'. 1562: $env{'user.name'}.'_'.$env{'user.domain'}.'_'. 1563: time.'_'.rand(1000000000).'.'.$suffix; 1564: $fh = Apache::File->new('>/home/httpd'.$filename); 1565: if (! defined($fh)) { 1566: $r->log_error("Couldn't open $filename for output $!"); 1567: $r->print(&mt('Problems occurred in creating the output file. ' 1568: .'This error has been logged. ' 1569: .'Please alert your LON-CAPA administrator.')); 1570: } 1571: return ($fh,$filename) 1572: } 1573: 1574: 1575: =pod 1576: 1577: =back 1578: 1579: =cut 1580: 1581: ############################################################### 1582: ## Home server <option> list generating code ## 1583: ############################################################### 1584: 1585: # ------------------------------------------ 1586: 1587: sub domain_select { 1588: my ($name,$value,$multiple)=@_; 1589: my %domains=map { 1590: $_ => $_.' '. &Apache::lonnet::domain($_,'description') 1591: } &Apache::lonnet::all_domains(); 1592: if ($multiple) { 1593: $domains{''}=&mt('Any domain'); 1594: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))]; 1595: return &multiple_select_form($name,$value,4,\%domains); 1596: } else { 1597: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))]; 1598: return &select_form($name,$value,%domains); 1599: } 1600: } 1601: 1602: #------------------------------------------- 1603: 1604: =pod 1605: 1606: =head1 Routines for form select boxes 1607: 1608: =over 4 1609: 1610: =item * &multiple_select_form($name,$value,$size,$hash,$order) 1611: 1612: Returns a string containing a <select> element int multiple mode 1613: 1614: 1615: Args: 1616: $name - name of the <select> element 1617: $value - scalar or array ref of values that should already be selected 1618: $size - number of rows long the select element is 1619: $hash - the elements should be 'option' => 'shown text' 1620: (shown text should already have been &mt()) 1621: $order - (optional) array ref of the order to show the elements in 1622: 1623: =cut 1624: 1625: #------------------------------------------- 1626: sub multiple_select_form { 1627: my ($name,$value,$size,$hash,$order)=@_; 1628: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value); 1629: my $output=''; 1630: if (! defined($size)) { 1631: $size = 4; 1632: if (scalar(keys(%$hash))<4) { 1633: $size = scalar(keys(%$hash)); 1634: } 1635: } 1636: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">'; 1637: my @order; 1638: if (ref($order) eq 'ARRAY') { 1639: @order = @{$order}; 1640: } else { 1641: @order = sort(keys(%$hash)); 1642: } 1643: if (exists($$hash{'select_form_order'})) { 1644: @order = @{$$hash{'select_form_order'}}; 1645: } 1646: 1647: foreach my $key (@order) { 1648: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" '; 1649: $output.='selected="selected" ' if ($selected{$key}); 1650: $output.='>'.$hash->{$key}."</option>\n"; 1651: } 1652: $output.="</select>\n"; 1653: return $output; 1654: } 1655: 1656: #------------------------------------------- 1657: 1658: =pod 1659: 1660: =item * &select_form($defdom,$name,%hash) 1661: 1662: Returns a string containing a <select name='$name' size='1'> form to 1663: allow a user to select options from a hash option_name => displayed text. 1664: See lonrights.pm for an example invocation and use. 1665: 1666: =cut 1667: 1668: #------------------------------------------- 1669: sub select_form { 1670: my ($def,$name,%hash) = @_; 1671: my $selectform = "<select name=\"$name\" size=\"1\">\n"; 1672: my @keys; 1673: if (exists($hash{'select_form_order'})) { 1674: @keys=@{$hash{'select_form_order'}}; 1675: } else { 1676: @keys=sort(keys(%hash)); 1677: } 1678: foreach my $key (@keys) { 1679: $selectform.= 1680: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '. 1681: ($key eq $def ? 'selected="selected" ' : ''). 1682: ">".&mt($hash{$key})."</option>\n"; 1683: } 1684: $selectform.="</select>"; 1685: return $selectform; 1686: } 1687: 1688: # For display filters 1689: 1690: sub display_filter { 1691: if (!$env{'form.show'}) { $env{'form.show'}=10; } 1692: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; } 1693: return '<span class="LC_nobreak"><label>'.&mt('Records [_1]', 1694: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef, 1695: (&mt('all'),10,20,50,100,1000,10000))). 1696: '</label></span> <span class="LC_nobreak">'. 1697: &mt('Filter [_1]', 1698: &select_form($env{'form.displayfilter'}, 1699: 'displayfilter', 1700: ('currentfolder' => 'Current folder/page', 1701: 'containing' => 'Containing phrase', 1702: 'none' => 'None'))). 1703: '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></span>'; 1704: } 1705: 1706: sub gradeleveldescription { 1707: my $gradelevel=shift; 1708: my %gradelevels=(0 => 'Not specified', 1709: 1 => 'Grade 1', 1710: 2 => 'Grade 2', 1711: 3 => 'Grade 3', 1712: 4 => 'Grade 4', 1713: 5 => 'Grade 5', 1714: 6 => 'Grade 6', 1715: 7 => 'Grade 7', 1716: 8 => 'Grade 8', 1717: 9 => 'Grade 9', 1718: 10 => 'Grade 10', 1719: 11 => 'Grade 11', 1720: 12 => 'Grade 12', 1721: 13 => 'Grade 13', 1722: 14 => '100 Level', 1723: 15 => '200 Level', 1724: 16 => '300 Level', 1725: 17 => '400 Level', 1726: 18 => 'Graduate Level'); 1727: return &mt($gradelevels{$gradelevel}); 1728: } 1729: 1730: sub select_level_form { 1731: my ($deflevel,$name)=@_; 1732: unless ($deflevel) { $deflevel=0; } 1733: my $selectform = "<select name=\"$name\" size=\"1\">\n"; 1734: for (my $i=0; $i<=18; $i++) { 1735: $selectform.="<option value=\"$i\" ". 1736: ($i==$deflevel ? 'selected="selected" ' : ''). 1737: ">".&gradeleveldescription($i)."</option>\n"; 1738: } 1739: $selectform.="</select>"; 1740: return $selectform; 1741: } 1742: 1743: #------------------------------------------- 1744: 1745: =pod 1746: 1747: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$autosubmit) 1748: 1749: Returns a string containing a <select name='$name' size='1'> form to 1750: allow a user to select the domain to preform an operation in. 1751: See loncreateuser.pm for an example invocation and use. 1752: 1753: If the $includeempty flag is set, it also includes an empty choice ("no domain 1754: selected"); 1755: 1756: If the $showdomdesc flag is set, the domain name is followed by the domain description. 1757: 1758: If the $autosubmit flag is set, the form containing the domain selector will be auto-submitted by an onchange action. 1759: 1760: =cut 1761: 1762: #------------------------------------------- 1763: sub select_dom_form { 1764: my ($defdom,$name,$includeempty,$showdomdesc,$autosubmit) = @_; 1765: my $onchange; 1766: if ($autosubmit) { 1767: $onchange = ' onchange="this.form.submit()"'; 1768: } 1769: my @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains()); 1770: if ($includeempty) { @domains=('',@domains); } 1771: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n"; 1772: foreach my $dom (@domains) { 1773: $selectdomain.="<option value=\"$dom\" ". 1774: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom; 1775: if ($showdomdesc) { 1776: if ($dom ne '') { 1777: my $domdesc = &Apache::lonnet::domain($dom,'description'); 1778: if ($domdesc ne '') { 1779: $selectdomain .= ' ('.$domdesc.')'; 1780: } 1781: } 1782: } 1783: $selectdomain .= "</option>\n"; 1784: } 1785: $selectdomain.="</select>"; 1786: return $selectdomain; 1787: } 1788: 1789: #------------------------------------------- 1790: 1791: =pod 1792: 1793: =item * &home_server_form_item($domain,$name,$defaultflag) 1794: 1795: input: 4 arguments (two required, two optional) - 1796: $domain - domain of new user 1797: $name - name of form element 1798: $default - Value of 'default' causes a default item to be first 1799: option, and selected by default. 1800: $hide - Value of 'hide' causes hiding of the name of the server, 1801: if 1 server found, or default, if 0 found. 1802: output: returns 2 items: 1803: (a) form element which contains either: 1804: (i) <select name="$name"> 1805: <option value="$hostid1">$hostid $servers{$hostid}</option> 1806: <option value="$hostid2">$hostid $servers{$hostid}</option> 1807: </select> 1808: form item if there are multiple library servers in $domain, or 1809: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item 1810: if there is only one library server in $domain. 1811: 1812: (b) number of library servers found. 1813: 1814: See loncreateuser.pm for example of use. 1815: 1816: =cut 1817: 1818: #------------------------------------------- 1819: sub home_server_form_item { 1820: my ($domain,$name,$default,$hide) = @_; 1821: my %servers = &Apache::lonnet::get_servers($domain,'library'); 1822: my $result; 1823: my $numlib = keys(%servers); 1824: if ($numlib > 1) { 1825: $result .= '<select name="'.$name.'" />'."\n"; 1826: if ($default) { 1827: $result .= '<option value="default" selected>'.&mt('default'). 1828: '</option>'."\n"; 1829: } 1830: foreach my $hostid (sort(keys(%servers))) { 1831: $result.= '<option value="'.$hostid.'">'. 1832: $hostid.' '.$servers{$hostid}."</option>\n"; 1833: } 1834: $result .= '</select>'."\n"; 1835: } elsif ($numlib == 1) { 1836: my $hostid; 1837: foreach my $item (keys(%servers)) { 1838: $hostid = $item; 1839: } 1840: $result .= '<input type="hidden" name="'.$name.'" value="'. 1841: $hostid.'" />'; 1842: if (!$hide) { 1843: $result .= $hostid.' '.$servers{$hostid}; 1844: } 1845: $result .= "\n"; 1846: } elsif ($default) { 1847: $result .= '<input type="hidden" name="'.$name. 1848: '" value="default" />'; 1849: if (!$hide) { 1850: $result .= &mt('default'); 1851: } 1852: $result .= "\n"; 1853: } 1854: return ($result,$numlib); 1855: } 1856: 1857: =pod 1858: 1859: =back 1860: 1861: =cut 1862: 1863: ############################################################### 1864: ## Decoding User Agent ## 1865: ############################################################### 1866: 1867: =pod 1868: 1869: =head1 Decoding the User Agent 1870: 1871: =over 4 1872: 1873: =item * &decode_user_agent() 1874: 1875: Inputs: $r 1876: 1877: Outputs: 1878: 1879: =over 4 1880: 1881: =item * $httpbrowser 1882: 1883: =item * $clientbrowser 1884: 1885: =item * $clientversion 1886: 1887: =item * $clientmathml 1888: 1889: =item * $clientunicode 1890: 1891: =item * $clientos 1892: 1893: =back 1894: 1895: =back 1896: 1897: =cut 1898: 1899: ############################################################### 1900: ############################################################### 1901: sub decode_user_agent { 1902: my ($r)=@_; 1903: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"}); 1904: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"}); 1905: my $httpbrowser=$ENV{"HTTP_USER_AGENT"}; 1906: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); } 1907: my $clientbrowser='unknown'; 1908: my $clientversion='0'; 1909: my $clientmathml=''; 1910: my $clientunicode='0'; 1911: for (my $i=0;$i<=$#browsertype;$i++) { 1912: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]); 1913: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) { 1914: $clientbrowser=$bname; 1915: $httpbrowser=~/$vreg/i; 1916: $clientversion=$1; 1917: $clientmathml=($clientversion>=$minv); 1918: $clientunicode=($clientversion>=$univ); 1919: } 1920: } 1921: my $clientos='unknown'; 1922: if (($httpbrowser=~/linux/i) || 1923: ($httpbrowser=~/unix/i) || 1924: ($httpbrowser=~/ux/i) || 1925: ($httpbrowser=~/solaris/i)) { $clientos='unix'; } 1926: if (($httpbrowser=~/vax/i) || 1927: ($httpbrowser=~/vms/i)) { $clientos='vms'; } 1928: if ($httpbrowser=~/next/i) { $clientos='next'; } 1929: if (($httpbrowser=~/mac/i) || 1930: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; } 1931: if ($httpbrowser=~/win/i) { $clientos='win'; } 1932: if ($httpbrowser=~/embed/i) { $clientos='pda'; } 1933: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml, 1934: $clientunicode,$clientos,); 1935: } 1936: 1937: ############################################################### 1938: ## Authentication changing form generation subroutines ## 1939: ############################################################### 1940: ## 1941: ## All of the authform_xxxxxxx subroutines take their inputs in a 1942: ## hash, and have reasonable default values. 1943: ## 1944: ## formname = the name given in the <form> tag. 1945: #------------------------------------------- 1946: 1947: =pod 1948: 1949: =head1 Authentication Routines 1950: 1951: =over 4 1952: 1953: =item * &authform_xxxxxx() 1954: 1955: The authform_xxxxxx subroutines provide javascript and html forms which 1956: handle some of the conveniences required for authentication forms. 1957: This is not an optimal method, but it works. 1958: 1959: =over 4 1960: 1961: =item * authform_header 1962: 1963: =item * authform_authorwarning 1964: 1965: =item * authform_nochange 1966: 1967: =item * authform_kerberos 1968: 1969: =item * authform_internal 1970: 1971: =item * authform_filesystem 1972: 1973: =back 1974: 1975: See loncreateuser.pm for invocation and use examples. 1976: 1977: =cut 1978: 1979: #------------------------------------------- 1980: sub authform_header{ 1981: my %in = ( 1982: formname => 'cu', 1983: kerb_def_dom => '', 1984: @_, 1985: ); 1986: $in{'formname'} = 'document.' . $in{'formname'}; 1987: my $result=''; 1988: 1989: #---------------------------------------------- Code for upper case translation 1990: my $Javascript_toUpperCase; 1991: unless ($in{kerb_def_dom}) { 1992: $Javascript_toUpperCase =<<"END"; 1993: switch (choice) { 1994: case 'krb': currentform.elements[choicearg].value = 1995: currentform.elements[choicearg].value.toUpperCase(); 1996: break; 1997: default: 1998: } 1999: END 2000: } else { 2001: $Javascript_toUpperCase = ""; 2002: } 2003: 2004: my $radioval = "'nochange'"; 2005: if (defined($in{'curr_authtype'})) { 2006: if ($in{'curr_authtype'} ne '') { 2007: $radioval = "'".$in{'curr_authtype'}."arg'"; 2008: } 2009: } 2010: my $argfield = 'null'; 2011: if (defined($in{'mode'})) { 2012: if ($in{'mode'} eq 'modifycourse') { 2013: if (defined($in{'curr_autharg'})) { 2014: if ($in{'curr_autharg'} ne '') { 2015: $argfield = "'$in{'curr_autharg'}'"; 2016: } 2017: } 2018: } 2019: } 2020: 2021: $result.=<<"END"; 2022: var current = new Object(); 2023: current.radiovalue = $radioval; 2024: current.argfield = $argfield; 2025: 2026: function changed_radio(choice,currentform) { 2027: var choicearg = choice + 'arg'; 2028: // If a radio button in changed, we need to change the argfield 2029: if (current.radiovalue != choice) { 2030: current.radiovalue = choice; 2031: if (current.argfield != null) { 2032: currentform.elements[current.argfield].value = ''; 2033: } 2034: if (choice == 'nochange') { 2035: current.argfield = null; 2036: } else { 2037: current.argfield = choicearg; 2038: switch(choice) { 2039: case 'krb': 2040: currentform.elements[current.argfield].value = 2041: "$in{'kerb_def_dom'}"; 2042: break; 2043: default: 2044: break; 2045: } 2046: } 2047: } 2048: return; 2049: } 2050: 2051: function changed_text(choice,currentform) { 2052: var choicearg = choice + 'arg'; 2053: if (currentform.elements[choicearg].value !='') { 2054: $Javascript_toUpperCase 2055: // clear old field 2056: if ((current.argfield != choicearg) && (current.argfield != null)) { 2057: currentform.elements[current.argfield].value = ''; 2058: } 2059: current.argfield = choicearg; 2060: } 2061: set_auth_radio_buttons(choice,currentform); 2062: return; 2063: } 2064: 2065: function set_auth_radio_buttons(newvalue,currentform) { 2066: var i=0; 2067: while (i < currentform.login.length) { 2068: if (currentform.login[i].value == newvalue) { break; } 2069: i++; 2070: } 2071: if (i == currentform.login.length) { 2072: return; 2073: } 2074: current.radiovalue = newvalue; 2075: currentform.login[i].checked = true; 2076: return; 2077: } 2078: END 2079: return $result; 2080: } 2081: 2082: sub authform_authorwarning{ 2083: my $result=''; 2084: $result='<i>'. 2085: &mt('As a general rule, only authors or co-authors should be '. 2086: 'filesystem authenticated '. 2087: '(which allows access to the server filesystem).')."</i>\n"; 2088: return $result; 2089: } 2090: 2091: sub authform_nochange{ 2092: my %in = ( 2093: formname => 'document.cu', 2094: kerb_def_dom => 'MSU.EDU', 2095: @_, 2096: ); 2097: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'}); 2098: my $result; 2099: if (keys(%can_assign) == 0) { 2100: $result = &mt('Under you current role you are not permitted to change login settings for this user'); 2101: } else { 2102: $result = '<label>'.&mt('[_1] Do not change login data', 2103: '<input type="radio" name="login" value="nochange" '. 2104: 'checked="checked" onclick="'. 2105: "javascript:changed_radio('nochange',$in{'formname'});".'" />'). 2106: '</label>'; 2107: } 2108: return $result; 2109: } 2110: 2111: sub authform_kerberos { 2112: my %in = ( 2113: formname => 'document.cu', 2114: kerb_def_dom => 'MSU.EDU', 2115: kerb_def_auth => 'krb4', 2116: @_, 2117: ); 2118: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype, 2119: $autharg,$jscall); 2120: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'}); 2121: if ($in{'kerb_def_auth'} eq 'krb5') { 2122: $check5 = ' checked="on"'; 2123: } else { 2124: $check4 = ' checked="on"'; 2125: } 2126: $krbarg = $in{'kerb_def_dom'}; 2127: if (defined($in{'curr_authtype'})) { 2128: if ($in{'curr_authtype'} eq 'krb') { 2129: $krbcheck = ' checked="on"'; 2130: if (defined($in{'mode'})) { 2131: if ($in{'mode'} eq 'modifyuser') { 2132: $krbcheck = ''; 2133: } 2134: } 2135: if (defined($in{'curr_kerb_ver'})) { 2136: if ($in{'curr_krb_ver'} eq '5') { 2137: $check5 = ' checked="on"'; 2138: $check4 = ''; 2139: } else { 2140: $check4 = ' checked="on"'; 2141: $check5 = ''; 2142: } 2143: } 2144: if (defined($in{'curr_autharg'})) { 2145: $krbarg = $in{'curr_autharg'}; 2146: } 2147: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) { 2148: if (defined($in{'curr_autharg'})) { 2149: $result = 2150: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].', 2151: $in{'curr_autharg'},$krbver); 2152: } else { 2153: $result = 2154: &mt('Currently Kerberos authenticated, Version [_1].',$krbver); 2155: } 2156: return $result; 2157: } 2158: } 2159: } else { 2160: if ($authnum == 1) { 2161: $authtype = '<input type="hidden" name="login" value="krb">'; 2162: } 2163: } 2164: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) { 2165: return; 2166: } elsif ($authtype eq '') { 2167: if (defined($in{'mode'})) { 2168: if ($in{'mode'} eq 'modifycourse') { 2169: if ($authnum == 1) { 2170: $authtype = '<input type="hidden" name="login" value="krb">'; 2171: } 2172: } 2173: } 2174: } 2175: $jscall = "javascript:changed_radio('krb',$in{'formname'});"; 2176: if ($authtype eq '') { 2177: $authtype = '<input type="radio" name="login" value="krb" '. 2178: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'. 2179: $krbcheck.' />'; 2180: } 2181: if (($can_assign{'krb4'} && $can_assign{'krb5'}) || 2182: ($can_assign{'krb4'} && !$can_assign{'krb5'} && 2183: $in{'curr_authtype'} eq 'krb5') || 2184: (!$can_assign{'krb4'} && $can_assign{'krb5'} && 2185: $in{'curr_authtype'} eq 'krb4')) { 2186: $result .= &mt 2187: ('[_1] Kerberos authenticated with domain [_2] '. 2188: '[_3] Version 4 [_4] Version 5 [_5]', 2189: '<label>'.$authtype, 2190: '</label><input type="text" size="10" name="krbarg" '. 2191: 'value="'.$krbarg.'" '. 2192: 'onchange="'.$jscall.'" />', 2193: '<label><input type="radio" name="krbver" value="4" '.$check4.' />', 2194: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />', 2195: '</label>'); 2196: } elsif ($can_assign{'krb4'}) { 2197: $result .= &mt 2198: ('[_1] Kerberos authenticated with domain [_2] '. 2199: '[_3] Version 4 [_4]', 2200: '<label>'.$authtype, 2201: '</label><input type="text" size="10" name="krbarg" '. 2202: 'value="'.$krbarg.'" '. 2203: 'onchange="'.$jscall.'" />', 2204: '<label><input type="hidden" name="krbver" value="4" />', 2205: '</label>'); 2206: } elsif ($can_assign{'krb5'}) { 2207: $result .= &mt 2208: ('[_1] Kerberos authenticated with domain [_2] '. 2209: '[_3] Version 5 [_4]', 2210: '<label>'.$authtype, 2211: '</label><input type="text" size="10" name="krbarg" '. 2212: 'value="'.$krbarg.'" '. 2213: 'onchange="'.$jscall.'" />', 2214: '<label><input type="hidden" name="krbver" value="5" />', 2215: '</label>'); 2216: } 2217: return $result; 2218: } 2219: 2220: sub authform_internal{ 2221: my %in = ( 2222: formname => 'document.cu', 2223: kerb_def_dom => 'MSU.EDU', 2224: @_, 2225: ); 2226: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall); 2227: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'}); 2228: if (defined($in{'curr_authtype'})) { 2229: if ($in{'curr_authtype'} eq 'int') { 2230: if ($can_assign{'int'}) { 2231: $intcheck = 'checked="on" '; 2232: if (defined($in{'mode'})) { 2233: if ($in{'mode'} eq 'modifyuser') { 2234: $intcheck = ''; 2235: } 2236: } 2237: if (defined($in{'curr_autharg'})) { 2238: $intarg = $in{'curr_autharg'}; 2239: } 2240: } else { 2241: $result = &mt('Currently internally authenticated.'); 2242: return $result; 2243: } 2244: } 2245: } else { 2246: if ($authnum == 1) { 2247: $authtype = '<input type="hidden" name="login" value="int">'; 2248: } 2249: } 2250: if (!$can_assign{'int'}) { 2251: return; 2252: } elsif ($authtype eq '') { 2253: if (defined($in{'mode'})) { 2254: if ($in{'mode'} eq 'modifycourse') { 2255: if ($authnum == 1) { 2256: $authtype = '<input type="hidden" name="login" value="int">'; 2257: } 2258: } 2259: } 2260: } 2261: $jscall = "javascript:changed_radio('int',$in{'formname'});"; 2262: if ($authtype eq '') { 2263: $authtype = '<input type="radio" name="login" value="int" '.$intcheck. 2264: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />'; 2265: } 2266: $autharg = '<input type="password" size="10" name="intarg" value="'. 2267: $intarg.'" onchange="'.$jscall.'" />'; 2268: $result = &mt 2269: ('[_1] Internally authenticated (with initial password [_2])', 2270: '<label>'.$authtype,'</label>'.$autharg); 2271: $result.="<label><input type=\"checkbox\" name=\"visible\" onClick='if (this.checked) { this.form.intarg.type=\"text\" } else { this.form.intarg.type=\"password\" }' />".&mt('Visible input').'</label>'; 2272: return $result; 2273: } 2274: 2275: sub authform_local{ 2276: my %in = ( 2277: formname => 'document.cu', 2278: kerb_def_dom => 'MSU.EDU', 2279: @_, 2280: ); 2281: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall); 2282: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'}); 2283: if (defined($in{'curr_authtype'})) { 2284: if ($in{'curr_authtype'} eq 'loc') { 2285: if ($can_assign{'loc'}) { 2286: $loccheck = 'checked="on" '; 2287: if (defined($in{'mode'})) { 2288: if ($in{'mode'} eq 'modifyuser') { 2289: $loccheck = ''; 2290: } 2291: } 2292: if (defined($in{'curr_autharg'})) { 2293: $locarg = $in{'curr_autharg'}; 2294: } 2295: } else { 2296: $result = &mt('Currently using local (institutional) authentication.'); 2297: return $result; 2298: } 2299: } 2300: } else { 2301: if ($authnum == 1) { 2302: $authtype = '<input type="hidden" name="login" value="loc">'; 2303: } 2304: } 2305: if (!$can_assign{'loc'}) { 2306: return; 2307: } elsif ($authtype eq '') { 2308: if (defined($in{'mode'})) { 2309: if ($in{'mode'} eq 'modifycourse') { 2310: if ($authnum == 1) { 2311: $authtype = '<input type="hidden" name="login" value="loc">'; 2312: } 2313: } 2314: } 2315: } 2316: $jscall = "javascript:changed_radio('loc',$in{'formname'});"; 2317: if ($authtype eq '') { 2318: $authtype = '<input type="radio" name="login" value="loc" '. 2319: $loccheck.' onchange="'.$jscall.'" onclick="'. 2320: $jscall.'" />'; 2321: } 2322: $autharg = '<input type="text" size="10" name="locarg" value="'. 2323: $locarg.'" onchange="'.$jscall.'" />'; 2324: $result = &mt('[_1] Local Authentication with argument [_2]', 2325: '<label>'.$authtype,'</label>'.$autharg); 2326: return $result; 2327: } 2328: 2329: sub authform_filesystem{ 2330: my %in = ( 2331: formname => 'document.cu', 2332: kerb_def_dom => 'MSU.EDU', 2333: @_, 2334: ); 2335: my ($fsyscheck,$result,$authtype,$autharg,$jscall); 2336: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'}); 2337: if (defined($in{'curr_authtype'})) { 2338: if ($in{'curr_authtype'} eq 'fsys') { 2339: if ($can_assign{'fsys'}) { 2340: $fsyscheck = 'checked="on" '; 2341: if (defined($in{'mode'})) { 2342: if ($in{'mode'} eq 'modifyuser') { 2343: $fsyscheck = ''; 2344: } 2345: } 2346: } else { 2347: $result = &mt('Currently Filesystem Authenticated.'); 2348: return $result; 2349: } 2350: } 2351: } else { 2352: if ($authnum == 1) { 2353: $authtype = '<input type="hidden" name="login" value="fsys">'; 2354: } 2355: } 2356: if (!$can_assign{'fsys'}) { 2357: return; 2358: } elsif ($authtype eq '') { 2359: if (defined($in{'mode'})) { 2360: if ($in{'mode'} eq 'modifycourse') { 2361: if ($authnum == 1) { 2362: $authtype = '<input type="hidden" name="login" value="fsys">'; 2363: } 2364: } 2365: } 2366: } 2367: $jscall = "javascript:changed_radio('fsys',$in{'formname'});"; 2368: if ($authtype eq '') { 2369: $authtype = '<input type="radio" name="login" value="fsys" '. 2370: $fsyscheck.' onchange="'.$jscall.'" onclick="'. 2371: $jscall.'" />'; 2372: } 2373: $autharg = '<input type="text" size="10" name="fsysarg" value=""'. 2374: ' onchange="'.$jscall.'" />'; 2375: $result = &mt 2376: ('[_1] Filesystem Authenticated (with initial password [_2])', 2377: '<label><input type="radio" name="login" value="fsys" '. 2378: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />', 2379: '</label><input type="password" size="10" name="fsysarg" value="" '. 2380: 'onchange="'.$jscall.'" />'); 2381: return $result; 2382: } 2383: 2384: sub get_assignable_auth { 2385: my ($dom) = @_; 2386: if ($dom eq '') { 2387: $dom = $env{'request.role.domain'}; 2388: } 2389: my %can_assign = ( 2390: krb4 => 1, 2391: krb5 => 1, 2392: int => 1, 2393: loc => 1, 2394: ); 2395: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom); 2396: if (ref($domconfig{'usercreation'}) eq 'HASH') { 2397: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') { 2398: my $authhash = $domconfig{'usercreation'}{'authtypes'}; 2399: my $context; 2400: if ($env{'request.role'} =~ /^au/) { 2401: $context = 'author'; 2402: } elsif ($env{'request.role'} =~ /^dc/) { 2403: $context = 'domain'; 2404: } elsif ($env{'request.course.id'}) { 2405: $context = 'course'; 2406: } 2407: if ($context) { 2408: if (ref($authhash->{$context}) eq 'HASH') { 2409: %can_assign = %{$authhash->{$context}}; 2410: } 2411: } 2412: } 2413: } 2414: my $authnum = 0; 2415: foreach my $key (keys(%can_assign)) { 2416: if ($can_assign{$key}) { 2417: $authnum ++; 2418: } 2419: } 2420: if ($can_assign{'krb4'} && $can_assign{'krb5'}) { 2421: $authnum --; 2422: } 2423: return ($authnum,%can_assign); 2424: } 2425: 2426: ############################################################### 2427: ## Get Kerberos Defaults for Domain ## 2428: ############################################################### 2429: ## 2430: ## Returns default kerberos version and an associated argument 2431: ## as listed in file domain.tab. If not listed, provides 2432: ## appropriate default domain and kerberos version. 2433: ## 2434: #------------------------------------------- 2435: 2436: =pod 2437: 2438: =item * &get_kerberos_defaults() 2439: 2440: get_kerberos_defaults($target_domain) returns the default kerberos 2441: version and domain. If not found, it defaults to version 4 and the 2442: domain of the server. 2443: 2444: =over 4 2445: 2446: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain); 2447: 2448: =back 2449: 2450: =back 2451: 2452: =cut 2453: 2454: #------------------------------------------- 2455: sub get_kerberos_defaults { 2456: my $domain=shift; 2457: my ($krbdef,$krbdefdom); 2458: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain); 2459: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) { 2460: $krbdef = $domdefaults{'auth_def'}; 2461: $krbdefdom = $domdefaults{'auth_arg_def'}; 2462: } else { 2463: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/; 2464: my $krbdefdom=$1; 2465: $krbdefdom=~tr/a-z/A-Z/; 2466: $krbdef = "krb4"; 2467: } 2468: return ($krbdef,$krbdefdom); 2469: } 2470: 2471: 2472: ############################################################### 2473: ## Thesaurus Functions ## 2474: ############################################################### 2475: 2476: =pod 2477: 2478: =head1 Thesaurus Functions 2479: 2480: =over 4 2481: 2482: =item * &initialize_keywords() 2483: 2484: Initializes the package variable %Keywords if it is empty. Uses the 2485: package variable $thesaurus_db_file. 2486: 2487: =cut 2488: 2489: ################################################### 2490: 2491: sub initialize_keywords { 2492: return 1 if (scalar keys(%Keywords)); 2493: # If we are here, %Keywords is empty, so fill it up 2494: # Make sure the file we need exists... 2495: if (! -e $thesaurus_db_file) { 2496: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file". 2497: " failed because it does not exist"); 2498: return 0; 2499: } 2500: # Set up the hash as a database 2501: my %thesaurus_db; 2502: if (! tie(%thesaurus_db,'GDBM_File', 2503: $thesaurus_db_file,&GDBM_READER(),0640)){ 2504: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ". 2505: $thesaurus_db_file); 2506: return 0; 2507: } 2508: # Get the average number of appearances of a word. 2509: my $avecount = $thesaurus_db{'average.count'}; 2510: # Put keywords (those that appear > average) into %Keywords 2511: while (my ($word,$data)=each (%thesaurus_db)) { 2512: my ($count,undef) = split /:/,$data; 2513: $Keywords{$word}++ if ($count > $avecount); 2514: } 2515: untie %thesaurus_db; 2516: # Remove special values from %Keywords. 2517: foreach my $value ('total.count','average.count') { 2518: delete($Keywords{$value}) if (exists($Keywords{$value})); 2519: } 2520: return 1; 2521: } 2522: 2523: ################################################### 2524: 2525: =pod 2526: 2527: =item * &keyword($word) 2528: 2529: Returns true if $word is a keyword. A keyword is a word that appears more 2530: than the average number of times in the thesaurus database. Calls 2531: &initialize_keywords 2532: 2533: =cut 2534: 2535: ################################################### 2536: 2537: sub keyword { 2538: return if (!&initialize_keywords()); 2539: my $word=lc(shift()); 2540: $word=~s/\W//g; 2541: return exists($Keywords{$word}); 2542: } 2543: 2544: ############################################################### 2545: 2546: =pod 2547: 2548: =item * &get_related_words() 2549: 2550: Look up a word in the thesaurus. Takes a scalar argument and returns 2551: an array of words. If the keyword is not in the thesaurus, an empty array 2552: will be returned. The order of the words returned is determined by the 2553: database which holds them. 2554: 2555: Uses global $thesaurus_db_file. 2556: 2557: =cut 2558: 2559: ############################################################### 2560: sub get_related_words { 2561: my $keyword = shift; 2562: my %thesaurus_db; 2563: if (! -e $thesaurus_db_file) { 2564: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ". 2565: "failed because the file does not exist"); 2566: return (); 2567: } 2568: if (! tie(%thesaurus_db,'GDBM_File', 2569: $thesaurus_db_file,&GDBM_READER(),0640)){ 2570: return (); 2571: } 2572: my @Words=(); 2573: my $count=0; 2574: if (exists($thesaurus_db{$keyword})) { 2575: # The first element is the number of times 2576: # the word appears. We do not need it now. 2577: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword})); 2578: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]); 2579: my $threshold=$mostfrequentcount/10; 2580: foreach my $possibleword (@RelatedWords) { 2581: my ($word,$wordcount)=split(/\,/,$possibleword); 2582: if ($wordcount>$threshold) { 2583: push(@Words,$word); 2584: $count++; 2585: if ($count>10) { last; } 2586: } 2587: } 2588: } 2589: untie %thesaurus_db; 2590: return @Words; 2591: } 2592: 2593: =pod 2594: 2595: =back 2596: 2597: =cut 2598: 2599: # -------------------------------------------------------------- Plaintext name 2600: =pod 2601: 2602: =head1 User Name Functions 2603: 2604: =over 4 2605: 2606: =item * &plainname($uname,$udom,$first) 2607: 2608: Takes a users logon name and returns it as a string in 2609: "first middle last generation" form 2610: if $first is set to 'lastname' then it returns it as 2611: 'lastname generation, firstname middlename' if their is a lastname 2612: 2613: =cut 2614: 2615: 2616: ############################################################### 2617: sub plainname { 2618: my ($uname,$udom,$first)=@_; 2619: return if (!defined($uname) || !defined($udom)); 2620: my %names=&getnames($uname,$udom); 2621: my $name=&Apache::lonnet::format_name($names{'firstname'}, 2622: $names{'middlename'}, 2623: $names{'lastname'}, 2624: $names{'generation'},$first); 2625: $name=~s/^\s+//; 2626: $name=~s/\s+$//; 2627: $name=~s/\s+/ /g; 2628: if ($name !~ /\S/) { $name=$uname.':'.$udom; } 2629: return $name; 2630: } 2631: 2632: # -------------------------------------------------------------------- Nickname 2633: =pod 2634: 2635: =item * &nickname($uname,$udom) 2636: 2637: Gets a users name and returns it as a string as 2638: 2639: ""nickname"" 2640: 2641: if the user has a nickname or 2642: 2643: "first middle last generation" 2644: 2645: if the user does not 2646: 2647: =cut 2648: 2649: sub nickname { 2650: my ($uname,$udom)=@_; 2651: return if (!defined($uname) || !defined($udom)); 2652: my %names=&getnames($uname,$udom); 2653: my $name=$names{'nickname'}; 2654: if ($name) { 2655: $name='"'.$name.'"'; 2656: } else { 2657: $name=$names{'firstname'}.' '.$names{'middlename'}.' '. 2658: $names{'lastname'}.' '.$names{'generation'}; 2659: $name=~s/\s+$//; 2660: $name=~s/\s+/ /g; 2661: } 2662: return $name; 2663: } 2664: 2665: sub getnames { 2666: my ($uname,$udom)=@_; 2667: return if (!defined($uname) || !defined($udom)); 2668: if ($udom eq 'public' && $uname eq 'public') { 2669: return ('lastname' => &mt('Public')); 2670: } 2671: my $id=$uname.':'.$udom; 2672: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id); 2673: if ($cached) { 2674: return %{$names}; 2675: } else { 2676: my %loadnames=&Apache::lonnet::get('environment', 2677: ['firstname','middlename','lastname','generation','nickname'], 2678: $udom,$uname); 2679: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames); 2680: return %loadnames; 2681: } 2682: } 2683: 2684: # -------------------------------------------------------------------- getemails 2685: 2686: =pod 2687: 2688: =item * &getemails($uname,$udom) 2689: 2690: Gets a user's email information and returns it as a hash with keys: 2691: notification, critnotification, permanentemail 2692: 2693: For notification and critnotification, values are comma-separated lists 2694: of e-mail addresses; for permanentemail, value is a single e-mail address. 2695: 2696: 2697: =cut 2698: 2699: 2700: sub getemails { 2701: my ($uname,$udom)=@_; 2702: if ($udom eq 'public' && $uname eq 'public') { 2703: return; 2704: } 2705: if (!$udom) { $udom=$env{'user.domain'}; } 2706: if (!$uname) { $uname=$env{'user.name'}; } 2707: my $id=$uname.':'.$udom; 2708: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id); 2709: if ($cached) { 2710: return %{$names}; 2711: } else { 2712: my %loadnames=&Apache::lonnet::get('environment', 2713: ['notification','critnotification', 2714: 'permanentemail'], 2715: $udom,$uname); 2716: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames); 2717: return %loadnames; 2718: } 2719: } 2720: 2721: sub flush_email_cache { 2722: my ($uname,$udom)=@_; 2723: if (!$udom) { $udom =$env{'user.domain'}; } 2724: if (!$uname) { $uname=$env{'user.name'}; } 2725: return if ($udom eq 'public' && $uname eq 'public'); 2726: my $id=$uname.':'.$udom; 2727: &Apache::lonnet::devalidate_cache_new('emailscache',$id); 2728: } 2729: 2730: # -------------------------------------------------------------------- getlangs 2731: 2732: =pod 2733: 2734: =item * &getlangs($uname,$udom) 2735: 2736: Gets a user's language preference and returns it as a hash with key: 2737: language. 2738: 2739: =cut 2740: 2741: 2742: sub getlangs { 2743: my ($uname,$udom) = @_; 2744: if (!$udom) { $udom =$env{'user.domain'}; } 2745: if (!$uname) { $uname=$env{'user.name'}; } 2746: my $id=$uname.':'.$udom; 2747: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id); 2748: if ($cached) { 2749: return %{$langs}; 2750: } else { 2751: my %loadlangs=&Apache::lonnet::get('environment',['languages'], 2752: $udom,$uname); 2753: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs); 2754: return %loadlangs; 2755: } 2756: } 2757: 2758: sub flush_langs_cache { 2759: my ($uname,$udom)=@_; 2760: if (!$udom) { $udom =$env{'user.domain'}; } 2761: if (!$uname) { $uname=$env{'user.name'}; } 2762: return if ($udom eq 'public' && $uname eq 'public'); 2763: my $id=$uname.':'.$udom; 2764: &Apache::lonnet::devalidate_cache_new('userlangs',$id); 2765: } 2766: 2767: # ------------------------------------------------------------------ Screenname 2768: 2769: =pod 2770: 2771: =item * &screenname($uname,$udom) 2772: 2773: Gets a users screenname and returns it as a string 2774: 2775: =cut 2776: 2777: sub screenname { 2778: my ($uname,$udom)=@_; 2779: if ($uname eq $env{'user.name'} && 2780: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};} 2781: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname); 2782: return $names{'screenname'}; 2783: } 2784: 2785: 2786: # ------------------------------------------------------------- Message Wrapper 2787: 2788: sub messagewrapper { 2789: my ($link,$username,$domain,$subject,$text)=@_; 2790: return 2791: '<a href="/adm/email?compose=individual&'. 2792: 'recname='.$username.'&recdom='.$domain. 2793: '&subject='.&escape($subject).'&text='.&escape($text).'" '. 2794: 'title="'.&mt('Send message').'">'.$link.'</a>'; 2795: } 2796: # --------------------------------------------------------------- Notes Wrapper 2797: 2798: sub noteswrapper { 2799: my ($link,$un,$do)=@_; 2800: return 2801: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>"; 2802: } 2803: # ------------------------------------------------------------- Aboutme Wrapper 2804: 2805: sub aboutmewrapper { 2806: my ($link,$username,$domain,$target)=@_; 2807: if (!defined($username) && !defined($domain)) { 2808: return; 2809: } 2810: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'. 2811: ($target?' target="$target"':'').' title="'.&mt("View this user's personal 2812: homepage").'">'.$link.'</a>'; 2813: } 2814: 2815: # ------------------------------------------------------------ Syllabus Wrapper 2816: 2817: 2818: sub syllabuswrapper { 2819: my ($linktext,$coursedir,$domain)=@_; 2820: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>}; 2821: } 2822: 2823: sub track_student_link { 2824: my ($linktext,$sname,$sdom,$target,$start) = @_; 2825: my $link ="/adm/trackstudent?"; 2826: my $title = 'View recent activity'; 2827: if (defined($sname) && $sname !~ /^\s*$/ && 2828: defined($sdom) && $sdom !~ /^\s*$/) { 2829: $link .= "selected_student=$sname:$sdom"; 2830: $title .= ' of this student'; 2831: } 2832: if (defined($target) && $target !~ /^\s*$/) { 2833: $target = qq{target="$target"}; 2834: } else { 2835: $target = ''; 2836: } 2837: if ($start) { $link.='&start='.$start; } 2838: $title = &mt($title); 2839: $linktext = &mt($linktext); 2840: return qq{<a href="$link" title="$title" $target>$linktext</a>}. 2841: &help_open_topic('View_recent_activity'); 2842: } 2843: 2844: # ===================================================== Display a student photo 2845: 2846: 2847: sub student_image_tag { 2848: my ($domain,$user)=@_; 2849: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg'); 2850: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) { 2851: return '<img src="'.$imgsrc.'" align="right" />'; 2852: } else { 2853: return ''; 2854: } 2855: } 2856: 2857: =pod 2858: 2859: =back 2860: 2861: =head1 Access .tab File Data 2862: 2863: =over 4 2864: 2865: =item * &languageids() 2866: 2867: returns list of all language ids 2868: 2869: =cut 2870: 2871: sub languageids { 2872: return sort(keys(%language)); 2873: } 2874: 2875: =pod 2876: 2877: =item * &languagedescription() 2878: 2879: returns description of a specified language id 2880: 2881: =cut 2882: 2883: sub languagedescription { 2884: my $code=shift; 2885: return ($supported_language{$code}?'* ':''). 2886: $language{$code}. 2887: ($supported_language{$code}?' ('.&mt('interface available').')':''); 2888: } 2889: 2890: sub plainlanguagedescription { 2891: my $code=shift; 2892: return $language{$code}; 2893: } 2894: 2895: sub supportedlanguagecode { 2896: my $code=shift; 2897: return $supported_language{$code}; 2898: } 2899: 2900: =pod 2901: 2902: =item * ©rightids() 2903: 2904: returns list of all copyrights 2905: 2906: =cut 2907: 2908: sub copyrightids { 2909: return sort(keys(%cprtag)); 2910: } 2911: 2912: =pod 2913: 2914: =item * ©rightdescription() 2915: 2916: returns description of a specified copyright id 2917: 2918: =cut 2919: 2920: sub copyrightdescription { 2921: return &mt($cprtag{shift(@_)}); 2922: } 2923: 2924: =pod 2925: 2926: =item * &source_copyrightids() 2927: 2928: returns list of all source copyrights 2929: 2930: =cut 2931: 2932: sub source_copyrightids { 2933: return sort(keys(%scprtag)); 2934: } 2935: 2936: =pod 2937: 2938: =item * &source_copyrightdescription() 2939: 2940: returns description of a specified source copyright id 2941: 2942: =cut 2943: 2944: sub source_copyrightdescription { 2945: return &mt($scprtag{shift(@_)}); 2946: } 2947: 2948: =pod 2949: 2950: =item * &filecategories() 2951: 2952: returns list of all file categories 2953: 2954: =cut 2955: 2956: sub filecategories { 2957: return sort(keys(%category_extensions)); 2958: } 2959: 2960: =pod 2961: 2962: =item * &filecategorytypes() 2963: 2964: returns list of file types belonging to a given file 2965: category 2966: 2967: =cut 2968: 2969: sub filecategorytypes { 2970: my ($cat) = @_; 2971: return @{$category_extensions{lc($cat)}}; 2972: } 2973: 2974: =pod 2975: 2976: =item * &fileembstyle() 2977: 2978: returns embedding style for a specified file type 2979: 2980: =cut 2981: 2982: sub fileembstyle { 2983: return $fe{lc(shift(@_))}; 2984: } 2985: 2986: sub filemimetype { 2987: return $fm{lc(shift(@_))}; 2988: } 2989: 2990: 2991: sub filecategoryselect { 2992: my ($name,$value)=@_; 2993: return &select_form($value,$name, 2994: '' => &mt('Any category'), 2995: map { $_,$_ } sort(keys(%category_extensions))); 2996: } 2997: 2998: =pod 2999: 3000: =item * &filedescription() 3001: 3002: returns description for a specified file type 3003: 3004: =cut 3005: 3006: sub filedescription { 3007: my $file_description = $fd{lc(shift())}; 3008: $file_description =~ s:([\[\]]):~$1:g; 3009: return &mt($file_description); 3010: } 3011: 3012: =pod 3013: 3014: =item * &filedescriptionex() 3015: 3016: returns description for a specified file type with 3017: extra formatting 3018: 3019: =cut 3020: 3021: sub filedescriptionex { 3022: my $ex=shift; 3023: my $file_description = $fd{lc($ex)}; 3024: $file_description =~ s:([\[\]]):~$1:g; 3025: return '.'.$ex.' '.&mt($file_description); 3026: } 3027: 3028: # End of .tab access 3029: =pod 3030: 3031: =back 3032: 3033: =cut 3034: 3035: # ------------------------------------------------------------------ File Types 3036: sub fileextensions { 3037: return sort(keys(%fe)); 3038: } 3039: 3040: # ----------------------------------------------------------- Display Languages 3041: # returns a hash with all desired display languages 3042: # 3043: 3044: sub display_languages { 3045: my %languages=(); 3046: foreach my $lang (&Apache::lonlocal::preferred_languages()) { 3047: $languages{$lang}=1; 3048: } 3049: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']); 3050: if ($env{'form.displaylanguage'}) { 3051: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) { 3052: $languages{$lang}=1; 3053: } 3054: } 3055: return %languages; 3056: } 3057: 3058: sub languages { 3059: my ($possible_langs) = @_; 3060: my @preferred_langs = &Apache::lonlocal::preferred_languages(); 3061: if (!ref($possible_langs)) { 3062: if( wantarray ) { 3063: return @preferred_langs; 3064: } else { 3065: return $preferred_langs[0]; 3066: } 3067: } 3068: my %possibilities = map { $_ => 1 } (@$possible_langs); 3069: my @preferred_possibilities; 3070: foreach my $preferred_lang (@preferred_langs) { 3071: if (exists($possibilities{$preferred_lang})) { 3072: push(@preferred_possibilities, $preferred_lang); 3073: } 3074: } 3075: if( wantarray ) { 3076: return @preferred_possibilities; 3077: } 3078: return $preferred_possibilities[0]; 3079: } 3080: 3081: sub user_lang { 3082: my ($touname,$toudom,$fromcid) = @_; 3083: my @userlangs; 3084: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) { 3085: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/, 3086: $env{'course.'.$fromcid.'.languages'})); 3087: } else { 3088: my %langhash = &getlangs($touname,$toudom); 3089: if ($langhash{'languages'} ne '') { 3090: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'}); 3091: } else { 3092: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom); 3093: if ($domdefs{'lang_def'} ne '') { 3094: @userlangs = ($domdefs{'lang_def'}); 3095: } 3096: } 3097: } 3098: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs); 3099: my $user_lh = Apache::localize->get_handle(@languages); 3100: return $user_lh; 3101: } 3102: 3103: 3104: ############################################################### 3105: ## Student Answer Attempts ## 3106: ############################################################### 3107: 3108: =pod 3109: 3110: =head1 Alternate Problem Views 3111: 3112: =over 4 3113: 3114: =item * &get_previous_attempt($symb, $username, $domain, $course, 3115: $getattempt, $regexp, $gradesub) 3116: 3117: Return string with previous attempt on problem. Arguments: 3118: 3119: =over 4 3120: 3121: =item * $symb: Problem, including path 3122: 3123: =item * $username: username of the desired student 3124: 3125: =item * $domain: domain of the desired student 3126: 3127: =item * $course: Course ID 3128: 3129: =item * $getattempt: Leave blank for all attempts, otherwise put 3130: something 3131: 3132: =item * $regexp: if string matches this regexp, the string will be 3133: sent to $gradesub 3134: 3135: =item * $gradesub: routine that processes the string if it matches $regexp 3136: 3137: =back 3138: 3139: The output string is a table containing all desired attempts, if any. 3140: 3141: =cut 3142: 3143: sub get_previous_attempt { 3144: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_; 3145: my $prevattempts=''; 3146: no strict 'refs'; 3147: if ($symb) { 3148: my (%returnhash)= 3149: &Apache::lonnet::restore($symb,$course,$domain,$username); 3150: if ($returnhash{'version'}) { 3151: my %lasthash=(); 3152: my $version; 3153: for ($version=1;$version<=$returnhash{'version'};$version++) { 3154: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) { 3155: $lasthash{$key}=$returnhash{$version.':'.$key}; 3156: } 3157: } 3158: $prevattempts=&start_data_table().&start_data_table_header_row(); 3159: $prevattempts.='<th>'.&mt('History').'</th>'; 3160: foreach my $key (sort(keys(%lasthash))) { 3161: my ($ign,@parts) = split(/\./,$key); 3162: if ($#parts > 0) { 3163: my $data=$parts[-1]; 3164: pop(@parts); 3165: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>'; 3166: } else { 3167: if ($#parts == 0) { 3168: $prevattempts.='<th>'.$parts[0].'</th>'; 3169: } else { 3170: $prevattempts.='<th>'.$ign.'</th>'; 3171: } 3172: } 3173: } 3174: $prevattempts.=&end_data_table_header_row(); 3175: if ($getattempt eq '') { 3176: for ($version=1;$version<=$returnhash{'version'};$version++) { 3177: $prevattempts.=&start_data_table_row(). 3178: '<td>'.&mt('Transaction [_1]',$version).'</td>'; 3179: foreach my $key (sort(keys(%lasthash))) { 3180: my $value = &format_previous_attempt_value($key, 3181: $returnhash{$version.':'.$key}); 3182: $prevattempts.='<td>'.$value.' </td>'; 3183: } 3184: $prevattempts.=&end_data_table_row(); 3185: } 3186: } 3187: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>'; 3188: foreach my $key (sort(keys(%lasthash))) { 3189: my $value = &format_previous_attempt_value($key,$lasthash{$key}); 3190: if ($key =~/$regexp$/ && (defined &$gradesub)) {$value = &$gradesub($value)} 3191: $prevattempts.='<td>'.$value.' </td>'; 3192: } 3193: $prevattempts.= &end_data_table_row().&end_data_table(); 3194: } else { 3195: $prevattempts= 3196: &start_data_table().&start_data_table_row(). 3197: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'. 3198: &end_data_table_row().&end_data_table(); 3199: } 3200: } else { 3201: $prevattempts= 3202: &start_data_table().&start_data_table_row(). 3203: '<td>'.&mt('No data.').'</td>'. 3204: &end_data_table_row().&end_data_table(); 3205: } 3206: } 3207: 3208: sub format_previous_attempt_value { 3209: my ($key,$value) = @_; 3210: if ($key =~ /timestamp/) { 3211: $value = &Apache::lonlocal::locallocaltime($value); 3212: } elsif (ref($value) eq 'ARRAY') { 3213: $value = '('.join(', ', @{ $value }).')'; 3214: } else { 3215: $value = &unescape($value); 3216: } 3217: return $value; 3218: } 3219: 3220: 3221: sub relative_to_absolute { 3222: my ($url,$output)=@_; 3223: my $parser=HTML::TokeParser->new(\$output); 3224: my $token; 3225: my $thisdir=$url; 3226: my @rlinks=(); 3227: while ($token=$parser->get_token) { 3228: if ($token->[0] eq 'S') { 3229: if ($token->[1] eq 'a') { 3230: if ($token->[2]->{'href'}) { 3231: $rlinks[$#rlinks+1]=$token->[2]->{'href'}; 3232: } 3233: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) { 3234: $rlinks[$#rlinks+1]=$token->[2]->{'src'}; 3235: } elsif ($token->[1] eq 'base') { 3236: $thisdir=$token->[2]->{'href'}; 3237: } 3238: } 3239: } 3240: $thisdir=~s-/[^/]*$--; 3241: foreach my $link (@rlinks) { 3242: unless (($link=~/^https?\:\/\//i) || 3243: ($link=~/^\//) || 3244: ($link=~/^javascript:/i) || 3245: ($link=~/^mailto:/i) || 3246: ($link=~/^\#/)) { 3247: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link); 3248: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/; 3249: } 3250: } 3251: # -------------------------------------------------- Deal with Applet codebases 3252: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei; 3253: return $output; 3254: } 3255: 3256: =pod 3257: 3258: =item * &get_student_view() 3259: 3260: show a snapshot of what student was looking at 3261: 3262: =cut 3263: 3264: sub get_student_view { 3265: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_; 3266: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb); 3267: my (%form); 3268: my @elements=('symb','courseid','domain','username'); 3269: foreach my $element (@elements) { 3270: $form{'grade_'.$element}=eval '$'.$element #' 3271: } 3272: if (defined($moreenv)) { 3273: %form=(%form,%{$moreenv}); 3274: } 3275: if (defined($target)) { $form{'grade_target'} = $target; } 3276: $feedurl=&Apache::lonnet::clutter($feedurl); 3277: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form); 3278: $userview=~s/\<body[^\>]*\>//gi; 3279: $userview=~s/\<\/body\>//gi; 3280: $userview=~s/\<html\>//gi; 3281: $userview=~s/\<\/html\>//gi; 3282: $userview=~s/\<head\>//gi; 3283: $userview=~s/\<\/head\>//gi; 3284: $userview=~s/action\s*\=/would_be_action\=/gi; 3285: $userview=&relative_to_absolute($feedurl,$userview); 3286: if (wantarray) { 3287: return ($userview,$response); 3288: } else { 3289: return $userview; 3290: } 3291: } 3292: 3293: sub get_student_view_with_retries { 3294: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_; 3295: 3296: my $ok = 0; # True if we got a good response. 3297: my $content; 3298: my $response; 3299: 3300: # Try to get the student_view done. within the retries count: 3301: 3302: do { 3303: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv); 3304: $ok = $response->is_success; 3305: if (!$ok) { 3306: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message); 3307: } 3308: $retries--; 3309: } while (!$ok && ($retries > 0)); 3310: 3311: if (!$ok) { 3312: $content = ''; # On error return an empty content. 3313: } 3314: if (wantarray) { 3315: return ($content, $response); 3316: } else { 3317: return $content; 3318: } 3319: } 3320: 3321: =pod 3322: 3323: =item * &get_student_answers() 3324: 3325: show a snapshot of how student was answering problem 3326: 3327: =cut 3328: 3329: sub get_student_answers { 3330: my ($symb,$username,$domain,$courseid,%form) = @_; 3331: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb); 3332: my (%moreenv); 3333: my @elements=('symb','courseid','domain','username'); 3334: foreach my $element (@elements) { 3335: $moreenv{'grade_'.$element}=eval '$'.$element #' 3336: } 3337: $moreenv{'grade_target'}='answer'; 3338: %moreenv=(%form,%moreenv); 3339: $feedurl = &Apache::lonnet::clutter($feedurl); 3340: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv); 3341: return $userview; 3342: } 3343: 3344: =pod 3345: 3346: =item * &submlink() 3347: 3348: Inputs: $text $uname $udom $symb $target 3349: 3350: Returns: A link to grades.pm such as to see the SUBM view of a student 3351: 3352: =cut 3353: 3354: ############################################### 3355: sub submlink { 3356: my ($text,$uname,$udom,$symb,$target)=@_; 3357: if (!($uname && $udom)) { 3358: (my $cursymb, my $courseid,$udom,$uname)= 3359: &Apache::lonnet::whichuser($symb); 3360: if (!$symb) { $symb=$cursymb; } 3361: } 3362: if (!$symb) { $symb=&Apache::lonnet::symbread(); } 3363: $symb=&escape($symb); 3364: if ($target) { $target="target=\"$target\""; } 3365: return '<a href="/adm/grades?&command=submission&'. 3366: 'symb='.$symb.'&student='.$uname. 3367: '&userdom='.$udom.'" '.$target.'>'.$text.'</a>'; 3368: } 3369: ############################################## 3370: 3371: =pod 3372: 3373: =item * &pgrdlink() 3374: 3375: Inputs: $text $uname $udom $symb $target 3376: 3377: Returns: A link to grades.pm such as to see the PGRD view of a student 3378: 3379: =cut 3380: 3381: ############################################### 3382: sub pgrdlink { 3383: my $link=&submlink(@_); 3384: $link=~s/(&command=submission)/$1&showgrading=yes/; 3385: return $link; 3386: } 3387: ############################################## 3388: 3389: =pod 3390: 3391: =item * &pprmlink() 3392: 3393: Inputs: $text $uname $udom $symb $target 3394: 3395: Returns: A link to parmset.pm such as to see the PPRM view of a 3396: student and a specific resource 3397: 3398: =cut 3399: 3400: ############################################### 3401: sub pprmlink { 3402: my ($text,$uname,$udom,$symb,$target)=@_; 3403: if (!($uname && $udom)) { 3404: (my $cursymb, my $courseid,$udom,$uname)= 3405: &Apache::lonnet::whichuser($symb); 3406: if (!$symb) { $symb=$cursymb; } 3407: } 3408: if (!$symb) { $symb=&Apache::lonnet::symbread(); } 3409: $symb=&escape($symb); 3410: if ($target) { $target="target=\"$target\""; } 3411: return '<a href="/adm/parmset?command=set&'. 3412: 'symb='.$symb.'&uname='.$uname. 3413: '&udom='.$udom.'" '.$target.'>'.$text.'</a>'; 3414: } 3415: ############################################## 3416: 3417: =pod 3418: 3419: =back 3420: 3421: =cut 3422: 3423: ############################################### 3424: 3425: 3426: sub timehash { 3427: my ($thistime) = @_; 3428: my $timezone = &Apache::lonlocal::gettimezone(); 3429: my $dt = DateTime->from_epoch(epoch => $thistime) 3430: ->set_time_zone($timezone); 3431: my $wday = $dt->day_of_week(); 3432: if ($wday == 7) { $wday = 0; } 3433: return ( 'second' => $dt->second(), 3434: 'minute' => $dt->minute(), 3435: 'hour' => $dt->hour(), 3436: 'day' => $dt->day_of_month(), 3437: 'month' => $dt->month(), 3438: 'year' => $dt->year(), 3439: 'weekday' => $wday, 3440: 'dayyear' => $dt->day_of_year(), 3441: 'dlsav' => $dt->is_dst() ); 3442: } 3443: 3444: sub utc_string { 3445: my ($date)=@_; 3446: return strftime("%Y%m%dT%H%M%SZ",gmtime($date)); 3447: } 3448: 3449: sub maketime { 3450: my %th=@_; 3451: my ($epoch_time,$timezone,$dt); 3452: $timezone = &Apache::lonlocal::gettimezone(); 3453: eval { 3454: $dt = DateTime->new( year => $th{'year'}, 3455: month => $th{'month'}, 3456: day => $th{'day'}, 3457: hour => $th{'hour'}, 3458: minute => $th{'minute'}, 3459: second => $th{'second'}, 3460: time_zone => $timezone, 3461: ); 3462: }; 3463: if (!$@) { 3464: $epoch_time = $dt->epoch; 3465: if ($epoch_time) { 3466: return $epoch_time; 3467: } 3468: } 3469: return POSIX::mktime( 3470: ($th{'seconds'},$th{'minutes'},$th{'hours'}, 3471: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1)); 3472: } 3473: 3474: ######################################### 3475: 3476: sub findallcourses { 3477: my ($roles,$uname,$udom) = @_; 3478: my %roles; 3479: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; } 3480: my %courses; 3481: my $now=time; 3482: if (!defined($uname)) { 3483: $uname = $env{'user.name'}; 3484: } 3485: if (!defined($udom)) { 3486: $udom = $env{'user.domain'}; 3487: } 3488: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) { 3489: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname); 3490: if (!%roles) { 3491: %roles = ( 3492: cc => 1, 3493: in => 1, 3494: ep => 1, 3495: ta => 1, 3496: cr => 1, 3497: st => 1, 3498: ); 3499: } 3500: foreach my $entry (keys(%roleshash)) { 3501: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry}); 3502: if ($trole =~ /^cr/) { 3503: next if (!exists($roles{$trole}) && !exists($roles{'cr'})); 3504: } else { 3505: next if (!exists($roles{$trole})); 3506: } 3507: if ($tend) { 3508: next if ($tend < $now); 3509: } 3510: if ($tstart) { 3511: next if ($tstart > $now); 3512: } 3513: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec); 3514: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry); 3515: if ($secpart eq '') { 3516: ($cnum,$role) = split(/_/,$cnumpart); 3517: $sec = 'none'; 3518: $realsec = ''; 3519: } else { 3520: $cnum = $cnumpart; 3521: ($sec,$role) = split(/_/,$secpart); 3522: $realsec = $sec; 3523: } 3524: $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec; 3525: } 3526: } else { 3527: foreach my $key (keys(%env)) { 3528: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} || 3529: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) { 3530: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4); 3531: next if ($role eq 'ca' || $role eq 'aa'); 3532: next if (%roles && !exists($roles{$role})); 3533: my ($starttime,$endtime)=split(/\./,$env{$key}); 3534: my $active=1; 3535: if ($starttime) { 3536: if ($now<$starttime) { $active=0; } 3537: } 3538: if ($endtime) { 3539: if ($now>$endtime) { $active=0; } 3540: } 3541: if ($active) { 3542: if ($sec eq '') { 3543: $sec = 'none'; 3544: } 3545: $courses{$cdom.'_'.$cnum}{$sec} = 3546: $role.'/'.$cdom.'/'.$cnum.'/'.$sec; 3547: } 3548: } 3549: } 3550: } 3551: return %courses; 3552: } 3553: 3554: ############################################### 3555: 3556: sub blockcheck { 3557: my ($setters,$activity,$uname,$udom) = @_; 3558: 3559: if (!defined($udom)) { 3560: $udom = $env{'user.domain'}; 3561: } 3562: if (!defined($uname)) { 3563: $uname = $env{'user.name'}; 3564: } 3565: 3566: # If uname and udom are for a course, check for blocks in the course. 3567: 3568: if (&Apache::lonnet::is_course($udom,$uname)) { 3569: my %records = &Apache::lonnet::dump('comm_block',$udom,$uname); 3570: my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname); 3571: return ($startblock,$endblock); 3572: } 3573: 3574: my $startblock = 0; 3575: my $endblock = 0; 3576: my %live_courses = &findallcourses(undef,$uname,$udom); 3577: 3578: # If uname is for a user, and activity is course-specific, i.e., 3579: # boards, chat or groups, check for blocking in current course only. 3580: 3581: if (($activity eq 'boards' || $activity eq 'chat' || 3582: $activity eq 'groups') && ($env{'request.course.id'})) { 3583: foreach my $key (keys(%live_courses)) { 3584: if ($key ne $env{'request.course.id'}) { 3585: delete($live_courses{$key}); 3586: } 3587: } 3588: } 3589: 3590: my $otheruser = 0; 3591: my %own_courses; 3592: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) { 3593: # Resource belongs to user other than current user. 3594: $otheruser = 1; 3595: # Gather courses for current user 3596: %own_courses = 3597: &findallcourses(undef,$env{'user.name'},$env{'user.domain'}); 3598: } 3599: 3600: # Gather active course roles - course coordinator, instructor, 3601: # exam proctor, ta, student, or custom role. 3602: 3603: foreach my $course (keys(%live_courses)) { 3604: my ($cdom,$cnum); 3605: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) { 3606: $cdom = $env{'course.'.$course.'.domain'}; 3607: $cnum = $env{'course.'.$course.'.num'}; 3608: } else { 3609: ($cdom,$cnum) = split(/_/,$course); 3610: } 3611: my $no_ownblock = 0; 3612: my $no_userblock = 0; 3613: if ($otheruser && $activity ne 'com') { 3614: # Check if current user has 'evb' priv for this 3615: if (defined($own_courses{$course})) { 3616: foreach my $sec (keys(%{$own_courses{$course}})) { 3617: my $checkrole = 'cm./'.$cdom.'/'.$cnum; 3618: if ($sec ne 'none') { 3619: $checkrole .= '/'.$sec; 3620: } 3621: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) { 3622: $no_ownblock = 1; 3623: last; 3624: } 3625: } 3626: } 3627: # if they have 'evb' priv and are currently not playing student 3628: next if (($no_ownblock) && 3629: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})); 3630: } 3631: foreach my $sec (keys(%{$live_courses{$course}})) { 3632: my $checkrole = 'cm./'.$cdom.'/'.$cnum; 3633: if ($sec ne 'none') { 3634: $checkrole .= '/'.$sec; 3635: } 3636: if ($otheruser) { 3637: # Resource belongs to user other than current user. 3638: # Assemble privs for that user, and check for 'evb' priv. 3639: my ($trole,$tdom,$tnum,$tsec); 3640: my $entry = $live_courses{$course}{$sec}; 3641: if ($entry =~ /^cr/) { 3642: ($trole,$tdom,$tnum,$tsec) = 3643: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|); 3644: } else { 3645: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry); 3646: } 3647: my ($spec,$area,$trest,%allroles,%userroles); 3648: $area = '/'.$tdom.'/'.$tnum; 3649: $trest = $tnum; 3650: if ($tsec ne '') { 3651: $area .= '/'.$tsec; 3652: $trest .= '/'.$tsec; 3653: } 3654: $spec = $trole.'.'.$area; 3655: if ($trole =~ /^cr/) { 3656: &Apache::lonnet::custom_roleprivs(\%allroles,$trole, 3657: $tdom,$spec,$trest,$area); 3658: } else { 3659: &Apache::lonnet::standard_roleprivs(\%allroles,$trole, 3660: $tdom,$spec,$trest,$area); 3661: } 3662: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles); 3663: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) { 3664: if ($1) { 3665: $no_userblock = 1; 3666: last; 3667: } 3668: } 3669: } else { 3670: # Resource belongs to current user 3671: # Check for 'evb' priv via lonnet::allowed(). 3672: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) { 3673: $no_ownblock = 1; 3674: last; 3675: } 3676: } 3677: } 3678: # if they have the evb priv and are currently not playing student 3679: next if (($no_ownblock) && 3680: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E})); 3681: next if ($no_userblock); 3682: 3683: # Retrieve blocking times and identity of blocker for course 3684: # of specified user, unless user has 'evb' privilege. 3685: 3686: my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum); 3687: if (($start != 0) && 3688: (($startblock == 0) || ($startblock > $start))) { 3689: $startblock = $start; 3690: } 3691: if (($end != 0) && 3692: (($endblock == 0) || ($endblock < $end))) { 3693: $endblock = $end; 3694: } 3695: } 3696: return ($startblock,$endblock); 3697: } 3698: 3699: sub get_blocks { 3700: my ($setters,$activity,$cdom,$cnum) = @_; 3701: my $startblock = 0; 3702: my $endblock = 0; 3703: my $course = $cdom.'_'.$cnum; 3704: $setters->{$course} = {}; 3705: $setters->{$course}{'staff'} = []; 3706: $setters->{$course}{'times'} = []; 3707: my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum); 3708: foreach my $record (keys(%records)) { 3709: my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/); 3710: if ($start <= time && $end >= time) { 3711: my ($staff_name,$staff_dom,$title,$blocks) = 3712: &parse_block_record($records{$record}); 3713: if ($blocks->{$activity} eq 'on') { 3714: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]); 3715: push(@{$$setters{$course}{'times'}}, [$start,$end]); 3716: if ( ($startblock == 0) || ($startblock > $start) ) { 3717: $startblock = $start; 3718: } 3719: if ( ($endblock == 0) || ($endblock < $end) ) { 3720: $endblock = $end; 3721: } 3722: } 3723: } 3724: } 3725: return ($startblock,$endblock); 3726: } 3727: 3728: sub parse_block_record { 3729: my ($record) = @_; 3730: my ($setuname,$setudom,$title,$blocks); 3731: if (ref($record) eq 'HASH') { 3732: ($setuname,$setudom) = split(/:/,$record->{'setter'}); 3733: $title = &unescape($record->{'event'}); 3734: $blocks = $record->{'blocks'}; 3735: } else { 3736: my @data = split(/:/,$record,3); 3737: if (scalar(@data) eq 2) { 3738: $title = $data[1]; 3739: ($setuname,$setudom) = split(/@/,$data[0]); 3740: } else { 3741: ($setuname,$setudom,$title) = @data; 3742: } 3743: $blocks = { 'com' => 'on' }; 3744: } 3745: return ($setuname,$setudom,$title,$blocks); 3746: } 3747: 3748: sub build_block_table { 3749: my ($startblock,$endblock,$setters) = @_; 3750: my %lt = &Apache::lonlocal::texthash( 3751: 'cacb' => 'Currently active communication blocks', 3752: 'cour' => 'Course', 3753: 'dura' => 'Duration', 3754: 'blse' => 'Block set by' 3755: ); 3756: my $output; 3757: $output = '<br />'.$lt{'cacb'}.':<br />'; 3758: $output .= &start_data_table(); 3759: $output .= ' 3760: <tr> 3761: <th>'.$lt{'cour'}.'</th> 3762: <th>'.$lt{'dura'}.'</th> 3763: <th>'.$lt{'blse'}.'</th> 3764: </tr> 3765: '; 3766: foreach my $course (keys(%{$setters})) { 3767: my %courseinfo=&Apache::lonnet::coursedescription($course); 3768: for (my $i=0; $i<@{$$setters{$course}{staff}}; $i++) { 3769: my ($uname,$udom) = @{$$setters{$course}{staff}[$i]}; 3770: my $fullname = &plainname($uname,$udom); 3771: if (defined($env{'user.name'}) && defined($env{'user.domain'}) 3772: && $env{'user.name'} ne 'public' 3773: && $env{'user.domain'} ne 'public') { 3774: $fullname = &aboutmewrapper($fullname,$uname,$udom); 3775: } 3776: my ($openblock,$closeblock) = @{$$setters{$course}{times}[$i]}; 3777: $openblock = &Apache::lonlocal::locallocaltime($openblock); 3778: $closeblock= &Apache::lonlocal::locallocaltime($closeblock); 3779: $output .= &Apache::loncommon::start_data_table_row(). 3780: '<td>'.$courseinfo{'description'}.'</td>'. 3781: '<td>'.$openblock.' to '.$closeblock.'</td>'. 3782: '<td>'.$fullname.'</td>'. 3783: &Apache::loncommon::end_data_table_row(); 3784: } 3785: } 3786: $output .= &end_data_table(); 3787: } 3788: 3789: sub blocking_status { 3790: my ($activity,$uname,$udom) = @_; 3791: my %setters; 3792: my ($blocked,$output,$ownitem,$is_course); 3793: my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom); 3794: if ($startblock && $endblock) { 3795: $blocked = 1; 3796: if (wantarray) { 3797: my $category; 3798: if ($activity eq 'boards') { 3799: $category = 'Discussion posts in this course'; 3800: } elsif ($activity eq 'blogs') { 3801: $category = 'Blogs'; 3802: } elsif ($activity eq 'port') { 3803: if (defined($uname) && defined($udom)) { 3804: if ($uname eq $env{'user.name'} && 3805: $udom eq $env{'user.domain'}) { 3806: $ownitem = 1; 3807: } 3808: } 3809: $is_course = &Apache::lonnet::is_course($udom,$uname); 3810: if ($ownitem) { 3811: $category = 'Your portfolio files'; 3812: } elsif ($is_course) { 3813: my $coursedesc; 3814: foreach my $course (keys(%setters)) { 3815: my %courseinfo = 3816: &Apache::lonnet::coursedescription($course); 3817: $coursedesc = $courseinfo{'description'}; 3818: } 3819: $category = "Group files in the course '$coursedesc'"; 3820: } else { 3821: $category = 'Portfolio files belonging to '; 3822: if ($env{'user.name'} eq 'public' && 3823: $env{'user.domain'} eq 'public') { 3824: $category .= &plainname($uname,$udom); 3825: } else { 3826: $category .= &aboutmewrapper(&plainname($uname,$udom),$uname,$udom); 3827: } 3828: } 3829: } elsif ($activity eq 'groups') { 3830: $category = 'Groups in this course'; 3831: } 3832: my $showstart = &Apache::lonlocal::locallocaltime($startblock); 3833: my $showend = &Apache::lonlocal::locallocaltime($endblock); 3834: $output = '<br />'.&mt('[_1] will be inaccessible between [_2] and [_3] because communication is being blocked.',$category,$showstart,$showend).'<br />'; 3835: if (!($activity eq 'port' && !($ownitem) && !($is_course))) { 3836: $output .= &build_block_table($startblock,$endblock,\%setters); 3837: } 3838: } 3839: } 3840: if (wantarray) { 3841: return ($blocked,$output); 3842: } else { 3843: return $blocked; 3844: } 3845: } 3846: 3847: ############################################### 3848: 3849: sub check_ip_acc { 3850: my ($acc)=@_; 3851: &Apache::lonxml::debug("acc is $acc"); 3852: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) { 3853: return 1; 3854: } 3855: my $allowed=0; 3856: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'}; 3857: 3858: my $name; 3859: foreach my $pattern (split(',',$acc)) { 3860: $pattern =~ s/^\s*//; 3861: $pattern =~ s/\s*$//; 3862: if ($pattern =~ /\*$/) { 3863: #35.8.* 3864: $pattern=~s/\*//; 3865: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; } 3866: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) { 3867: #35.8.3.[34-56] 3868: my $low=$2; 3869: my $high=$3; 3870: $pattern=$1; 3871: if ($ip =~ /^\Q$pattern\E/) { 3872: my $last=(split(/\./,$ip))[3]; 3873: if ($last <=$high && $last >=$low) { $allowed=1; } 3874: } 3875: } elsif ($pattern =~ /^\*/) { 3876: #*.msu.edu 3877: $pattern=~s/\*//; 3878: if (!defined($name)) { 3879: use Socket; 3880: my $netaddr=inet_aton($ip); 3881: ($name)=gethostbyaddr($netaddr,AF_INET); 3882: } 3883: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; } 3884: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) { 3885: #127.0.0.1 3886: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; } 3887: } else { 3888: #some.name.com 3889: if (!defined($name)) { 3890: use Socket; 3891: my $netaddr=inet_aton($ip); 3892: ($name)=gethostbyaddr($netaddr,AF_INET); 3893: } 3894: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; } 3895: } 3896: if ($allowed) { last; } 3897: } 3898: return $allowed; 3899: } 3900: 3901: ############################################### 3902: 3903: =pod 3904: 3905: =head1 Domain Template Functions 3906: 3907: =over 4 3908: 3909: =item * &determinedomain() 3910: 3911: Inputs: $domain (usually will be undef) 3912: 3913: Returns: Determines which domain should be used for designs 3914: 3915: =cut 3916: 3917: ############################################### 3918: sub determinedomain { 3919: my $domain=shift; 3920: if (! $domain) { 3921: # Determine domain if we have not been given one 3922: $domain = $Apache::lonnet::perlvar{'lonDefDomain'}; 3923: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; } 3924: if ($env{'request.role.domain'}) { 3925: $domain=$env{'request.role.domain'}; 3926: } 3927: } 3928: return $domain; 3929: } 3930: ############################################### 3931: 3932: sub devalidate_domconfig_cache { 3933: my ($udom)=@_; 3934: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom); 3935: } 3936: 3937: # ---------------------- Get domain configuration for a domain 3938: sub get_domainconf { 3939: my ($udom) = @_; 3940: my $cachetime=1800; 3941: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom); 3942: if (defined($cached)) { return %{$result}; } 3943: 3944: my %domconfig = &Apache::lonnet::get_dom('configuration', 3945: ['login','rolecolors'],$udom); 3946: my (%designhash,%legacy); 3947: if (keys(%domconfig) > 0) { 3948: if (ref($domconfig{'login'}) eq 'HASH') { 3949: if (keys(%{$domconfig{'login'}})) { 3950: foreach my $key (keys(%{$domconfig{'login'}})) { 3951: if (ref($domconfig{'login'}{$key}) eq 'HASH') { 3952: foreach my $img (keys(%{$domconfig{'login'}{$key}})) { 3953: $designhash{$udom.'.login.'.$key.'_'.$img} = 3954: $domconfig{'login'}{$key}{$img}; 3955: } 3956: } else { 3957: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key}; 3958: } 3959: } 3960: } else { 3961: $legacy{'login'} = 1; 3962: } 3963: } else { 3964: $legacy{'login'} = 1; 3965: } 3966: if (ref($domconfig{'rolecolors'}) eq 'HASH') { 3967: if (keys(%{$domconfig{'rolecolors'}})) { 3968: foreach my $role (keys(%{$domconfig{'rolecolors'}})) { 3969: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') { 3970: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) { 3971: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item}; 3972: } 3973: } 3974: } 3975: } else { 3976: $legacy{'rolecolors'} = 1; 3977: } 3978: } else { 3979: $legacy{'rolecolors'} = 1; 3980: } 3981: if (keys(%legacy) > 0) { 3982: my %legacyhash = &get_legacy_domconf($udom); 3983: foreach my $item (keys(%legacyhash)) { 3984: if ($item =~ /^\Q$udom\E\.login/) { 3985: if ($legacy{'login'}) { 3986: $designhash{$item} = $legacyhash{$item}; 3987: } 3988: } else { 3989: if ($legacy{'rolecolors'}) { 3990: $designhash{$item} = $legacyhash{$item}; 3991: } 3992: } 3993: } 3994: } 3995: } else { 3996: %designhash = &get_legacy_domconf($udom); 3997: } 3998: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash, 3999: $cachetime); 4000: return %designhash; 4001: } 4002: 4003: sub get_legacy_domconf { 4004: my ($udom) = @_; 4005: my %legacyhash; 4006: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors'; 4007: my $designfile = $designdir.'/'.$udom.'.tab'; 4008: if (-e $designfile) { 4009: if ( open (my $fh,"<$designfile") ) { 4010: while (my $line = <$fh>) { 4011: next if ($line =~ /^\#/); 4012: chomp($line); 4013: my ($key,$val)=(split(/\=/,$line)); 4014: if ($val) { $legacyhash{$udom.'.'.$key}=$val; } 4015: } 4016: close($fh); 4017: } 4018: } 4019: if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') { 4020: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif"; 4021: } 4022: return %legacyhash; 4023: } 4024: 4025: =pod 4026: 4027: =item * &domainlogo() 4028: 4029: Inputs: $domain (usually will be undef) 4030: 4031: Returns: A link to a domain logo, if the domain logo exists. 4032: If the domain logo does not exist, a description of the domain. 4033: 4034: =cut 4035: 4036: ############################################### 4037: sub domainlogo { 4038: my $domain = &determinedomain(shift); 4039: my %designhash = &get_domainconf($domain); 4040: # See if there is a logo 4041: if ($designhash{$domain.'.login.domlogo'} ne '') { 4042: my $imgsrc = $designhash{$domain.'.login.domlogo'}; 4043: if ($imgsrc =~ m{^/(adm|res)/}) { 4044: if ($imgsrc =~ m{^/res/}) { 4045: my $local_name = &Apache::lonnet::filelocation('',$imgsrc); 4046: &Apache::lonnet::repcopy($local_name); 4047: } 4048: $imgsrc = &lonhttpdurl($imgsrc); 4049: } 4050: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />'; 4051: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) { 4052: return &Apache::lonnet::domain($domain,'description'); 4053: } else { 4054: return ''; 4055: } 4056: } 4057: ############################################## 4058: 4059: =pod 4060: 4061: =item * &designparm() 4062: 4063: Inputs: $which parameter; $domain (usually will be undef) 4064: 4065: Returns: value of designparamter $which 4066: 4067: =cut 4068: 4069: 4070: ############################################## 4071: sub designparm { 4072: my ($which,$domain)=@_; 4073: if ($env{'browser.blackwhite'} eq 'on') { 4074: if ($which=~/\.(font|alink|vlink|link|textcol)$/) { 4075: return '#000000'; 4076: } 4077: if ($which=~/\.(pgbg|sidebg|bgcol)$/) { 4078: return '#FFFFFF'; 4079: } 4080: if ($which=~/\.tabbg$/) { 4081: return '#CCCCCC'; 4082: } 4083: } 4084: if (exists($env{'environment.color.'.$which})) { 4085: return $env{'environment.color.'.$which}; 4086: } 4087: $domain=&determinedomain($domain); 4088: my %domdesign = &get_domainconf($domain); 4089: my $output; 4090: if ($domdesign{$domain.'.'.$which} ne '') { 4091: $output = $domdesign{$domain.'.'.$which}; 4092: } else { 4093: $output = $defaultdesign{$which}; 4094: } 4095: if (($which =~ /^(student|coordinator|author|admin)\.img$/) || 4096: ($which =~ /login\.(img|logo|domlogo|login)/)) { 4097: if ($output =~ m{^/(adm|res)/}) { 4098: if ($output =~ m{^/res/}) { 4099: my $local_name = &Apache::lonnet::filelocation('',$output); 4100: &Apache::lonnet::repcopy($local_name); 4101: } 4102: $output = &lonhttpdurl($output); 4103: } 4104: } 4105: return $output; 4106: } 4107: 4108: ############################################### 4109: ############################################### 4110: 4111: =pod 4112: 4113: =back 4114: 4115: =head1 HTML Helpers 4116: 4117: =over 4 4118: 4119: =item * &bodytag() 4120: 4121: Returns a uniform header for LON-CAPA web pages. 4122: 4123: Inputs: 4124: 4125: =over 4 4126: 4127: =item * $title, A title to be displayed on the page. 4128: 4129: =item * $function, the current role (can be undef). 4130: 4131: =item * $addentries, extra parameters for the <body> tag. 4132: 4133: =item * $bodyonly, if defined, only return the <body> tag. 4134: 4135: =item * $domain, if defined, force a given domain. 4136: 4137: =item * $forcereg, if page should register as content page (relevant for 4138: text interface only) 4139: 4140: =item * $customtitle, alternate text to use instead of $title 4141: in the title box that appears, this text 4142: is not auto translated like the $title is 4143: 4144: =item * $notopbar, if true, keep the 'what is this' info but remove the 4145: navigational links 4146: 4147: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value 4148: 4149: =item * $notitle, if true keep the nav controls, but remove the title bar 4150: 4151: =item * $no_inline_link, if true and in remote mode, don't show the 4152: 'Switch To Inline Menu' link 4153: 4154: =item * $args, optional argument valid values are 4155: no_auto_mt_title -> prevents &mt()ing the title arg 4156: inherit_jsmath -> when creating popup window in a page, 4157: should it have jsmath forced on by the 4158: current page 4159: 4160: =back 4161: 4162: Returns: A uniform header for LON-CAPA web pages. 4163: If $bodyonly is nonzero, a string containing a <body> tag will be returned. 4164: If $bodyonly is undef or zero, an html string containing a <body> tag and 4165: other decorations will be returned. 4166: 4167: =cut 4168: 4169: sub bodytag { 4170: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,$customtitle, 4171: $notopbar,$bgcolor,$notitle,$no_inline_link,$args)=@_; 4172: 4173: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); } 4174: 4175: $function = &get_users_function() if (!$function); 4176: my $img = &designparm($function.'.img',$domain); 4177: my $font = &designparm($function.'.font',$domain); 4178: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain); 4179: 4180: my %design = ( 'style' => 'margin-top: 0px', 4181: 'bgcolor' => $pgbg, 4182: 'text' => $font, 4183: 'alink' => &designparm($function.'.alink',$domain), 4184: 'vlink' => &designparm($function.'.vlink',$domain), 4185: 'link' => &designparm($function.'.link',$domain),); 4186: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)}; 4187: 4188: # role and realm 4189: my ($role,$realm) = split(/\./,$env{'request.role'},2); 4190: if ($role eq 'ca') { 4191: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$}); 4192: $realm = &plainname($rname,$rdom); 4193: } 4194: # realm 4195: if ($env{'request.course.id'}) { 4196: if ($env{'request.role'} !~ /^cr/) { 4197: $role = &Apache::lonnet::plaintext($role,&course_type()); 4198: } 4199: $realm = $env{'course.'.$env{'request.course.id'}.'.description'}; 4200: } else { 4201: $role = &Apache::lonnet::plaintext($role); 4202: } 4203: 4204: if (!$realm) { $realm=' '; } 4205: # Set messages 4206: my $messages=&domainlogo($domain); 4207: 4208: my $extra_body_attr = &make_attr_string($forcereg,\%design); 4209: 4210: # construct main body tag 4211: my $bodytag = "<body $extra_body_attr>". 4212: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'}); 4213: 4214: if ($bodyonly) { 4215: return $bodytag; 4216: } elsif ($env{'browser.interface'} eq 'textual') { 4217: # Accessibility 4218: 4219: $bodytag.=&Apache::lonmenu::menubuttons($forcereg,$forcereg); 4220: if (!$notitle) { 4221: $bodytag.='<h1>LON-CAPA: '.$title.'</h1>'; 4222: } 4223: return $bodytag; 4224: } 4225: 4226: my $name = &plainname($env{'user.name'},$env{'user.domain'}); 4227: if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') { 4228: undef($role); 4229: } else { 4230: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'}); 4231: } 4232: 4233: my $roleinfo=(<<ENDROLE); 4234: <td class="LC_title_bar_who"> 4235: <div class="LC_title_bar_name"> 4236: $name 4237: 4238: </div> 4239: <div class="LC_title_bar_role"> 4240: $role 4241: </div> 4242: <div class="LC_title_bar_realm"> 4243: $realm 4244: </div> 4245: </td> 4246: ENDROLE 4247: 4248: my $titleinfo = '<span class="LC_title_bar_title">'.$title.'</span>'; 4249: if ($customtitle) { 4250: $titleinfo = $customtitle; 4251: } 4252: # 4253: # Extra info if you are the DC 4254: my $dc_info = ''; 4255: if ($env{'user.adv'} && exists($env{'user.role.dc./'. 4256: $env{'course.'.$env{'request.course.id'}. 4257: '.domain'}.'/'})) { 4258: my $cid = $env{'request.course.id'}; 4259: $dc_info.= $cid.' '.$env{'course.'.$cid.'.internal.coursecode'}; 4260: $dc_info =~ s/\s+$//; 4261: $dc_info = '('.$dc_info.')'; 4262: } 4263: 4264: if (($env{'environment.remote'} eq 'off') || ($args->{'suppress_header_logos'})) { 4265: # No Remote 4266: if ($env{'request.state'} eq 'construct') { 4267: $forcereg=1; 4268: } 4269: 4270: if (!$customtitle && $env{'request.state'} eq 'construct') { 4271: # this is for resources; directories have customtitle, and crumbs 4272: # and select recent are created in lonpubdir.pm 4273: my ($uname,$thisdisfn)= 4274: ($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|); 4275: my $formaction='/priv/'.$uname.'/'.$thisdisfn; 4276: $formaction=~s/\/+/\//g; 4277: 4278: my $parentpath = ''; 4279: my $lastitem = ''; 4280: if ($thisdisfn =~ m-(.+/)([^/]*)$-) { 4281: $parentpath = $1; 4282: $lastitem = $2; 4283: } else { 4284: $lastitem = $thisdisfn; 4285: } 4286: $titleinfo = 4287: &Apache::loncommon::help_open_menu('','',3,'Authoring') 4288: .'<b>'.&mt('Construction Space').'</b>: ' 4289: .'<form name="dirs" method="post" action="'.$formaction 4290: .'" target="_top"><tt><b>' 4291: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv','','+1',1)."<span class=\"LC_fontsize_big\">$lastitem</span></b></tt><br />" 4292: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()') 4293: .'</form>' 4294: .&Apache::lonmenu::constspaceform(); 4295: } 4296: 4297: my $titletable; 4298: if (!$notitle) { 4299: $titletable = 4300: '<table id="LC_title_bar">'. 4301: "<tr><td> $titleinfo $dc_info</td>".$roleinfo. 4302: '</tr></table>'; 4303: } 4304: if ($notopbar) { 4305: $bodytag .= $titletable; 4306: } else { 4307: if ($env{'request.state'} eq 'construct') { 4308: $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg, 4309: $titletable); 4310: } else { 4311: $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg). 4312: $titletable; 4313: } 4314: } 4315: return $bodytag; 4316: } 4317: 4318: # 4319: # Top frame rendering, Remote is up 4320: # 4321: 4322: my $imgsrc = $img; 4323: if ($img =~ /^\/adm/) { 4324: $imgsrc = &lonhttpdurl($img); 4325: } 4326: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />'; 4327: 4328: # Explicit link to get inline menu 4329: my $menu= ($no_inline_link?'' 4330: :'<br /><a href="/adm/remote?action=collapse">'.&mt('Switch to Inline Menu Mode').'</a>'); 4331: # 4332: if ($notitle) { 4333: return $bodytag; 4334: } 4335: return(<<ENDBODY); 4336: $bodytag 4337: <table id="LC_title_bar" class="LC_with_remote"> 4338: <tr><td class="LC_title_bar_role_logo">$upperleft</td> 4339: <td class="LC_title_bar_domain_logo">$messages </td> 4340: </tr> 4341: <tr><td>$titleinfo $dc_info $menu</td> 4342: $roleinfo 4343: </tr> 4344: </table> 4345: ENDBODY 4346: } 4347: 4348: sub make_attr_string { 4349: my ($register,$attr_ref) = @_; 4350: 4351: if ($attr_ref && !ref($attr_ref)) { 4352: die("addentries Must be a hash ref ". 4353: join(':',caller(1))." ". 4354: join(':',caller(0))." "); 4355: } 4356: 4357: if ($register) { 4358: my ($on_load,$on_unload); 4359: foreach my $key (keys(%{$attr_ref})) { 4360: if (lc($key) eq 'onload') { 4361: $on_load.=$attr_ref->{$key}.';'; 4362: delete($attr_ref->{$key}); 4363: 4364: } elsif (lc($key) eq 'onunload') { 4365: $on_unload.=$attr_ref->{$key}.';'; 4366: delete($attr_ref->{$key}); 4367: } 4368: } 4369: $attr_ref->{'onload'} = 4370: &Apache::lonmenu::loadevents(). $on_load; 4371: $attr_ref->{'onunload'}= 4372: &Apache::lonmenu::unloadevents().$on_unload; 4373: } 4374: 4375: # Accessibility font enhance 4376: if ($env{'browser.fontenhance'} eq 'on') { 4377: my $style; 4378: foreach my $key (keys(%{$attr_ref})) { 4379: if (lc($key) eq 'style') { 4380: $style.=$attr_ref->{$key}.';'; 4381: delete($attr_ref->{$key}); 4382: } 4383: } 4384: $attr_ref->{'style'}=$style.'; font-size: x-large;'; 4385: } 4386: 4387: if ($env{'browser.blackwhite'} eq 'on') { 4388: delete($attr_ref->{'font'}); 4389: delete($attr_ref->{'link'}); 4390: delete($attr_ref->{'alink'}); 4391: delete($attr_ref->{'vlink'}); 4392: delete($attr_ref->{'bgcolor'}); 4393: delete($attr_ref->{'background'}); 4394: } 4395: 4396: my $attr_string; 4397: foreach my $attr (keys(%$attr_ref)) { 4398: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" '; 4399: } 4400: return $attr_string; 4401: } 4402: 4403: 4404: ############################################### 4405: ############################################### 4406: 4407: =pod 4408: 4409: =item * &endbodytag() 4410: 4411: Returns a uniform footer for LON-CAPA web pages. 4412: 4413: Inputs: 1 - optional reference to an args hash 4414: If in the hash, key for noredirectlink has a value which evaluates to true, 4415: a 'Continue' link is not displayed if the page contains an 4416: internal redirect in the <head></head> section, 4417: i.e., $env{'internal.head.redirect'} exists 4418: 4419: =cut 4420: 4421: sub endbodytag { 4422: my ($args) = @_; 4423: my $endbodytag='</body>'; 4424: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag; 4425: if ( exists( $env{'internal.head.redirect'} ) ) { 4426: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) { 4427: $endbodytag= 4428: "<br /><a href=\"$env{'internal.head.redirect'}\">". 4429: &mt('Continue').'</a>'. 4430: $endbodytag; 4431: } 4432: } 4433: return $endbodytag; 4434: } 4435: 4436: =pod 4437: 4438: =item * &standard_css() 4439: 4440: Returns a style sheet 4441: 4442: Inputs: (all optional) 4443: domain -> force to color decorate a page for a specific 4444: domain 4445: function -> force usage of a specific rolish color scheme 4446: bgcolor -> override the default page bgcolor 4447: 4448: =cut 4449: 4450: sub standard_css { 4451: my ($function,$domain,$bgcolor) = @_; 4452: $function = &get_users_function() if (!$function); 4453: my $img = &designparm($function.'.img', $domain); 4454: my $tabbg = &designparm($function.'.tabbg', $domain); 4455: my $font = &designparm($function.'.font', $domain); 4456: my $sidebg = &designparm($function.'.sidebg',$domain); 4457: my $pgbg_or_bgcolor = 4458: $bgcolor || 4459: &designparm($function.'.pgbg', $domain); 4460: my $pgbg = &designparm($function.'.pgbg', $domain); 4461: my $alink = &designparm($function.'.alink', $domain); 4462: my $vlink = &designparm($function.'.vlink', $domain); 4463: my $link = &designparm($function.'.link', $domain); 4464: 4465: my $loginbg = &designparm('login.sidebg',$domain); 4466: my $bgcol = &designparm('login.bgcol',$domain); 4467: my $textcol = &designparm('login.textcol',$domain); 4468: 4469: my $sans = 'Verdana,Arial,Helvetica,sans-serif'; 4470: my $mono = 'monospace'; 4471: my $data_table_head = $tabbg; 4472: my $data_table_light = '#EEEEEE'; 4473: my $data_table_dark = '#DDDDDD'; 4474: my $data_table_darker = '#CCCCCC'; 4475: my $data_table_highlight = '#FFFF00'; 4476: my $mail_new = '#FFBB77'; 4477: my $mail_new_hover = '#DD9955'; 4478: my $mail_read = '#BBBB77'; 4479: my $mail_read_hover = '#999944'; 4480: my $mail_replied = '#AAAA88'; 4481: my $mail_replied_hover = '#888855'; 4482: my $mail_other = '#99BBBB'; 4483: my $mail_other_hover = '#669999'; 4484: my $table_header = '#DDDDDD'; 4485: my $feedback_link_bg = '#BBBBBB'; 4486: my $lg_border_color = '#C8C8C8'; 4487: 4488: my $border = ($env{'browser.type'} eq 'explorer' || 4489: $env{'browser.type'} eq 'safari' ) ? '0px 2px 0px 2px' 4490: : '0px 3px 0px 4px'; 4491: 4492: 4493: return <<END; 4494: body{ 4495: font-family: $sans; 4496: line-height:130%; 4497: font-size:0.83em; 4498: color:$font; 4499: } 4500: a:link, a:visited { font-size:100%; } 4501: 4502: a:focus { color: red; background: yellow } 4503: table.thinborder, 4504: table.thinborder tr th { 4505: border-style: solid; 4506: border-width: 1px; 4507: border-color: $lg_border_color; 4508: background: $tabbg; 4509: } 4510: table.thinborder tr td { 4511: border-style: solid; 4512: border-width: 1px; 4513: border-color: $lg_border_color; 4514: } 4515: 4516: form, .inline { display: inline; } 4517: 4518: .LC_center { text-align: center; } 4519: .LC_left { text-align:left; } 4520: .LC_right {text-align:right;} 4521: .LC_middle {vertical-align:middle;} 4522: .LC_top {vertical-align:top;} 4523: .LC_bottom {vertical-align:bottom;} 4524: 4525: /* just for tests */ 4526: .LC_300Box { width:300px; } 4527: .LC_400Box {width:400px; } 4528: .LC_500Box {width:500px; } 4529: .LC_600Box {width:600px; } 4530: .LC_800Box {width:800px;} 4531: /* end */ 4532: 4533: .LC_filename {font-family: $mono; white-space:pre;} 4534: .LC_error { 4535: color: red; 4536: font-size: larger; 4537: } 4538: .LC_warning, 4539: .LC_diff_removed { 4540: color: red; 4541: } 4542: 4543: .LC_info, 4544: .LC_success, 4545: .LC_diff_added { 4546: color: green; 4547: } 4548: .LC_unknown { 4549: color: yellow; 4550: } 4551: 4552: .LC_icon { 4553: border: 0px; 4554: } 4555: .LC_indexer_icon { 4556: border: 0px; 4557: height: 22px; 4558: } 4559: .LC_docs_spacer { 4560: width: 25px; 4561: height: 1px; 4562: border: 0px; 4563: } 4564: 4565: .LC_internal_info { 4566: color: #999999; 4567: } 4568: 4569: table.LC_pastsubmission { 4570: border: 1px solid black; 4571: margin: 2px; 4572: } 4573: 4574: table#LC_top_nav, table#LC_menubuttons,table#LC_nav_location { 4575: width: 100%; 4576: background: $pgbg; 4577: border: 2px; 4578: border-collapse: separate; 4579: padding: 0px; 4580: } 4581: 4582: table#LC_title_bar, table.LC_breadcrumbs, 4583: table#LC_title_bar.LC_with_remote { 4584: width: 100%; 4585: border-color: $pgbg; 4586: border-style: solid; 4587: border-width: $border; 4588: 4589: background: $pgbg; 4590: font-family: $sans; 4591: border-collapse: collapse; 4592: padding: 0px; 4593: } 4594: table.LC_docs_path { 4595: width: 100%; 4596: border: 0; 4597: background: $pgbg; 4598: font-family: $sans; 4599: border-collapse: collapse; 4600: padding: 0px; 4601: } 4602: 4603: table#LC_title_bar td { 4604: background: $tabbg; 4605: } 4606: table#LC_title_bar td.LC_title_bar_who { 4607: background: $tabbg; 4608: color: $font; 4609: font: small $sans; 4610: text-align: right; 4611: } 4612: span.LC_metadata { 4613: font-family: $sans; 4614: } 4615: span.LC_title_bar_title { 4616: font: bold x-large $sans; 4617: } 4618: table#LC_title_bar td.LC_title_bar_domain_logo { 4619: background: $sidebg; 4620: text-align: right; 4621: padding: 0px; 4622: } 4623: table#LC_title_bar td.LC_title_bar_role_logo { 4624: background: $sidebg; 4625: padding: 0px; 4626: } 4627: 4628: table#LC_menubuttons img{ 4629: border: 0px; 4630: } 4631: table#LC_top_nav td { 4632: background: $tabbg; 4633: border: 0px; 4634: font-size: small; 4635: vertical-align:top; 4636: padding:2px 5px 2px 5px; 4637: } 4638: table#LC_top_nav td a, div#LC_top_nav a { 4639: color: $font; 4640: font-family: $sans; 4641: } 4642: table#LC_top_nav td.LC_top_nav_logo { 4643: background: $tabbg; 4644: text-align: left; 4645: white-space: nowrap; 4646: width: 31px; 4647: } 4648: table#LC_top_nav td.LC_top_nav_logo img { 4649: border: 0px; 4650: vertical-align: bottom; 4651: } 4652: table#LC_top_nav td.LC_top_nav_exit, 4653: table#LC_top_nav td.LC_top_nav_help { 4654: width: 2.0em; 4655: } 4656: table#LC_top_nav td.LC_top_nav_login { 4657: width: 4.0em; 4658: text-align: center; 4659: } 4660: table.LC_breadcrumbs td, table.LC_docs_path td { 4661: background: $tabbg; 4662: color: $font; 4663: font-family: $sans; 4664: font-size: smaller; 4665: } 4666: table.LC_breadcrumbs td.LC_breadcrumbs_component, 4667: table.LC_docs_path td.LC_docs_path_component { 4668: background: $tabbg; 4669: color: $font; 4670: font-family: $sans; 4671: font-size: larger; 4672: text-align: right; 4673: } 4674: td.LC_table_cell_checkbox { 4675: text-align: center; 4676: } 4677: table#LC_mainmenu td.LC_mainmenu_column { 4678: vertical-align: top; 4679: } 4680: 4681: .LC_fontsize_small 4682: { 4683: font-size: 70%; 4684: } 4685: 4686: .LC_fontsize_medium 4687: { 4688: font-size: 85%; 4689: } 4690: 4691: .LC_fontsize_large 4692: { 4693: font-size: 120%; 4694: } 4695: 4696: .LC_fontcolor_red 4697: { 4698: color: #FF0000; 4699: } 4700: 4701: .LC_menubuttons_inline_text { 4702: color: $font; 4703: font-family: $sans; 4704: font-size: 90%; 4705: padding-left:3px; 4706: } 4707: 4708: .LC_menubuttons_link { 4709: text-decoration: none; 4710: } 4711: /*2008--9-5: new menu style sheet.Changed category*/ 4712: .LC_menubuttons_category { 4713: color: $font; 4714: background: $pgbg; 4715: font-family: $sans; 4716: font-size: larger; 4717: font-weight: bold; 4718: } 4719: 4720: td.LC_menubuttons_text { 4721: color: $font; 4722: } 4723: 4724: 4725: 4726: .LC_current_location { 4727: font-family: $sans; 4728: background: $tabbg; 4729: } 4730: .LC_new_mail { 4731: font-family: $sans; 4732: background: $tabbg; 4733: font-weight: bold; 4734: } 4735: 4736: 4737: .LC_dropadd_labeltext { 4738: font-family: $sans; 4739: text-align: right; 4740: } 4741: 4742: .LC_preferences_labeltext { 4743: font-family: $sans; 4744: text-align: right; 4745: } 4746: 4747: .LC_roleslog_note { 4748: font-size: small; 4749: } 4750: 4751: .LC_mail_functions { 4752: font-weight: bold; 4753: } 4754: 4755: table.LC_aboutme_port { 4756: border: 0px; 4757: border-collapse: collapse; 4758: border-spacing: 0px; 4759: } 4760: table.LC_data_table, table.LC_mail_list { 4761: border: 1px solid #000000; 4762: border-collapse: separate; 4763: border-spacing: 1px; 4764: background: $pgbg; 4765: } 4766: .LC_data_table_dense { 4767: font-size: small; 4768: } 4769: table.LC_nested_outer { 4770: border: 1px solid #000000; 4771: border-collapse: collapse; 4772: border-spacing: 0px; 4773: width: 100%; 4774: } 4775: table.LC_nested { 4776: border: 0px; 4777: border-collapse: collapse; 4778: border-spacing: 0px; 4779: width: 100%; 4780: } 4781: table.LC_data_table tr th, table.LC_calendar tr th, table.LC_mail_list tr th, 4782: table.LC_prior_tries tr th { 4783: font-weight: bold; 4784: background-color: $data_table_head; 4785: font-size:90%; 4786: } 4787: table.LC_data_table tr.LC_info_row > td { 4788: background-color: #CCCCCC; 4789: font-weight: bold; 4790: text-align: left; 4791: } 4792: table.LC_data_table tr.LC_odd_row > td, 4793: table.LC_pick_box tr > td.LC_odd_row, 4794: table.LC_aboutme_port tr td { 4795: background-color: $data_table_light; 4796: padding: 2px; 4797: } 4798: table.LC_data_table tr.LC_even_row > td, 4799: table.LC_pick_box tr > td.LC_even_row, 4800: table.LC_aboutme_port tr.LC_even_row td { 4801: background-color: $data_table_dark; 4802: padding: 2px; 4803: } 4804: table.LC_data_table tr.LC_data_table_highlight td { 4805: background-color: $data_table_darker; 4806: } 4807: table.LC_data_table tr td.LC_leftcol_header { 4808: background-color: $data_table_head; 4809: font-weight: bold; 4810: } 4811: table.LC_data_table tr.LC_empty_row td, 4812: table.LC_nested tr.LC_empty_row td { 4813: background-color: #FFFFFF; 4814: font-weight: bold; 4815: font-style: italic; 4816: text-align: center; 4817: padding: 8px; 4818: } 4819: table.LC_nested tr.LC_empty_row td { 4820: padding: 4ex 4821: } 4822: table.LC_nested_outer tr th { 4823: font-weight: bold; 4824: background-color: $data_table_head; 4825: font-size: small; 4826: border-bottom: 1px solid #000000; 4827: } 4828: table.LC_nested_outer tr td.LC_subheader { 4829: background-color: $data_table_head; 4830: font-weight: bold; 4831: font-size: small; 4832: border-bottom: 1px solid #000000; 4833: text-align: right; 4834: } 4835: table.LC_nested tr.LC_info_row td { 4836: background-color: #CCCCCC; 4837: font-weight: bold; 4838: font-size: small; 4839: text-align: center; 4840: } 4841: table.LC_nested tr.LC_info_row td.LC_left_item, 4842: table.LC_nested_outer tr th.LC_left_item { 4843: text-align: left; 4844: } 4845: table.LC_nested td { 4846: background-color: #FFFFFF; 4847: font-size: small; 4848: } 4849: table.LC_nested_outer tr th.LC_right_item, 4850: table.LC_nested tr.LC_info_row td.LC_right_item, 4851: table.LC_nested tr.LC_odd_row td.LC_right_item, 4852: table.LC_nested tr td.LC_right_item { 4853: text-align: right; 4854: } 4855: 4856: table.LC_nested tr.LC_odd_row td { 4857: background-color: #EEEEEE; 4858: } 4859: 4860: table.LC_createuser { 4861: } 4862: 4863: table.LC_createuser tr.LC_section_row td { 4864: font-size: small; 4865: } 4866: 4867: table.LC_createuser tr.LC_info_row td { 4868: background-color: #CCCCCC; 4869: font-weight: bold; 4870: text-align: center; 4871: } 4872: 4873: table.LC_calendar { 4874: border: 1px solid #000000; 4875: border-collapse: collapse; 4876: } 4877: table.LC_calendar_pickdate { 4878: font-size: xx-small; 4879: } 4880: table.LC_calendar tr td { 4881: border: 1px solid #000000; 4882: vertical-align: top; 4883: } 4884: table.LC_calendar tr td.LC_calendar_day_empty { 4885: background-color: $data_table_dark; 4886: } 4887: table.LC_calendar tr td.LC_calendar_day_current { 4888: background-color: $data_table_highlight; 4889: } 4890: 4891: table.LC_mail_list tr.LC_mail_new { 4892: background-color: $mail_new; 4893: } 4894: table.LC_mail_list tr.LC_mail_new:hover { 4895: background-color: $mail_new_hover; 4896: } 4897: table.LC_mail_list tr.LC_mail_read { 4898: background-color: $mail_read; 4899: } 4900: table.LC_mail_list tr.LC_mail_read:hover { 4901: background-color: $mail_read_hover; 4902: } 4903: table.LC_mail_list tr.LC_mail_replied { 4904: background-color: $mail_replied; 4905: } 4906: table.LC_mail_list tr.LC_mail_replied:hover { 4907: background-color: $mail_replied_hover; 4908: } 4909: table.LC_mail_list tr.LC_mail_other { 4910: background-color: $mail_other; 4911: } 4912: table.LC_mail_list tr.LC_mail_other:hover { 4913: background-color: $mail_other_hover; 4914: } 4915: table.LC_mail_list tr.LC_mail_even { 4916: } 4917: table.LC_mail_list tr.LC_mail_odd { 4918: } 4919: 4920: table.LC_data_table tr > td.LC_browser_file, 4921: table.LC_data_table tr > td.LC_browser_file_published { 4922: background: #CCFF88; 4923: } 4924: table.LC_data_table tr > td.LC_browser_file_locked, 4925: table.LC_data_table tr > td.LC_browser_file_unpublished { 4926: background: #FFAA99; 4927: } 4928: table.LC_data_table tr > td.LC_browser_file_obsolete { 4929: background: #AAAAAA; 4930: } 4931: table.LC_data_table tr > td.LC_browser_file_modified, 4932: table.LC_data_table tr > td.LC_browser_file_metamodified { 4933: background: #FFFF77; 4934: } 4935: table.LC_data_table tr.LC_browser_folder > td { 4936: background: #CCCCFF; 4937: } 4938: 4939: table.LC_data_table tr > td.LC_roles_is { 4940: /* background: #77FF77; */ 4941: } 4942: table.LC_data_table tr > td.LC_roles_future { 4943: background: #FFFF77; 4944: } 4945: table.LC_data_table tr > td.LC_roles_will { 4946: background: #FFAA77; 4947: } 4948: table.LC_data_table tr > td.LC_roles_expired { 4949: background: #FF7777; 4950: } 4951: table.LC_data_table tr > td.LC_roles_will_not { 4952: background: #AAFF77; 4953: } 4954: table.LC_data_table tr > td.LC_roles_selected { 4955: background: #11CC55; 4956: } 4957: 4958: span.LC_current_location { 4959: font-size:larger; 4960: background: $pgbg; 4961: } 4962: 4963: span.LC_parm_menu_item { 4964: font-size: larger; 4965: font-family: $sans; 4966: } 4967: span.LC_parm_scope_all { 4968: color: red; 4969: } 4970: span.LC_parm_scope_folder { 4971: color: green; 4972: } 4973: span.LC_parm_scope_resource { 4974: color: orange; 4975: } 4976: span.LC_parm_part { 4977: color: blue; 4978: } 4979: span.LC_parm_folder, span.LC_parm_symb { 4980: font-size: x-small; 4981: font-family: $mono; 4982: color: #AAAAAA; 4983: } 4984: 4985: td.LC_parm_overview_level_menu, td.LC_parm_overview_map_menu, 4986: td.LC_parm_overview_parm_selectors, td.LC_parm_overview_parm_restrictions { 4987: border: 1px solid black; 4988: border-collapse: collapse; 4989: } 4990: table.LC_parm_overview_restrictions td { 4991: border-width: 1px 4px 1px 4px; 4992: border-style: solid; 4993: border-color: $pgbg; 4994: text-align: center; 4995: } 4996: table.LC_parm_overview_restrictions th { 4997: background: $tabbg; 4998: border-width: 1px 4px 1px 4px; 4999: border-style: solid; 5000: border-color: $pgbg; 5001: } 5002: table#LC_helpmenu { 5003: border: 0px; 5004: height: 55px; 5005: border-spacing: 0px; 5006: } 5007: 5008: table#LC_helpmenu fieldset legend { 5009: font-size: larger; 5010: font-weight: bold; 5011: } 5012: table#LC_helpmenu_links { 5013: width: 100%; 5014: border: 1px solid black; 5015: background: $pgbg; 5016: padding: 0px; 5017: border-spacing: 1px; 5018: } 5019: table#LC_helpmenu_links tr td { 5020: padding: 1px; 5021: background: $tabbg; 5022: text-align: center; 5023: font-weight: bold; 5024: } 5025: 5026: table#LC_helpmenu_links a:link, table#LC_helpmenu_links a:visited, 5027: table#LC_helpmenu_links a:active { 5028: text-decoration: none; 5029: color: $font; 5030: } 5031: table#LC_helpmenu_links a:hover { 5032: text-decoration: underline; 5033: color: $vlink; 5034: } 5035: 5036: .LC_chrt_popup_exists { 5037: border: 1px solid #339933; 5038: margin: -1px; 5039: } 5040: .LC_chrt_popup_up { 5041: border: 1px solid yellow; 5042: margin: -1px; 5043: } 5044: .LC_chrt_popup { 5045: border: 1px solid #8888FF; 5046: background: #CCCCFF; 5047: } 5048: table.LC_pick_box { 5049: border-collapse: separate; 5050: background: white; 5051: border: 1px solid black; 5052: border-spacing: 1px; 5053: } 5054: table.LC_pick_box td.LC_pick_box_title { 5055: background: $tabbg; 5056: font-weight: bold; 5057: text-align: right; 5058: vertical-align: top; 5059: width: 184px; 5060: padding: 8px; 5061: } 5062: table.LC_pick_box td.LC_selfenroll_pick_box_title { 5063: background: $tabbg; 5064: font-weight: bold; 5065: text-align: right; 5066: width: 350px; 5067: padding: 8px; 5068: } 5069: 5070: table.LC_pick_box td.LC_pick_box_value { 5071: text-align: left; 5072: padding: 8px; 5073: } 5074: table.LC_pick_box td.LC_pick_box_select { 5075: text-align: left; 5076: padding: 8px; 5077: } 5078: table.LC_pick_box td.LC_pick_box_separator { 5079: padding: 0px; 5080: height: 1px; 5081: background: black; 5082: } 5083: table.LC_pick_box td.LC_pick_box_submit { 5084: text-align: right; 5085: } 5086: table.LC_pick_box td.LC_evenrow_value { 5087: text-align: left; 5088: padding: 8px; 5089: background-color: $data_table_light; 5090: } 5091: table.LC_pick_box td.LC_oddrow_value { 5092: text-align: left; 5093: padding: 8px; 5094: background-color: $data_table_light; 5095: } 5096: table.LC_helpform_receipt { 5097: width: 620px; 5098: border-collapse: separate; 5099: background: white; 5100: border: 1px solid black; 5101: border-spacing: 1px; 5102: } 5103: table.LC_helpform_receipt td.LC_pick_box_title { 5104: background: $tabbg; 5105: font-weight: bold; 5106: text-align: right; 5107: width: 184px; 5108: padding: 8px; 5109: } 5110: table.LC_helpform_receipt td.LC_evenrow_value { 5111: text-align: left; 5112: padding: 8px; 5113: background-color: $data_table_light; 5114: } 5115: table.LC_helpform_receipt td.LC_oddrow_value { 5116: text-align: left; 5117: padding: 8px; 5118: background-color: $data_table_light; 5119: } 5120: table.LC_helpform_receipt td.LC_pick_box_separator { 5121: padding: 0px; 5122: height: 1px; 5123: background: black; 5124: } 5125: span.LC_helpform_receipt_cat { 5126: font-weight: bold; 5127: } 5128: table.LC_group_priv_box { 5129: background: white; 5130: border: 1px solid black; 5131: border-spacing: 1px; 5132: } 5133: table.LC_group_priv_box td.LC_pick_box_title { 5134: background: $tabbg; 5135: font-weight: bold; 5136: text-align: right; 5137: width: 184px; 5138: } 5139: table.LC_group_priv_box td.LC_groups_fixed { 5140: background: $data_table_light; 5141: text-align: center; 5142: } 5143: table.LC_group_priv_box td.LC_groups_optional { 5144: background: $data_table_dark; 5145: text-align: center; 5146: } 5147: table.LC_group_priv_box td.LC_groups_functionality { 5148: background: $data_table_darker; 5149: text-align: center; 5150: font-weight: bold; 5151: } 5152: table.LC_group_priv td { 5153: text-align: left; 5154: padding: 0px; 5155: } 5156: 5157: table.LC_notify_front_page { 5158: background: white; 5159: border: 1px solid black; 5160: padding: 8px; 5161: } 5162: table.LC_notify_front_page td { 5163: padding: 8px; 5164: } 5165: .LC_navbuttons { 5166: margin: 2ex 0ex 2ex 0ex; 5167: } 5168: .LC_topic_bar { 5169: font-family: $sans; 5170: font-weight: bold; 5171: width: 100%; 5172: background: $tabbg; 5173: vertical-align: middle; 5174: margin: 2ex 0ex 2ex 0ex; 5175: } 5176: .LC_topic_bar span { 5177: vertical-align: middle; 5178: } 5179: .LC_topic_bar img { 5180: vertical-align: bottom; 5181: } 5182: table.LC_course_group_status { 5183: margin: 20px; 5184: } 5185: table.LC_status_selector td { 5186: vertical-align: top; 5187: text-align: center; 5188: padding: 4px; 5189: } 5190: table.LC_descriptive_input td.LC_description { 5191: vertical-align: top; 5192: text-align: right; 5193: font-weight: bold; 5194: } 5195: div.LC_feedback_link { 5196: clear: both; 5197: background: white; 5198: width: 100%; 5199: } 5200: span.LC_feedback_link { 5201: background: $feedback_link_bg; 5202: font-size: larger; 5203: } 5204: span.LC_message_link { 5205: background: $feedback_link_bg; 5206: font-size: larger; 5207: position: absolute; 5208: right: 1em; 5209: } 5210: 5211: table.LC_prior_tries { 5212: border: 1px solid #000000; 5213: border-collapse: separate; 5214: border-spacing: 1px; 5215: } 5216: 5217: table.LC_prior_tries td { 5218: padding: 2px; 5219: } 5220: 5221: .LC_answer_correct { 5222: background: #AAFFAA; 5223: color: black; 5224: } 5225: .LC_answer_charged_try { 5226: background: #FFAAAA ! important; 5227: color: black; 5228: } 5229: .LC_answer_not_charged_try, 5230: .LC_answer_no_grade, 5231: .LC_answer_late { 5232: background: #FFFFAA; 5233: color: black; 5234: } 5235: .LC_answer_previous { 5236: background: #AAAAFF; 5237: color: black; 5238: } 5239: .LC_answer_no_message { 5240: background: #FFFFFF; 5241: color: black; 5242: } 5243: .LC_answer_unknown { 5244: background: orange; 5245: color: black; 5246: } 5247: 5248: 5249: span.LC_prior_numerical, 5250: span.LC_prior_string, 5251: span.LC_prior_custom, 5252: span.LC_prior_reaction, 5253: span.LC_prior_math { 5254: font-family: monospace; 5255: white-space: pre; 5256: } 5257: 5258: span.LC_prior_string { 5259: font-family: monospace; 5260: white-space: pre; 5261: } 5262: 5263: table.LC_prior_option { 5264: width: 100%; 5265: border-collapse: collapse; 5266: } 5267: table.LC_prior_rank, table.LC_prior_match { 5268: border-collapse: collapse; 5269: } 5270: table.LC_prior_option tr td, 5271: table.LC_prior_rank tr td, 5272: table.LC_prior_match tr td { 5273: border: 1px solid #000000; 5274: } 5275: 5276: span.LC_nobreak { 5277: white-space: nowrap; 5278: } 5279: 5280: span.LC_cusr_emph { 5281: font-style: italic; 5282: } 5283: 5284: span.LC_cusr_subheading { 5285: font-weight: normal; 5286: font-size: 85%; 5287: } 5288: 5289: table.LC_docs_documents { 5290: background: #BBBBBB; 5291: border-width: 0px; 5292: border-collapse: collapse; 5293: } 5294: 5295: table.LC_docs_documents td.LC_docs_document { 5296: border: 2px solid black; 5297: padding: 4px; 5298: } 5299: 5300: .LC_docs_entry_move { 5301: border: 0px; 5302: border-collapse: collapse; 5303: } 5304: 5305: .LC_docs_entry_move td { 5306: border: 2px solid #BBBBBB; 5307: background: #DDDDDD; 5308: } 5309: 5310: .LC_docs_editor td.LC_docs_entry_commands { 5311: background: #DDDDDD; 5312: font-size: x-small; 5313: } 5314: .LC_docs_copy { 5315: color: #000099; 5316: } 5317: .LC_docs_cut { 5318: color: #550044; 5319: } 5320: .LC_docs_rename { 5321: color: #009900; 5322: } 5323: .LC_docs_remove { 5324: color: #990000; 5325: } 5326: 5327: .LC_docs_reinit_warn, 5328: .LC_docs_ext_edit { 5329: font-size: x-small; 5330: } 5331: 5332: .LC_docs_editor td.LC_docs_entry_title, 5333: .LC_docs_editor td.LC_docs_entry_icon { 5334: background: #FFFFBB; 5335: } 5336: .LC_docs_editor td.LC_docs_entry_parameter { 5337: background: #BBBBFF; 5338: font-size: x-small; 5339: white-space: nowrap; 5340: } 5341: 5342: table.LC_docs_adddocs td, 5343: table.LC_docs_adddocs th { 5344: border: 1px solid #BBBBBB; 5345: padding: 4px; 5346: background: #DDDDDD; 5347: } 5348: 5349: table.LC_sty_begin { 5350: background: #BBFFBB; 5351: } 5352: table.LC_sty_end { 5353: background: #FFBBBB; 5354: } 5355: 5356: table.LC_double_column { 5357: border-width: 0px; 5358: border-collapse: collapse; 5359: width: 100%; 5360: padding: 2px; 5361: } 5362: 5363: table.LC_double_column tr td.LC_left_col { 5364: top: 2px; 5365: left: 2px; 5366: width: 47%; 5367: vertical-align: top; 5368: } 5369: 5370: table.LC_double_column tr td.LC_right_col { 5371: top: 2px; 5372: right: 2px; 5373: width: 47%; 5374: vertical-align: top; 5375: } 5376: 5377: span.LC_role_level { 5378: font-weight: bold; 5379: } 5380: 5381: div.LC_left_float { 5382: float: left; 5383: padding-right: 5%; 5384: padding-bottom: 4px; 5385: } 5386: 5387: div.LC_clear_float_header { 5388: padding-bottom: 2px; 5389: } 5390: 5391: div.LC_clear_float_footer { 5392: padding-top: 10px; 5393: clear: both; 5394: } 5395: 5396: 5397: div.LC_grade_show_user { 5398: margin-top: 20px; 5399: border: 1px solid black; 5400: } 5401: div.LC_grade_user_name { 5402: background: #DDDDEE; 5403: border-bottom: 1px solid black; 5404: font-weight: bold; 5405: font-size: large; 5406: } 5407: div.LC_grade_show_user_odd_row div.LC_grade_user_name { 5408: background: #DDEEDD; 5409: } 5410: 5411: div.LC_grade_show_problem, 5412: div.LC_grade_submissions, 5413: div.LC_grade_message_center, 5414: div.LC_grade_info_links, 5415: div.LC_grade_assign { 5416: margin: 5px; 5417: width: 99%; 5418: background: #FFFFFF; 5419: } 5420: div.LC_grade_show_problem_header, 5421: div.LC_grade_submissions_header, 5422: div.LC_grade_message_center_header, 5423: div.LC_grade_assign_header { 5424: font-weight: bold; 5425: font-size: large; 5426: } 5427: div.LC_grade_show_problem_problem, 5428: div.LC_grade_submissions_body, 5429: div.LC_grade_message_center_body, 5430: div.LC_grade_assign_body { 5431: border: 1px solid black; 5432: width: 99%; 5433: background: #FFFFFF; 5434: } 5435: span.LC_grade_check_note { 5436: font-weight: normal; 5437: font-size: medium; 5438: display: inline; 5439: position: absolute; 5440: right: 1em; 5441: } 5442: 5443: table.LC_scantron_action { 5444: width: 100%; 5445: } 5446: table.LC_scantron_action tr th { 5447: font-weight:bold; 5448: font-style:normal; 5449: } 5450: .LC_edit_problem_header, 5451: div.LC_edit_problem_footer { 5452: font-weight: normal; 5453: font-size: medium; 5454: margin: 2px; 5455: } 5456: div.LC_edit_problem_header, 5457: div.LC_edit_problem_header div, 5458: div.LC_edit_problem_footer, 5459: div.LC_edit_problem_footer div, 5460: div.LC_edit_problem_editxml_header, 5461: div.LC_edit_problem_editxml_header div { 5462: margin-top: 5px; 5463: } 5464: div.LC_edit_problem_header_edit_row { 5465: background: $tabbg; 5466: padding: 3px; 5467: margin-bottom: 5px; 5468: } 5469: div.LC_edit_problem_header_title { 5470: font-weight: bold; 5471: font-size: larger; 5472: background: $tabbg; 5473: padding: 3px; 5474: } 5475: table.LC_edit_problem_header_title { 5476: font-size: larger; 5477: font-weight: bold; 5478: width: 100%; 5479: border-color: $pgbg; 5480: border-style: solid; 5481: border-width: $border; 5482: 5483: background: $tabbg; 5484: border-collapse: collapse; 5485: padding: 0px 5486: } 5487: 5488: div.LC_edit_problem_discards { 5489: float: left; 5490: padding-bottom: 5px; 5491: } 5492: div.LC_edit_problem_saves { 5493: float: right; 5494: padding-bottom: 5px; 5495: } 5496: hr.LC_edit_problem_divide { 5497: clear: both; 5498: color: $tabbg; 5499: background-color: $tabbg; 5500: height: 3px; 5501: border: 0px; 5502: } 5503: img.stift{ 5504: border-width:0; 5505: vertical-align:middle; 5506: } 5507: 5508: table#LC_mainmenu{ 5509: margin-top:10px; 5510: width:80%; 5511: 5512: } 5513: 5514: table#LC_mainmenu td.LC_mainmenu_col_fieldset{ 5515: vertical-align: top; 5516: width: 45%; 5517: } 5518: .LC_mainmenu_fieldset_category { 5519: color: $font; 5520: background: $pgbg; 5521: font-family: $sans; 5522: font-size: small; 5523: font-weight: bold; 5524: } 5525: 5526: div.LC_createcourse { 5527: margin: 10px 10px 10px 10px; 5528: } 5529: 5530: /* ---- Remove when done ---- 5531: # The following styles is part of the redesign of LON-CAPA and are 5532: # subject to change during this project. 5533: # Don't rely on their current functionality as they might be 5534: # changed or removed. 5535: # --------------------------*/ 5536: 5537: a:hover, 5538: ol.LC_smallMenu a:hover, 5539: ol#LC_MenuBreadcrumbs a:hover, 5540: ol#LC_PathBreadcrumbs a:hover, 5541: ul#LC_TabMainMenuContent a:hover, 5542: .LC_FormSectionClearButton input:hover 5543: ul.LC_TabContent li:hover a{ 5544: color:#BF2317; 5545: text-decoration:none; 5546: } 5547: 5548: h1 { 5549: padding:5px 10px 5px 20px; 5550: line-height:130%; 5551: } 5552: 5553: h2,h3,h4,h5,h6 5554: { 5555: margin:5px 0px 5px 0px; 5556: padding:0px; 5557: line-height:130%; 5558: } 5559: .LC_hcell{ 5560: padding:3px 15px 3px 15px; 5561: margin:0px; 5562: background-color:$tabbg; 5563: border-bottom:solid 1px $lg_border_color; 5564: } 5565: .LC_noBorder { 5566: border:0px; 5567: } 5568: 5569: .LC_bgLightGrey{ 5570: background:URL(/adm/lonIcons/lightGreyBG.png) repeat-x left bottom; 5571: } 5572: 5573: 5574: /* Main Header with discription of Person, Course, etc. */ 5575: .LC_HeadRight { 5576: text-align: right; 5577: float: right; 5578: margin: 0px; 5579: padding: 0px; 5580: right:0; 5581: position:absolute; 5582: overflow:hidden; 5583: } 5584: 5585: p, .LC_ContentBox { 5586: padding: 10px; 5587: 5588: } 5589: .LC_FormSectionClearButton input { 5590: background-color:transparent; 5591: border:0px; 5592: cursor:pointer; 5593: text-decoration:underline; 5594: } 5595: 5596: 5597: dl,ul,div,fieldset { 5598: margin: 10px 10px 10px 0px; 5599: overflow:hidden; 5600: } 5601: ol.LC_smallMenu, ol#LC_PathBreadcrumbs { 5602: margin: 0px; 5603: } 5604: 5605: ol.LC_smallMenu li { 5606: display: inline; 5607: padding: 5px 5px 0px 10px; 5608: vertical-align: top; 5609: } 5610: 5611: ol.LC_smallMenu li img { 5612: vertical-align: bottom; 5613: } 5614: 5615: ol.LC_smallMenu a { 5616: font-size: 90%; 5617: color: RGB(80, 80, 80); 5618: text-decoration: none; 5619: } 5620: ol#LC_TabMainMenueContent, ul.LC_TabContent , 5621: ul.LC_TabContentBigger { 5622: display:block; 5623: list-style:none; 5624: margin: 0px; 5625: padding: 0px; 5626: } 5627: 5628: ol#LC_TabMainMenuContent li, ul.LC_TabContent li, 5629: ul.LC_TabContentBigger li{ 5630: display: inline; 5631: border-right: solid 1px $lg_border_color; 5632: float:left; 5633: line-height:140%; 5634: white-space:nowrap; 5635: } 5636: ol#LC_TabMainMenuContent li{ 5637: vertical-align: bottom; 5638: border-bottom: solid 1px RGB(175, 175, 175); 5639: padding: 5px 10px 5px 10px; 5640: margin-right:5px; 5641: margin-bottom:3px; 5642: font-weight: bold; 5643: background: url(/adm/lonIcons/lightGreyBG.png) repeat-x left top; 5644: } 5645: 5646: ol#LC_TabMainMenuContent li a{ 5647: color: RGB(47, 47, 47); 5648: text-decoration: none; 5649: } 5650: ul.LC_TabContent { 5651: min-height:1.6em; 5652: } 5653: ul.LC_TabContent li{ 5654: vertical-align:middle; 5655: padding:0px 10px 0px 10px; 5656: background-color:$tabbg; 5657: border-bottom:solid 1px $lg_border_color; 5658: } 5659: ul.LC_TabContent li a, ul.LC_TabContent li{ 5660: color:rgb(47,47,47); 5661: text-decoration:none; 5662: font-size:95%; 5663: font-weight:bold; 5664: } 5665: ul.LC_TabContent li:hover, ul.LC_TabContent li.active{ 5666: background-color:#FFFFFF; 5667: border-bottom:solid 1px #FFFFFF; 5668: } 5669: ul.LC_TabContentBigger li{ 5670: vertical-align:bottom; 5671: border-top:solid 1px $lg_border_color; 5672: border-left:solid 1px $lg_border_color; 5673: padding:5px 10px 5px 10px; 5674: margin-left:2px; 5675: background:url(/adm/lonIcons/lightGreyBG.png) repeat-x left top; 5676: } 5677: ul.LC_TabContentBigger li:hover, ul.LC_TabContentBigger li.active{ 5678: background:url(/adm/lonIcons/lightGreyBG.png) repeat-x right bottom; 5679: } 5680: ul.LC_TabContentBigger li, ul.LC_TabContentBigger li a{ 5681: font-size:110%; 5682: font-weight:bold; 5683: } 5684: #LC_CourseDocuments, #LC_SupplementalCourseDocuments 5685: { 5686: margin:0px; 5687: } 5688: 5689: .LC_hideThis 5690: { 5691: display:none; 5692: visibility:hidden; 5693: } 5694: 5695: ol#LC_MenuBreadcrumbs, ol#LC_PathBreadcrumbs { 5696: border-top: solid 1px RGB(255, 255, 255); 5697: height: 20px; 5698: line-height: 20px; 5699: vertical-align: bottom; 5700: margin: 0px 0px 30px 0px; 5701: padding-left: 10px; 5702: list-style-position: inside; 5703: background: url(/adm/lonIcons/lightGreyBG.png) repeat-x left top; 5704: } 5705: 5706: ol#LC_MenuBreadcrumbs li, ol#LC_PathBreadcrumbs li { 5707: /* 5708: background: url(/adm/lonIcons/arrow_white.png) no-repeat left center; 5709: */ 5710: display: inline; 5711: padding: 0px 0px 0px 10px; 5712: vertical-align: bottom; 5713: overflow:hidden; 5714: } 5715: 5716: ol#LC_MenuBreadcrumbs li a { 5717: text-decoration: none; 5718: font-size:90%; 5719: } 5720: ol#LC_PathBreadcrumbs li a{ 5721: text-decoration:none; 5722: font-size:100%; 5723: font-weight:bold; 5724: } 5725: .LC_ContentBoxSpecial 5726: { 5727: border: solid 1px $lg_border_color; 5728: } 5729: .LC_ContentBoxSpecialContactInfo 5730: { 5731: border: solid 1px $lg_border_color; 5732: max-width:25%; 5733: min-width:25%; 5734: } 5735: .LC_AboutMe_Image 5736: { 5737: float:left; 5738: margin-right:10px; 5739: } 5740: .LC_Clear_AboutMe_Image 5741: { 5742: clear:left; 5743: } 5744: dl.LC_ListStyleClean dt { 5745: padding-right: 5px; 5746: display: table-header-group; 5747: } 5748: 5749: dl.LC_ListStyleClean dd { 5750: display: table-row; 5751: } 5752: 5753: .LC_ListStyleClean, 5754: .LC_ListStyleSimple, 5755: .LC_ListStyleNormal, 5756: .LC_ListStyleNormal_Border, 5757: .LC_ListStyleSpecial 5758: { 5759: /*display:block; */ 5760: list-style-position: inside; 5761: list-style-type: none; 5762: overflow: hidden; 5763: padding: 0px; 5764: } 5765: 5766: .LC_ListStyleSimple li, 5767: .LC_ListStyleSimple dd, 5768: .LC_ListStyleNormal li, 5769: .LC_ListStyleNormal dd, 5770: .LC_ListStyleSpecial li, 5771: .LC_ListStyleSpecial dd 5772: { 5773: margin: 0px; 5774: padding: 5px 5px 5px 10px; 5775: clear: both; 5776: } 5777: 5778: .LC_ListStyleClean li, 5779: .LC_ListStyleClean dd { 5780: padding-top: 0px; 5781: padding-bottom: 0px; 5782: } 5783: 5784: .LC_ListStyleSimple dd, 5785: .LC_ListStyleSimple li{ 5786: border-bottom: solid 1px $lg_border_color; 5787: } 5788: 5789: .LC_ListStyleSpecial li, 5790: .LC_ListStyleSpecial dd { 5791: list-style-type: none; 5792: background-color: RGB(220, 220, 220); 5793: margin-bottom: 4px; 5794: } 5795: 5796: table.LC_SimpleTable { 5797: margin:5px; 5798: border:solid 1px $lg_border_color; 5799: } 5800: 5801: table.LC_SimpleTable tr { 5802: padding:0px; 5803: border:solid 1px $lg_border_color; 5804: } 5805: table.LC_SimpleTable thead{ 5806: background:rgb(220,220,220); 5807: } 5808: 5809: div.LC_columnSection { 5810: display: block; 5811: clear: both; 5812: overflow: hidden; 5813: margin:0px; 5814: } 5815: 5816: div.LC_columnSection>* { 5817: float: left; 5818: margin: 10px 20px 10px 0px; 5819: overflow:hidden; 5820: } 5821: 5822: .ContentBoxSpecialTemplate 5823: { 5824: border: solid 1px $lg_border_color; 5825: } 5826: .ContentBoxTemplate { 5827: padding:10px; 5828: } 5829: 5830: div.LC_columnSection > .ContentBoxTemplate, 5831: div.LC_columnSection > .ContentBoxSpecialTemplate 5832: { 5833: width: 600px; 5834: } 5835: 5836: .clear{ 5837: clear: both; 5838: line-height: 0px; 5839: font-size: 0px; 5840: height: 0px; 5841: } 5842: 5843: .LC_loginpage_container { 5844: text-align:left; 5845: margin : 0 auto; 5846: width:65%; 5847: padding: 10px; 5848: height: auto; 5849: background-color:#FFFFFF; 5850: border:1px solid #CCCCCC; 5851: } 5852: 5853: 5854: .LC_loginpage_loginContainer { 5855: float:left; 5856: width: 182px; 5857: border:1px solid #CCCCCC; 5858: background-color:$loginbg; 5859: } 5860: 5861: .LC_loginpage_loginContainer h2{ 5862: margin-top:0; 5863: display:block; 5864: background:$bgcol; 5865: color:$textcol; 5866: padding-left:5px; 5867: } 5868: .LC_loginpage_loginInfo { 5869: margin-left:20px; 5870: float:left; 5871: width:30%; 5872: border:1px solid #CCCCCC; 5873: padding:10px; 5874: } 5875: 5876: .LC_loginpage_loginDomain { 5877: margin-right:20px; 5878: width:20%; 5879: float:left; 5880: padding:10px; 5881: } 5882: 5883: .LC_loginpage_space { 5884: clear: both; 5885: margin-bottom: 20px; 5886: border-bottom: 1px solid #CCCCCC; 5887: } 5888: 5889: table em{ 5890: font-weight: bold; 5891: font-style: normal; 5892: } 5893: 5894: table#LC_tableOfContent{ 5895: border-collapse: collapse; 5896: border-spacing: 0; 5897: padding: 3px; 5898: border: 0; 5899: background-color: #FFFFFF; 5900: font-size: 90%; 5901: } 5902: table#LC_tableOfContent a { 5903: text-decoration: none; 5904: } 5905: 5906: table#LC_tableOfContent tr.LC_trOdd{ 5907: background-color: #EEEEEE; 5908: } 5909: 5910: table#LC_tableOfContent img{ 5911: border: none; 5912: height: 1.3em; 5913: vertical-align: text-bottom; 5914: margin-right: 0.3em; 5915: } 5916: END 5917: } 5918: 5919: =pod 5920: 5921: =item * &headtag() 5922: 5923: Returns a uniform footer for LON-CAPA web pages. 5924: 5925: Inputs: $title - optional title for the head 5926: $head_extra - optional extra HTML to put inside the <head> 5927: $args - optional arguments 5928: force_register - if is true call registerurl so the remote is 5929: informed 5930: redirect -> array ref of 5931: 1- seconds before redirect occurs 5932: 2- url to redirect to 5933: 3- whether the side effect should occur 5934: (side effect of setting 5935: $env{'internal.head.redirect'} to the url 5936: redirected too) 5937: domain -> force to color decorate a page for a specific 5938: domain 5939: function -> force usage of a specific rolish color scheme 5940: bgcolor -> override the default page bgcolor 5941: no_auto_mt_title 5942: -> prevent &mt()ing the title arg 5943: 5944: =cut 5945: 5946: sub headtag { 5947: my ($title,$head_extra,$args) = @_; 5948: 5949: my $function = $args->{'function'} || &get_users_function(); 5950: my $domain = $args->{'domain'} || &determinedomain(); 5951: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain); 5952: my $url = join(':',$env{'user.name'},$env{'user.domain'}, 5953: $Apache::lonnet::perlvar{'lonVersion'}, 5954: #time(), 5955: $env{'environment.color.timestamp'}, 5956: $function,$domain,$bgcolor); 5957: 5958: $url = '/adm/css/'.&escape($url).'.css'; 5959: 5960: my $result = 5961: '<head>'. 5962: &font_settings(); 5963: 5964: if (!$args->{'frameset'}) { 5965: $result .= &Apache::lonhtmlcommon::htmlareaheaders(); 5966: } 5967: if ($args->{'force_register'}) { 5968: $result .= &Apache::lonmenu::registerurl(1); 5969: } 5970: if (!$args->{'no_nav_bar'} 5971: && !$args->{'only_body'} 5972: && !$args->{'frameset'}) { 5973: $result .= &help_menu_js(); 5974: } 5975: 5976: if (ref($args->{'redirect'})) { 5977: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}}; 5978: $url = &Apache::lonenc::check_encrypt($url); 5979: if (!$inhibit_continue) { 5980: $env{'internal.head.redirect'} = $url; 5981: } 5982: $result.=<<ADDMETA 5983: <meta http-equiv="pragma" content="no-cache" /> 5984: <meta http-equiv="Refresh" content="$time; url=$url" /> 5985: ADDMETA 5986: } 5987: if (!defined($title)) { 5988: $title = 'The LearningOnline Network with CAPA'; 5989: } 5990: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); } 5991: $result .= '<title> LON-CAPA '.$title.'</title>' 5992: .'<link rel="stylesheet" type="text/css" href="'.$url.'" />' 5993: .$head_extra; 5994: return $result; 5995: } 5996: 5997: =pod 5998: 5999: =item * &font_settings() 6000: 6001: Returns neccessary <meta> to set the proper encoding 6002: 6003: Inputs: none 6004: 6005: =cut 6006: 6007: sub font_settings { 6008: my $headerstring=''; 6009: if (!$env{'browser.mathml'} && $env{'browser.unicode'}) { 6010: $headerstring.= 6011: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'; 6012: } 6013: return $headerstring; 6014: } 6015: 6016: =pod 6017: 6018: =item * &xml_begin() 6019: 6020: Returns the needed doctype and <html> 6021: 6022: Inputs: none 6023: 6024: =cut 6025: 6026: sub xml_begin { 6027: my $output=''; 6028: 6029: if ($env{'internal.start_page'}==1) { 6030: &Apache::lonhtmlcommon::init_htmlareafields(); 6031: } 6032: 6033: if ($env{'browser.mathml'}) { 6034: $output='<?xml version="1.0"?>' 6035: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n" 6036: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" ' 6037: 6038: # .'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" [<!ENTITY mathns "http://www.w3.org/1998/Math/MathML">] >' 6039: .'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">' 6040: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" ' 6041: .'xmlns="http://www.w3.org/1999/xhtml">'; 6042: } else { 6043: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>'; 6044: } 6045: return $output; 6046: } 6047: 6048: =pod 6049: 6050: =item * &endheadtag() 6051: 6052: Returns a uniform </head> for LON-CAPA web pages. 6053: 6054: Inputs: none 6055: 6056: =cut 6057: 6058: sub endheadtag { 6059: return '</head>'; 6060: } 6061: 6062: =pod 6063: 6064: =item * &head() 6065: 6066: Returns a uniform complete <head>..</head> section for LON-CAPA web pages. 6067: 6068: Inputs: 6069: 6070: =over 4 6071: 6072: $title - optional title for the page 6073: 6074: $head_extra - optional extra HTML to put inside the <head> 6075: 6076: =back 6077: 6078: =cut 6079: 6080: sub head { 6081: my ($title,$head_extra,$args) = @_; 6082: return &headtag($title,$head_extra,$args).&endheadtag(); 6083: } 6084: 6085: =pod 6086: 6087: =item * &start_page() 6088: 6089: Returns a complete <html> .. <body> section for LON-CAPA web pages. 6090: 6091: Inputs: 6092: 6093: =over 4 6094: 6095: $title - optional title for the page 6096: 6097: $head_extra - optional extra HTML to incude inside the <head> 6098: 6099: $args - additional optional args supported are: 6100: 6101: =over 8 6102: 6103: only_body -> is true will set &bodytag() onlybodytag 6104: arg on 6105: no_nav_bar -> is true will set &bodytag() notopbar arg on 6106: add_entries -> additional attributes to add to the <body> 6107: domain -> force to color decorate a page for a 6108: specific domain 6109: function -> force usage of a specific rolish color 6110: scheme 6111: redirect -> see &headtag() 6112: bgcolor -> override the default page bg color 6113: js_ready -> return a string ready for being used in 6114: a javascript writeln 6115: html_encode -> return a string ready for being used in 6116: a html attribute 6117: force_register -> if is true will turn on the &bodytag() 6118: $forcereg arg 6119: body_title -> alternate text to use instead of $title 6120: in the title box that appears, this text 6121: is not auto translated like the $title is 6122: frameset -> if true will start with a <frameset> 6123: rather than <body> 6124: no_title -> if true the title bar won't be shown 6125: skip_phases -> hash ref of 6126: head -> skip the <html><head> generation 6127: body -> skip all <body> generation 6128: no_inline_link -> if true and in remote mode, don't show the 6129: 'Switch To Inline Menu' link 6130: no_auto_mt_title -> prevent &mt()ing the title arg 6131: inherit_jsmath -> when creating popup window in a page, 6132: should it have jsmath forced on by the 6133: current page 6134: 6135: =back 6136: 6137: =back 6138: 6139: =cut 6140: 6141: sub start_page { 6142: my ($title,$head_extra,$args) = @_; 6143: #&Apache::lonnet::logthis("start_page ".join(':',caller(0))); 6144: my %head_args; 6145: foreach my $arg ('redirect','force_register','domain','function', 6146: 'bgcolor','frameset','no_nav_bar','only_body', 6147: 'no_auto_mt_title') { 6148: if (defined($args->{$arg})) { 6149: $head_args{$arg} = $args->{$arg}; 6150: } 6151: } 6152: 6153: $env{'internal.start_page'}++; 6154: my $result; 6155: if (! exists($args->{'skip_phases'}{'head'}) ) { 6156: $result.= 6157: &xml_begin(). 6158: &headtag($title,$head_extra,\%head_args).&endheadtag(); 6159: } 6160: 6161: if (! exists($args->{'skip_phases'}{'body'}) ) { 6162: if ($args->{'frameset'}) { 6163: my $attr_string = &make_attr_string($args->{'force_register'}, 6164: $args->{'add_entries'}); 6165: $result .= "\n<frameset $attr_string>\n"; 6166: } else { 6167: $result .= 6168: &bodytag($title, 6169: $args->{'function'}, $args->{'add_entries'}, 6170: $args->{'only_body'}, $args->{'domain'}, 6171: $args->{'force_register'}, $args->{'body_title'}, 6172: $args->{'no_nav_bar'}, $args->{'bgcolor'}, 6173: $args->{'no_title'}, $args->{'no_inline_link'}, 6174: $args); 6175: } 6176: } 6177: 6178: if ($args->{'js_ready'}) { 6179: $result = &js_ready($result); 6180: } 6181: if ($args->{'html_encode'}) { 6182: $result = &html_encode($result); 6183: } 6184: 6185: if (exists($args->{'bread_crumbs'})) { 6186: &Apache::lonhtmlcommon::clear_breadcrumbs(); 6187: if (ref($args->{'bread_crumbs'}) eq 'ARRAY') { 6188: foreach my $crumb (@{$args->{'bread_crumbs'}}){ 6189: &Apache::lonhtmlcommon::add_breadcrumb($crumb); 6190: } 6191: } 6192: $result .= &Apache::lonhtmlcommon::breadcrumbs(); 6193: } 6194: 6195: return $result; 6196: } 6197: 6198: 6199: =pod 6200: 6201: =item * &head() 6202: 6203: Returns a complete </body></html> section for LON-CAPA web pages. 6204: 6205: Inputs: $args - additional optional args supported are: 6206: js_ready -> return a string ready for being used in 6207: a javascript writeln 6208: html_encode -> return a string ready for being used in 6209: a html attribute 6210: frameset -> if true will start with a <frameset> 6211: rather than <body> 6212: dicsussion -> if true will get discussion from 6213: lonxml::xmlend 6214: (you can pass the target and parser arguments 6215: through optional 'target' and 'parser' args 6216: to this routine) 6217: 6218: =cut 6219: 6220: sub end_page { 6221: my ($args) = @_; 6222: $env{'internal.end_page'}++; 6223: my $result; 6224: if ($args->{'discussion'}) { 6225: my ($target,$parser); 6226: if (ref($args->{'discussion'})) { 6227: ($target,$parser) =($args->{'discussion'}{'target'}, 6228: $args->{'discussion'}{'parser'}); 6229: } 6230: $result .= &Apache::lonxml::xmlend($target,$parser); 6231: } 6232: 6233: if ($args->{'frameset'}) { 6234: $result .= '</frameset>'; 6235: } else { 6236: $result .= &endbodytag($args); 6237: } 6238: $result .= "\n</html>"; 6239: 6240: if ($args->{'js_ready'}) { 6241: $result = &js_ready($result); 6242: } 6243: 6244: if ($args->{'html_encode'}) { 6245: $result = &html_encode($result); 6246: } 6247: 6248: return $result; 6249: } 6250: 6251: sub html_encode { 6252: my ($result) = @_; 6253: 6254: $result = &HTML::Entities::encode($result,'<>&"'); 6255: 6256: return $result; 6257: } 6258: sub js_ready { 6259: my ($result) = @_; 6260: 6261: $result =~ s/[\n\r]/ /xmsg; 6262: $result =~ s/\\/\\\\/xmsg; 6263: $result =~ s/'/\\'/xmsg; 6264: $result =~ s{</}{<\\/}xmsg; 6265: 6266: return $result; 6267: } 6268: 6269: sub validate_page { 6270: if ( exists($env{'internal.start_page'}) 6271: && $env{'internal.start_page'} > 1) { 6272: &Apache::lonnet::logthis('start_page called multiple times '. 6273: $env{'internal.start_page'}.' '. 6274: $ENV{'request.filename'}); 6275: } 6276: if ( exists($env{'internal.end_page'}) 6277: && $env{'internal.end_page'} > 1) { 6278: &Apache::lonnet::logthis('end_page called multiple times '. 6279: $env{'internal.end_page'}.' '. 6280: $env{'request.filename'}); 6281: } 6282: if ( exists($env{'internal.start_page'}) 6283: && ! exists($env{'internal.end_page'})) { 6284: &Apache::lonnet::logthis('start_page called without end_page '. 6285: $env{'request.filename'}); 6286: } 6287: if ( ! exists($env{'internal.start_page'}) 6288: && exists($env{'internal.end_page'})) { 6289: &Apache::lonnet::logthis('end_page called without start_page'. 6290: $env{'request.filename'}); 6291: } 6292: } 6293: 6294: sub simple_error_page { 6295: my ($r,$title,$msg) = @_; 6296: my $page = 6297: &Apache::loncommon::start_page($title). 6298: &mt($msg). 6299: &Apache::loncommon::end_page(); 6300: if (ref($r)) { 6301: $r->print($page); 6302: return; 6303: } 6304: return $page; 6305: } 6306: 6307: { 6308: my @row_count; 6309: sub start_data_table { 6310: my ($add_class) = @_; 6311: my $css_class = (join(' ','LC_data_table',$add_class)); 6312: unshift(@row_count,0); 6313: return '<table class="'.$css_class.'">'."\n"; 6314: } 6315: 6316: sub end_data_table { 6317: shift(@row_count); 6318: return '</table>'."\n";; 6319: } 6320: 6321: sub start_data_table_row { 6322: my ($add_class) = @_; 6323: $row_count[0]++; 6324: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row'; 6325: $css_class = (join(' ',$css_class,$add_class)); 6326: return '<tr class="'.$css_class.'">'."\n";; 6327: } 6328: 6329: sub continue_data_table_row { 6330: my ($add_class) = @_; 6331: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row'; 6332: $css_class = (join(' ',$css_class,$add_class)); 6333: return '<tr class="'.$css_class.'">'."\n";; 6334: } 6335: 6336: sub end_data_table_row { 6337: return '</tr>'."\n";; 6338: } 6339: 6340: sub start_data_table_empty_row { 6341: # $row_count[0]++; 6342: return '<tr class="LC_empty_row" >'."\n";; 6343: } 6344: 6345: sub end_data_table_empty_row { 6346: return '</tr>'."\n";; 6347: } 6348: 6349: sub start_data_table_header_row { 6350: return '<tr class="LC_header_row">'."\n";; 6351: } 6352: 6353: sub end_data_table_header_row { 6354: return '</tr>'."\n";; 6355: } 6356: } 6357: 6358: =pod 6359: 6360: =item * &inhibit_menu_check($arg) 6361: 6362: Checks for a inhibitmenu state and generates output to preserve it 6363: 6364: Inputs: $arg - can be any of 6365: - undef - in which case the return value is a string 6366: to add into arguments list of a uri 6367: - 'input' - in which case the return value is a HTML 6368: <form> <input> field of type hidden to 6369: preserve the value 6370: - a url - in which case the return value is the url with 6371: the neccesary cgi args added to preserve the 6372: inhibitmenu state 6373: - a ref to a url - no return value, but the string is 6374: updated to include the neccessary cgi 6375: args to preserve the inhibitmenu state 6376: 6377: =cut 6378: 6379: sub inhibit_menu_check { 6380: my ($arg) = @_; 6381: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']); 6382: if ($arg eq 'input') { 6383: if ($env{'form.inhibitmenu'}) { 6384: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />'; 6385: } else { 6386: return 6387: } 6388: } 6389: if ($env{'form.inhibitmenu'}) { 6390: if (ref($arg)) { 6391: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'}; 6392: } elsif ($arg eq '') { 6393: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'}; 6394: } else { 6395: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'}; 6396: } 6397: } 6398: if (!ref($arg)) { 6399: return $arg; 6400: } 6401: } 6402: 6403: ############################################### 6404: 6405: =pod 6406: 6407: =back 6408: 6409: =head1 User Information Routines 6410: 6411: =over 4 6412: 6413: =item * &get_users_function() 6414: 6415: Used by &bodytag to determine the current users primary role. 6416: Returns either 'student','coordinator','admin', or 'author'. 6417: 6418: =cut 6419: 6420: ############################################### 6421: sub get_users_function { 6422: my $function = 'student'; 6423: if ($env{'request.role'}=~/^(cc|in|ta|ep)/) { 6424: $function='coordinator'; 6425: } 6426: if ($env{'request.role'}=~/^(su|dc|ad|li)/) { 6427: $function='admin'; 6428: } 6429: if (($env{'request.role'}=~/^(au|ca)/) || 6430: ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) { 6431: $function='author'; 6432: } 6433: return $function; 6434: } 6435: 6436: ############################################### 6437: 6438: =pod 6439: 6440: =item * &check_user_status() 6441: 6442: Determines current status of supplied role for a 6443: specific user. Roles can be active, previous or future. 6444: 6445: Inputs: 6446: user's domain, user's username, course's domain, 6447: course's number, optional section ID. 6448: 6449: Outputs: 6450: role status: active, previous or future. 6451: 6452: =cut 6453: 6454: sub check_user_status { 6455: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_; 6456: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname); 6457: my @uroles = keys %userinfo; 6458: my $srchstr; 6459: my $active_chk = 'none'; 6460: my $now = time; 6461: if (@uroles > 0) { 6462: if (($role eq 'cc') || ($sec eq '') || (!defined($sec))) { 6463: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role; 6464: } else { 6465: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role; 6466: } 6467: if (grep/^\Q$srchstr\E$/,@uroles) { 6468: my $role_end = 0; 6469: my $role_start = 0; 6470: $active_chk = 'active'; 6471: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) { 6472: $role_end = $1; 6473: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) { 6474: $role_start = $1; 6475: } 6476: } 6477: if ($role_start > 0) { 6478: if ($now < $role_start) { 6479: $active_chk = 'future'; 6480: } 6481: } 6482: if ($role_end > 0) { 6483: if ($now > $role_end) { 6484: $active_chk = 'previous'; 6485: } 6486: } 6487: } 6488: } 6489: return $active_chk; 6490: } 6491: 6492: ############################################### 6493: 6494: =pod 6495: 6496: =item * &get_sections() 6497: 6498: Determines all the sections for a course including 6499: sections with students and sections containing other roles. 6500: Incoming parameters: 6501: 6502: 1. domain 6503: 2. course number 6504: 3. reference to array containing roles for which sections should 6505: be gathered (optional). 6506: 4. reference to array containing status types for which sections 6507: should be gathered (optional). 6508: 6509: If the third argument is undefined, sections are gathered for any role. 6510: If the fourth argument is undefined, sections are gathered for any status. 6511: Permissible values are 'active' or 'future' or 'previous'. 6512: 6513: Returns section hash (keys are section IDs, values are 6514: number of users in each section), subject to the 6515: optional roles filter, optional status filter 6516: 6517: =cut 6518: 6519: ############################################### 6520: sub get_sections { 6521: my ($cdom,$cnum,$possible_roles,$possible_status) = @_; 6522: if (!defined($cdom) || !defined($cnum)) { 6523: my $cid = $env{'request.course.id'}; 6524: 6525: return if (!defined($cid)); 6526: 6527: $cdom = $env{'course.'.$cid.'.domain'}; 6528: $cnum = $env{'course.'.$cid.'.num'}; 6529: } 6530: 6531: my %sectioncount; 6532: my $now = time; 6533: 6534: if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) { 6535: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum); 6536: my $sec_index = &Apache::loncoursedata::CL_SECTION(); 6537: my $status_index = &Apache::loncoursedata::CL_STATUS(); 6538: my $start_index = &Apache::loncoursedata::CL_START(); 6539: my $end_index = &Apache::loncoursedata::CL_END(); 6540: my $status; 6541: while (my ($student,$data) = each(%$classlist)) { 6542: my ($section,$stu_status,$start,$end) = ($data->[$sec_index], 6543: $data->[$status_index], 6544: $data->[$start_index], 6545: $data->[$end_index]); 6546: if ($stu_status eq 'Active') { 6547: $status = 'active'; 6548: } elsif ($end < $now) { 6549: $status = 'previous'; 6550: } elsif ($start > $now) { 6551: $status = 'future'; 6552: } 6553: if ($section ne '-1' && $section !~ /^\s*$/) { 6554: if ((!defined($possible_status)) || (($status ne '') && 6555: (grep/^\Q$status\E$/,@{$possible_status}))) { 6556: $sectioncount{$section}++; 6557: } 6558: } 6559: } 6560: } 6561: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum); 6562: foreach my $user (sort(keys(%courseroles))) { 6563: if ($user !~ /^(\w{2})/) { next; } 6564: my ($role) = ($user =~ /^(\w{2})/); 6565: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; } 6566: my ($section,$status); 6567: if ($role eq 'cr' && 6568: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) { 6569: $section=$1; 6570: } 6571: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; } 6572: if (!defined($section) || $section eq '-1') { next; } 6573: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/); 6574: if ($end == -1 && $start == -1) { 6575: next; #deleted role 6576: } 6577: if (!defined($possible_status)) { 6578: $sectioncount{$section}++; 6579: } else { 6580: if ((!$end || $end >= $now) && (!$start || $start <= $now)) { 6581: $status = 'active'; 6582: } elsif ($end < $now) { 6583: $status = 'future'; 6584: } elsif ($start > $now) { 6585: $status = 'previous'; 6586: } 6587: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) { 6588: $sectioncount{$section}++; 6589: } 6590: } 6591: } 6592: return %sectioncount; 6593: } 6594: 6595: ############################################### 6596: 6597: =pod 6598: 6599: =item * &get_course_users() 6600: 6601: Retrieves usernames:domains for users in the specified course 6602: with specific role(s), and access status. 6603: 6604: Incoming parameters: 6605: 1. course domain 6606: 2. course number 6607: 3. access status: users must have - either active, 6608: previous, future, or all. 6609: 4. reference to array of permissible roles 6610: 5. reference to array of section restrictions (optional) 6611: 6. reference to results object (hash of hashes). 6612: 7. reference to optional userdata hash 6613: 8. reference to optional statushash 6614: 9. flag if privileged users (except those set to unhide in 6615: course settings) should be excluded 6616: Keys of top level results hash are roles. 6617: Keys of inner hashes are username:domain, with 6618: values set to access type. 6619: Optional userdata hash returns an array with arguments in the 6620: same order as loncoursedata::get_classlist() for student data. 6621: 6622: Optional statushash returns 6623: 6624: Entries for end, start, section and status are blank because 6625: of the possibility of multiple values for non-student roles. 6626: 6627: =cut 6628: 6629: ############################################### 6630: 6631: sub get_course_users { 6632: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_; 6633: my %idx = (); 6634: my %seclists; 6635: 6636: $idx{udom} = &Apache::loncoursedata::CL_SDOM(); 6637: $idx{uname} = &Apache::loncoursedata::CL_SNAME(); 6638: $idx{end} = &Apache::loncoursedata::CL_END(); 6639: $idx{start} = &Apache::loncoursedata::CL_START(); 6640: $idx{id} = &Apache::loncoursedata::CL_ID(); 6641: $idx{section} = &Apache::loncoursedata::CL_SECTION(); 6642: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME(); 6643: $idx{status} = &Apache::loncoursedata::CL_STATUS(); 6644: 6645: if (grep(/^st$/,@{$roles})) { 6646: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum); 6647: my $now = time; 6648: foreach my $student (keys(%{$classlist})) { 6649: my $match = 0; 6650: my $secmatch = 0; 6651: my $section = $$classlist{$student}[$idx{section}]; 6652: my $status = $$classlist{$student}[$idx{status}]; 6653: if ($section eq '') { 6654: $section = 'none'; 6655: } 6656: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) { 6657: if (grep(/^all$/,@{$sections})) { 6658: $secmatch = 1; 6659: } elsif ($$classlist{$student}[$idx{section}] eq '') { 6660: if (grep(/^none$/,@{$sections})) { 6661: $secmatch = 1; 6662: } 6663: } else { 6664: if (grep(/^\Q$section\E$/,@{$sections})) { 6665: $secmatch = 1; 6666: } 6667: } 6668: if (!$secmatch) { 6669: next; 6670: } 6671: } 6672: if (defined($$types{'active'})) { 6673: if ($$classlist{$student}[$idx{status}] eq 'Active') { 6674: push(@{$$users{st}{$student}},'active'); 6675: $match = 1; 6676: } 6677: } 6678: if (defined($$types{'previous'})) { 6679: if ($$classlist{$student}[$idx{status}] eq 'Expired') { 6680: push(@{$$users{st}{$student}},'previous'); 6681: $match = 1; 6682: } 6683: } 6684: if (defined($$types{'future'})) { 6685: if ($$classlist{$student}[$idx{status}] eq 'Future') { 6686: push(@{$$users{st}{$student}},'future'); 6687: $match = 1; 6688: } 6689: } 6690: if ($match) { 6691: push(@{$seclists{$student}},$section); 6692: if (ref($userdata) eq 'HASH') { 6693: $$userdata{$student} = $$classlist{$student}; 6694: } 6695: if (ref($statushash) eq 'HASH') { 6696: $statushash->{$student}{'st'}{$section} = $status; 6697: } 6698: } 6699: } 6700: } 6701: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) { 6702: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum); 6703: my $now = time; 6704: my %displaystatus = ( previous => 'Expired', 6705: active => 'Active', 6706: future => 'Future', 6707: ); 6708: my %nothide; 6709: if ($hidepriv) { 6710: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum); 6711: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) { 6712: if ($user !~ /:/) { 6713: $nothide{join(':',split(/[\@]/,$user))}=1; 6714: } else { 6715: $nothide{$user} = 1; 6716: } 6717: } 6718: } 6719: foreach my $person (sort(keys(%coursepersonnel))) { 6720: my $match = 0; 6721: my $secmatch = 0; 6722: my $status; 6723: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/); 6724: $user =~ s/:$//; 6725: my ($end,$start) = split(/:/,$coursepersonnel{$person}); 6726: if ($end == -1 || $start == -1) { 6727: next; 6728: } 6729: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) || 6730: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) { 6731: my ($uname,$udom) = split(/:/,$user); 6732: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) { 6733: if (grep(/^all$/,@{$sections})) { 6734: $secmatch = 1; 6735: } elsif ($usec eq '') { 6736: if (grep(/^none$/,@{$sections})) { 6737: $secmatch = 1; 6738: } 6739: } else { 6740: if (grep(/^\Q$usec\E$/,@{$sections})) { 6741: $secmatch = 1; 6742: } 6743: } 6744: if (!$secmatch) { 6745: next; 6746: } 6747: } 6748: if ($usec eq '') { 6749: $usec = 'none'; 6750: } 6751: if ($uname ne '' && $udom ne '') { 6752: if ($hidepriv) { 6753: if ((&Apache::lonnet::privileged($uname,$udom)) && 6754: (!$nothide{$uname.':'.$udom})) { 6755: next; 6756: } 6757: } 6758: if ($end > 0 && $end < $now) { 6759: $status = 'previous'; 6760: } elsif ($start > $now) { 6761: $status = 'future'; 6762: } else { 6763: $status = 'active'; 6764: } 6765: foreach my $type (keys(%{$types})) { 6766: if ($status eq $type) { 6767: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) { 6768: push(@{$$users{$role}{$user}},$type); 6769: } 6770: $match = 1; 6771: } 6772: } 6773: if (($match) && (ref($userdata) eq 'HASH')) { 6774: if (!exists($$userdata{$uname.':'.$udom})) { 6775: &get_user_info($udom,$uname,\%idx,$userdata); 6776: } 6777: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) { 6778: push(@{$seclists{$uname.':'.$udom}},$usec); 6779: } 6780: if (ref($statushash) eq 'HASH') { 6781: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status}; 6782: } 6783: } 6784: } 6785: } 6786: } 6787: if (grep(/^ow$/,@{$roles})) { 6788: if ((defined($cdom)) && (defined($cnum))) { 6789: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum); 6790: if ( defined($csettings{'internal.courseowner'}) ) { 6791: my $owner = $csettings{'internal.courseowner'}; 6792: next if ($owner eq ''); 6793: my ($ownername,$ownerdom); 6794: if ($owner =~ /^([^:]+):([^:]+)$/) { 6795: $ownername = $1; 6796: $ownerdom = $2; 6797: } else { 6798: $ownername = $owner; 6799: $ownerdom = $cdom; 6800: $owner = $ownername.':'.$ownerdom; 6801: } 6802: @{$$users{'ow'}{$owner}} = 'any'; 6803: if (defined($userdata) && 6804: !exists($$userdata{$owner})) { 6805: &get_user_info($ownerdom,$ownername,\%idx,$userdata); 6806: if (!grep(/^none$/,@{$seclists{$owner}})) { 6807: push(@{$seclists{$owner}},'none'); 6808: } 6809: if (ref($statushash) eq 'HASH') { 6810: $statushash->{$owner}{'ow'}{'none'} = 'Any'; 6811: } 6812: } 6813: } 6814: } 6815: } 6816: foreach my $user (keys(%seclists)) { 6817: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}}); 6818: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}}); 6819: } 6820: } 6821: return; 6822: } 6823: 6824: sub get_user_info { 6825: my ($udom,$uname,$idx,$userdata) = @_; 6826: $$userdata{$uname.':'.$udom}[$$idx{fullname}] = 6827: &plainname($uname,$udom,'lastname'); 6828: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname; 6829: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom; 6830: my %idhash = &Apache::lonnet::idrget($udom,($uname)); 6831: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname}; 6832: return; 6833: } 6834: 6835: ############################################### 6836: 6837: =pod 6838: 6839: =item * &get_user_quota() 6840: 6841: Retrieves quota assigned for storage of portfolio files for a user 6842: 6843: Incoming parameters: 6844: 1. user's username 6845: 2. user's domain 6846: 6847: Returns: 6848: 1. Disk quota (in Mb) assigned to student. 6849: 2. (Optional) Type of setting: custom or default 6850: (individually assigned or default for user's 6851: institutional status). 6852: 3. (Optional) - User's institutional status (e.g., faculty, staff 6853: or student - types as defined in localenroll::inst_usertypes 6854: for user's domain, which determines default quota for user. 6855: 4. (Optional) - Default quota which would apply to the user. 6856: 6857: If a value has been stored in the user's environment, 6858: it will return that, otherwise it returns the maximal default 6859: defined for the user's instituional status(es) in the domain. 6860: 6861: =cut 6862: 6863: ############################################### 6864: 6865: 6866: sub get_user_quota { 6867: my ($uname,$udom) = @_; 6868: my ($quota,$quotatype,$settingstatus,$defquota); 6869: if (!defined($udom)) { 6870: $udom = $env{'user.domain'}; 6871: } 6872: if (!defined($uname)) { 6873: $uname = $env{'user.name'}; 6874: } 6875: if (($udom eq '' || $uname eq '') || 6876: ($udom eq 'public') && ($uname eq 'public')) { 6877: $quota = 0; 6878: $quotatype = 'default'; 6879: $defquota = 0; 6880: } else { 6881: my $inststatus; 6882: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) { 6883: $quota = $env{'environment.portfolioquota'}; 6884: $inststatus = $env{'environment.inststatus'}; 6885: } else { 6886: my %userenv = 6887: &Apache::lonnet::get('environment',['portfolioquota', 6888: 'inststatus'],$udom,$uname); 6889: my ($tmp) = keys(%userenv); 6890: if ($tmp !~ /^(con_lost|error|no_such_host)/i) { 6891: $quota = $userenv{'portfolioquota'}; 6892: $inststatus = $userenv{'inststatus'}; 6893: } else { 6894: undef(%userenv); 6895: } 6896: } 6897: ($defquota,$settingstatus) = &default_quota($udom,$inststatus); 6898: if ($quota eq '') { 6899: $quota = $defquota; 6900: $quotatype = 'default'; 6901: } else { 6902: $quotatype = 'custom'; 6903: } 6904: } 6905: if (wantarray) { 6906: return ($quota,$quotatype,$settingstatus,$defquota); 6907: } else { 6908: return $quota; 6909: } 6910: } 6911: 6912: ############################################### 6913: 6914: =pod 6915: 6916: =item * &default_quota() 6917: 6918: Retrieves default quota assigned for storage of user portfolio files, 6919: given an (optional) user's institutional status. 6920: 6921: Incoming parameters: 6922: 1. domain 6923: 2. (Optional) institutional status(es). This is a : separated list of 6924: status types (e.g., faculty, staff, student etc.) 6925: which apply to the user for whom the default is being retrieved. 6926: If the institutional status string in undefined, the domain 6927: default quota will be returned. 6928: 6929: Returns: 6930: 1. Default disk quota (in Mb) for user portfolios in the domain. 6931: 2. (Optional) institutional type which determined the value of the 6932: default quota. 6933: 6934: If a value has been stored in the domain's configuration db, 6935: it will return that, otherwise it returns 20 (for backwards 6936: compatibility with domains which have not set up a configuration 6937: db file; the original statically defined portfolio quota was 20 Mb). 6938: 6939: If the user's status includes multiple types (e.g., staff and student), 6940: the largest default quota which applies to the user determines the 6941: default quota returned. 6942: 6943: =cut 6944: 6945: ############################################### 6946: 6947: 6948: sub default_quota { 6949: my ($udom,$inststatus) = @_; 6950: my ($defquota,$settingstatus); 6951: my %quotahash = &Apache::lonnet::get_dom('configuration', 6952: ['quotas'],$udom); 6953: if (ref($quotahash{'quotas'}) eq 'HASH') { 6954: if ($inststatus ne '') { 6955: my @statuses = split(/:/,$inststatus); 6956: foreach my $item (@statuses) { 6957: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') { 6958: if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') { 6959: if ($defquota eq '') { 6960: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item}; 6961: $settingstatus = $item; 6962: } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) { 6963: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item}; 6964: $settingstatus = $item; 6965: } 6966: } 6967: } else { 6968: if ($quotahash{'quotas'}{$item} ne '') { 6969: if ($defquota eq '') { 6970: $defquota = $quotahash{'quotas'}{$item}; 6971: $settingstatus = $item; 6972: } elsif ($quotahash{'quotas'}{$item} > $defquota) { 6973: $defquota = $quotahash{'quotas'}{$item}; 6974: $settingstatus = $item; 6975: } 6976: } 6977: } 6978: } 6979: } 6980: if ($defquota eq '') { 6981: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') { 6982: $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'}; 6983: } else { 6984: $defquota = $quotahash{'quotas'}{'default'}; 6985: } 6986: $settingstatus = 'default'; 6987: } 6988: } else { 6989: $settingstatus = 'default'; 6990: $defquota = 20; 6991: } 6992: if (wantarray) { 6993: return ($defquota,$settingstatus); 6994: } else { 6995: return $defquota; 6996: } 6997: } 6998: 6999: sub get_secgrprole_info { 7000: my ($cdom,$cnum,$needroles,$type) = @_; 7001: my %sections_count = &get_sections($cdom,$cnum); 7002: my @sections = (sort {$a <=> $b} keys(%sections_count)); 7003: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum); 7004: my @groups = sort(keys(%curr_groups)); 7005: my $allroles = []; 7006: my $rolehash; 7007: my $accesshash = { 7008: active => 'Currently has access', 7009: future => 'Will have future access', 7010: previous => 'Previously had access', 7011: }; 7012: if ($needroles) { 7013: $rolehash = {'all' => 'all'}; 7014: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum); 7015: if (&Apache::lonnet::error(%user_roles)) { 7016: undef(%user_roles); 7017: } 7018: foreach my $item (keys(%user_roles)) { 7019: my ($role)=split(/\:/,$item,2); 7020: if ($role eq 'cr') { next; } 7021: if ($role =~ /^cr/) { 7022: $$rolehash{$role} = (split('/',$role))[3]; 7023: } else { 7024: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type); 7025: } 7026: } 7027: foreach my $key (sort(keys(%{$rolehash}))) { 7028: push(@{$allroles},$key); 7029: } 7030: push (@{$allroles},'st'); 7031: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type); 7032: } 7033: return (\@sections,\@groups,$allroles,$rolehash,$accesshash); 7034: } 7035: 7036: sub user_picker { 7037: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype) = @_; 7038: my $currdom = $dom; 7039: my %curr_selected = ( 7040: srchin => 'dom', 7041: srchby => 'lastname', 7042: ); 7043: my $srchterm; 7044: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) { 7045: if ($srch->{'srchby'} ne '') { 7046: $curr_selected{'srchby'} = $srch->{'srchby'}; 7047: } 7048: if ($srch->{'srchin'} ne '') { 7049: $curr_selected{'srchin'} = $srch->{'srchin'}; 7050: } 7051: if ($srch->{'srchtype'} ne '') { 7052: $curr_selected{'srchtype'} = $srch->{'srchtype'}; 7053: } 7054: if ($srch->{'srchdomain'} ne '') { 7055: $currdom = $srch->{'srchdomain'}; 7056: } 7057: $srchterm = $srch->{'srchterm'}; 7058: } 7059: my %lt=&Apache::lonlocal::texthash( 7060: 'usr' => 'Search criteria', 7061: 'doma' => 'Domain/institution to search', 7062: 'uname' => 'username', 7063: 'lastname' => 'last name', 7064: 'lastfirst' => 'last name, first name', 7065: 'crs' => 'in this course', 7066: 'dom' => 'in selected LON-CAPA domain', 7067: 'alc' => 'all LON-CAPA', 7068: 'instd' => 'in institutional directory for selected domain', 7069: 'exact' => 'is', 7070: 'contains' => 'contains', 7071: 'begins' => 'begins with', 7072: 'youm' => "You must include some text to search for.", 7073: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.", 7074: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.", 7075: 'yomc' => "You must choose a domain when using an institutional directory search.", 7076: 'ymcd' => "You must choose a domain when using a domain search.", 7077: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.", 7078: 'whse' => "When searching by last,first you must include at least one character in the first name.", 7079: 'thfo' => "The following need to be corrected before the search can be run:", 7080: ); 7081: my $domform = &select_dom_form($currdom,'srchdomain',1,1); 7082: my $srchinsel = ' <select name="srchin">'; 7083: 7084: my @srchins = ('crs','dom','alc','instd'); 7085: 7086: foreach my $option (@srchins) { 7087: # FIXME 'alc' option unavailable until 7088: # loncreateuser::print_user_query_page() 7089: # has been completed. 7090: next if ($option eq 'alc'); 7091: next if ($option eq 'crs' && !$env{'request.course.id'}); 7092: if ($curr_selected{'srchin'} eq $option) { 7093: $srchinsel .= ' 7094: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>'; 7095: } else { 7096: $srchinsel .= ' 7097: <option value="'.$option.'">'.$lt{$option}.'</option>'; 7098: } 7099: } 7100: $srchinsel .= "\n </select>\n"; 7101: 7102: my $srchbysel = ' <select name="srchby">'; 7103: foreach my $option ('lastname','lastfirst','uname') { 7104: if ($curr_selected{'srchby'} eq $option) { 7105: $srchbysel .= ' 7106: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>'; 7107: } else { 7108: $srchbysel .= ' 7109: <option value="'.$option.'">'.$lt{$option}.'</option>'; 7110: } 7111: } 7112: $srchbysel .= "\n </select>\n"; 7113: 7114: my $srchtypesel = ' <select name="srchtype">'; 7115: foreach my $option ('begins','contains','exact') { 7116: if ($curr_selected{'srchtype'} eq $option) { 7117: $srchtypesel .= ' 7118: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>'; 7119: } else { 7120: $srchtypesel .= ' 7121: <option value="'.$option.'">'.$lt{$option}.'</option>'; 7122: } 7123: } 7124: $srchtypesel .= "\n </select>\n"; 7125: 7126: my ($newuserscript,$new_user_create); 7127: 7128: if ($forcenewuser) { 7129: if (ref($srch) eq 'HASH') { 7130: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $env{'request.role.domain'}) { 7131: if ($cancreate) { 7132: $new_user_create = '<p> <input type="submit" name="forcenew" value="'.&HTML::Entities::encode(&mt('Make new user "[_1]"',$srchterm),'<>&"').'" onclick="javascript:setSearch(\'1\','.$caller.');" /> </p>'; 7133: } else { 7134: my $helplink = ' href="javascript:helpMenu('."'display'".')"'; 7135: my %usertypetext = ( 7136: official => 'institutional', 7137: unofficial => 'non-institutional', 7138: ); 7139: $new_user_create = '<br /><span class="LC_warning">'.&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.").' '.&mt('Contact the <a[_1]>helpdesk</a> for assistance.',$helplink).'</span><br /><br />'; 7140: } 7141: } 7142: } 7143: 7144: $newuserscript = <<"ENDSCRIPT"; 7145: 7146: function setSearch(createnew,callingForm) { 7147: if (createnew == 1) { 7148: for (var i=0; i<callingForm.srchby.length; i++) { 7149: if (callingForm.srchby.options[i].value == 'uname') { 7150: callingForm.srchby.selectedIndex = i; 7151: } 7152: } 7153: for (var i=0; i<callingForm.srchin.length; i++) { 7154: if ( callingForm.srchin.options[i].value == 'dom') { 7155: callingForm.srchin.selectedIndex = i; 7156: } 7157: } 7158: for (var i=0; i<callingForm.srchtype.length; i++) { 7159: if (callingForm.srchtype.options[i].value == 'exact') { 7160: callingForm.srchtype.selectedIndex = i; 7161: } 7162: } 7163: for (var i=0; i<callingForm.srchdomain.length; i++) { 7164: if (callingForm.srchdomain.options[i].value == '$env{'request.role.domain'}') { 7165: callingForm.srchdomain.selectedIndex = i; 7166: } 7167: } 7168: } 7169: } 7170: ENDSCRIPT 7171: 7172: } 7173: 7174: my $output = <<"END_BLOCK"; 7175: <script type="text/javascript"> 7176: function validateEntry(callingForm) { 7177: 7178: var checkok = 1; 7179: var srchin; 7180: for (var i=0; i<callingForm.srchin.length; i++) { 7181: if ( callingForm.srchin[i].checked ) { 7182: srchin = callingForm.srchin[i].value; 7183: } 7184: } 7185: 7186: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value; 7187: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value; 7188: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value; 7189: var srchterm = callingForm.srchterm.value; 7190: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value; 7191: var msg = ""; 7192: 7193: if (srchterm == "") { 7194: checkok = 0; 7195: msg += "$lt{'youm'}\\n"; 7196: } 7197: 7198: if (srchtype== 'begins') { 7199: if (srchterm.length < 2) { 7200: checkok = 0; 7201: msg += "$lt{'thte'}\\n"; 7202: } 7203: } 7204: 7205: if (srchtype== 'contains') { 7206: if (srchterm.length < 3) { 7207: checkok = 0; 7208: msg += "$lt{'thet'}\\n"; 7209: } 7210: } 7211: if (srchin == 'instd') { 7212: if (srchdomain == '') { 7213: checkok = 0; 7214: msg += "$lt{'yomc'}\\n"; 7215: } 7216: } 7217: if (srchin == 'dom') { 7218: if (srchdomain == '') { 7219: checkok = 0; 7220: msg += "$lt{'ymcd'}\\n"; 7221: } 7222: } 7223: if (srchby == 'lastfirst') { 7224: if (srchterm.indexOf(",") == -1) { 7225: checkok = 0; 7226: msg += "$lt{'whus'}\\n"; 7227: } 7228: if (srchterm.indexOf(",") == srchterm.length -1) { 7229: checkok = 0; 7230: msg += "$lt{'whse'}\\n"; 7231: } 7232: } 7233: if (checkok == 0) { 7234: alert("$lt{'thfo'}\\n"+msg); 7235: return; 7236: } 7237: if (checkok == 1) { 7238: callingForm.submit(); 7239: } 7240: } 7241: 7242: $newuserscript 7243: 7244: </script> 7245: 7246: $new_user_create 7247: 7248: <table> 7249: <tr> 7250: <td>$lt{'doma'}:</td> 7251: <td>$domform</td> 7252: </td> 7253: </tr> 7254: <tr> 7255: <td>$lt{'usr'}:</td> 7256: <td>$srchbysel 7257: $srchtypesel 7258: <input type="text" size="15" name="srchterm" value="$srchterm" /> 7259: $srchinsel 7260: </td> 7261: </tr> 7262: </table> 7263: <br /> 7264: END_BLOCK 7265: 7266: return $output; 7267: } 7268: 7269: sub user_rule_check { 7270: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_; 7271: my $response; 7272: if (ref($usershash) eq 'HASH') { 7273: foreach my $user (keys(%{$usershash})) { 7274: my ($uname,$udom) = split(/:/,$user); 7275: next if ($udom eq '' || $uname eq ''); 7276: my ($id,$newuser); 7277: if (ref($usershash->{$user}) eq 'HASH') { 7278: $newuser = $usershash->{$user}->{'newuser'}; 7279: $id = $usershash->{$user}->{'id'}; 7280: } 7281: my $inst_response; 7282: if (ref($checks) eq 'HASH') { 7283: if (defined($checks->{'username'})) { 7284: ($inst_response,%{$inst_results->{$user}}) = 7285: &Apache::lonnet::get_instuser($udom,$uname); 7286: } elsif (defined($checks->{'id'})) { 7287: ($inst_response,%{$inst_results->{$user}}) = 7288: &Apache::lonnet::get_instuser($udom,undef,$id); 7289: } 7290: } else { 7291: ($inst_response,%{$inst_results->{$user}}) = 7292: &Apache::lonnet::get_instuser($udom,$uname); 7293: return; 7294: } 7295: if (!$got_rules->{$udom}) { 7296: my %domconfig = &Apache::lonnet::get_dom('configuration', 7297: ['usercreation'],$udom); 7298: if (ref($domconfig{'usercreation'}) eq 'HASH') { 7299: foreach my $item ('username','id') { 7300: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') { 7301: $$curr_rules{$udom}{$item} = 7302: $domconfig{'usercreation'}{$item.'_rule'}; 7303: } 7304: } 7305: } 7306: $got_rules->{$udom} = 1; 7307: } 7308: foreach my $item (keys(%{$checks})) { 7309: if (ref($$curr_rules{$udom}) eq 'HASH') { 7310: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') { 7311: if (@{$$curr_rules{$udom}{$item}} > 0) { 7312: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item}); 7313: foreach my $rule (@{$$curr_rules{$udom}{$item}}) { 7314: if ($rule_check{$rule}) { 7315: $$rulematch{$user}{$item} = $rule; 7316: if ($inst_response eq 'ok') { 7317: if (ref($inst_results) eq 'HASH') { 7318: if (ref($inst_results->{$user}) eq 'HASH') { 7319: if (keys(%{$inst_results->{$user}}) == 0) { 7320: $$alerts{$item}{$udom}{$uname} = 1; 7321: } 7322: } 7323: } 7324: } 7325: last; 7326: } 7327: } 7328: } 7329: } 7330: } 7331: } 7332: } 7333: } 7334: return; 7335: } 7336: 7337: sub user_rule_formats { 7338: my ($domain,$domdesc,$curr_rules,$check) = @_; 7339: my %text = ( 7340: 'username' => 'Usernames', 7341: 'id' => 'IDs', 7342: ); 7343: my $output; 7344: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check); 7345: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) { 7346: if (@{$ruleorder} > 0) { 7347: $output = '<br />'.&mt("$text{$check} with the following format(s) may <span class=\"LC_cusr_emph\">only</span> be used for verified users at [_1]:",$domdesc).' <ul>'; 7348: foreach my $rule (@{$ruleorder}) { 7349: if (ref($curr_rules) eq 'ARRAY') { 7350: if (grep(/^\Q$rule\E$/,@{$curr_rules})) { 7351: if (ref($rules->{$rule}) eq 'HASH') { 7352: $output .= '<li>'.$rules->{$rule}{'name'}.': '. 7353: $rules->{$rule}{'desc'}.'</li>'; 7354: } 7355: } 7356: } 7357: } 7358: $output .= '</ul>'; 7359: } 7360: } 7361: return $output; 7362: } 7363: 7364: sub instrule_disallow_msg { 7365: my ($checkitem,$domdesc,$count,$mode) = @_; 7366: my $response; 7367: my %text = ( 7368: item => 'username', 7369: items => 'usernames', 7370: match => 'matches', 7371: do => 'does', 7372: action => 'a username', 7373: one => 'one', 7374: ); 7375: if ($count > 1) { 7376: $text{'item'} = 'usernames'; 7377: $text{'match'} ='match'; 7378: $text{'do'} = 'do'; 7379: $text{'action'} = 'usernames', 7380: $text{'one'} = 'ones'; 7381: } 7382: if ($checkitem eq 'id') { 7383: $text{'items'} = 'IDs'; 7384: $text{'item'} = 'ID'; 7385: $text{'action'} = 'an ID'; 7386: if ($count > 1) { 7387: $text{'item'} = 'IDs'; 7388: $text{'action'} = 'IDs'; 7389: } 7390: } 7391: $response = &mt("The $text{'item'} you chose $text{'match'} the format of $text{'items'} defined for [_1], but the $text{'item'} $text{'do'} not exist in the institutional directory.",'<span class="LC_cusr_emph">'.$domdesc.'</span>').'<br />'; 7392: if ($mode eq 'upload') { 7393: if ($checkitem eq 'username') { 7394: $response .= &mt("You will need to modify your upload file so it will include $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}."); 7395: } elsif ($checkitem eq 'id') { 7396: $response .= &mt("Either upload a file which includes $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}, or when associating fields with data columns, omit an association for the Student/Employee ID field."); 7397: } 7398: } elsif ($mode eq 'selfcreate') { 7399: if ($checkitem eq 'id') { 7400: $response .= &mt("You must either choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}, or leave the ID field blank."); 7401: } 7402: } else { 7403: if ($checkitem eq 'username') { 7404: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}."); 7405: } elsif ($checkitem eq 'id') { 7406: $response .= &mt("You must either choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}, or leave the ID field blank."); 7407: } 7408: } 7409: return $response; 7410: } 7411: 7412: sub personal_data_fieldtitles { 7413: my %fieldtitles = &Apache::lonlocal::texthash ( 7414: id => 'Student/Employee ID', 7415: permanentemail => 'E-mail address', 7416: lastname => 'Last Name', 7417: firstname => 'First Name', 7418: middlename => 'Middle Name', 7419: generation => 'Generation', 7420: gen => 'Generation', 7421: ); 7422: return %fieldtitles; 7423: } 7424: 7425: sub sorted_inst_types { 7426: my ($dom) = @_; 7427: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom); 7428: my $othertitle = &mt('All users'); 7429: if ($env{'request.course.id'}) { 7430: $othertitle = &mt('Any users'); 7431: } 7432: my @types; 7433: if (ref($order) eq 'ARRAY') { 7434: @types = @{$order}; 7435: } 7436: if (@types == 0) { 7437: if (ref($usertypes) eq 'HASH') { 7438: @types = sort(keys(%{$usertypes})); 7439: } 7440: } 7441: if (keys(%{$usertypes}) > 0) { 7442: $othertitle = &mt('Other users'); 7443: } 7444: return ($othertitle,$usertypes,\@types); 7445: } 7446: 7447: sub get_institutional_codes { 7448: my ($settings,$allcourses,$LC_code) = @_; 7449: # Get complete list of course sections to update 7450: my @currsections = (); 7451: my @currxlists = (); 7452: my $coursecode = $$settings{'internal.coursecode'}; 7453: 7454: if ($$settings{'internal.sectionnums'} ne '') { 7455: @currsections = split(/,/,$$settings{'internal.sectionnums'}); 7456: } 7457: 7458: if ($$settings{'internal.crosslistings'} ne '') { 7459: @currxlists = split(/,/,$$settings{'internal.crosslistings'}); 7460: } 7461: 7462: if (@currxlists > 0) { 7463: foreach (@currxlists) { 7464: if (m/^([^:]+):(\w*)$/) { 7465: unless (grep/^$1$/,@{$allcourses}) { 7466: push @{$allcourses},$1; 7467: $$LC_code{$1} = $2; 7468: } 7469: } 7470: } 7471: } 7472: 7473: if (@currsections > 0) { 7474: foreach (@currsections) { 7475: if (m/^(\w+):(\w*)$/) { 7476: my $sec = $coursecode.$1; 7477: my $lc_sec = $2; 7478: unless (grep/^$sec$/,@{$allcourses}) { 7479: push @{$allcourses},$sec; 7480: $$LC_code{$sec} = $lc_sec; 7481: } 7482: } 7483: } 7484: } 7485: return; 7486: } 7487: 7488: =pod 7489: 7490: =back 7491: 7492: =head1 HTTP Helpers 7493: 7494: =over 4 7495: 7496: =item * &get_unprocessed_cgi($query,$possible_names) 7497: 7498: Modify the %env hash to contain unprocessed CGI form parameters held in 7499: $query. The parameters listed in $possible_names (an array reference), 7500: will be set in $env{'form.name'} if they do not already exist. 7501: 7502: Typically called with $ENV{'QUERY_STRING'} as the first parameter. 7503: $possible_names is an ref to an array of form element names. As an example: 7504: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']); 7505: will result in $env{'form.uname'} and $env{'form.udom'} being set. 7506: 7507: =cut 7508: 7509: sub get_unprocessed_cgi { 7510: my ($query,$possible_names)= @_; 7511: # $Apache::lonxml::debug=1; 7512: foreach my $pair (split(/&/,$query)) { 7513: my ($name, $value) = split(/=/,$pair); 7514: $name = &unescape($name); 7515: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) { 7516: $value =~ tr/+/ /; 7517: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg; 7518: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) }; 7519: } 7520: } 7521: } 7522: 7523: =pod 7524: 7525: =item * &cacheheader() 7526: 7527: returns cache-controlling header code 7528: 7529: =cut 7530: 7531: sub cacheheader { 7532: unless ($env{'request.method'} eq 'GET') { return ''; } 7533: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime); 7534: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" /> 7535: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" /> 7536: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />'; 7537: return $output; 7538: } 7539: 7540: =pod 7541: 7542: =item * &no_cache($r) 7543: 7544: specifies header code to not have cache 7545: 7546: =cut 7547: 7548: sub no_cache { 7549: my ($r) = @_; 7550: if ($ENV{'REQUEST_METHOD'} ne 'GET' && 7551: $env{'request.method'} ne 'GET') { return ''; } 7552: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time)); 7553: $r->no_cache(1); 7554: $r->header_out("Expires" => $date); 7555: $r->header_out("Pragma" => "no-cache"); 7556: } 7557: 7558: sub content_type { 7559: my ($r,$type,$charset) = @_; 7560: if ($r) { 7561: # Note that printout.pl calls this with undef for $r. 7562: &no_cache($r); 7563: } 7564: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; } 7565: unless ($charset) { 7566: $charset=&Apache::lonlocal::current_encoding; 7567: } 7568: if ($charset) { $type.='; charset='.$charset; } 7569: if ($r) { 7570: $r->content_type($type); 7571: } else { 7572: print("Content-type: $type\n\n"); 7573: } 7574: } 7575: 7576: =pod 7577: 7578: =item * &add_to_env($name,$value) 7579: 7580: adds $name to the %env hash with value 7581: $value, if $name already exists, the entry is converted to an array 7582: reference and $value is added to the array. 7583: 7584: =cut 7585: 7586: sub add_to_env { 7587: my ($name,$value)=@_; 7588: if (defined($env{$name})) { 7589: if (ref($env{$name})) { 7590: #already have multiple values 7591: push(@{ $env{$name} },$value); 7592: } else { 7593: #first time seeing multiple values, convert hash entry to an arrayref 7594: my $first=$env{$name}; 7595: undef($env{$name}); 7596: push(@{ $env{$name} },$first,$value); 7597: } 7598: } else { 7599: $env{$name}=$value; 7600: } 7601: } 7602: 7603: =pod 7604: 7605: =item * &get_env_multiple($name) 7606: 7607: gets $name from the %env hash, it seemlessly handles the cases where multiple 7608: values may be defined and end up as an array ref. 7609: 7610: returns an array of values 7611: 7612: =cut 7613: 7614: sub get_env_multiple { 7615: my ($name) = @_; 7616: my @values; 7617: if (defined($env{$name})) { 7618: # exists is it an array 7619: if (ref($env{$name})) { 7620: @values=@{ $env{$name} }; 7621: } else { 7622: $values[0]=$env{$name}; 7623: } 7624: } 7625: return(@values); 7626: } 7627: 7628: sub ask_for_embedded_content { 7629: my ($actionurl,$state,$allfiles,$codebase,$args)=@_; 7630: my $upload_output = ' 7631: <form name="upload_embedded" action="'.$actionurl.'" 7632: method="post" enctype="multipart/form-data">'; 7633: $upload_output .= $state; 7634: $upload_output .= '<b>Upload embedded files</b>:<br />'.&start_data_table(); 7635: 7636: my $num = 0; 7637: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%{$allfiles})) { 7638: $upload_output .= &start_data_table_row(). 7639: '<td>'.$embed_file.'</td><td>'; 7640: if ($args->{'ignore_remote_references'} 7641: && $embed_file =~ m{^\w+://}) { 7642: $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>'; 7643: } elsif ($args->{'error_on_invalid_names'} 7644: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) { 7645: 7646: $upload_output.='<span class="LC_warning">'.&mt("Invalid characters").'</span>'; 7647: 7648: } else { 7649: $upload_output .=' 7650: <input name="embedded_item_'.$num.'" type="file" value="" /> 7651: <input name="embedded_orig_'.$num.'" type="hidden" value="'.&escape($embed_file).'" />'; 7652: my $attrib = join(':',@{$$allfiles{$embed_file}}); 7653: $upload_output .= 7654: "\n\t\t". 7655: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'. 7656: $attrib.'" />'; 7657: if (exists($$codebase{$embed_file})) { 7658: $upload_output .= 7659: "\n\t\t". 7660: '<input name="codebase_'.$num.'" type="hidden" value="'. 7661: &escape($$codebase{$embed_file}).'" />'; 7662: } 7663: } 7664: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row(); 7665: $num++; 7666: } 7667: $upload_output .= &Apache::loncommon::end_data_table().'<br /> 7668: <input type ="hidden" name="number_embedded_items" value="'.$num.'" /> 7669: <input type ="submit" value="'.&mt('Upload Listed Files').'" /> 7670: '.&mt('(only files for which a location has been provided will be uploaded)').' 7671: </form>'; 7672: return $upload_output; 7673: } 7674: 7675: sub upload_embedded { 7676: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota, 7677: $current_disk_usage) = @_; 7678: my $output; 7679: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) { 7680: next if (!exists($env{'form.embedded_item_'.$i.'.filename'})); 7681: my $orig_uploaded_filename = 7682: $env{'form.embedded_item_'.$i.'.filename'}; 7683: 7684: $env{'form.embedded_orig_'.$i} = 7685: &unescape($env{'form.embedded_orig_'.$i}); 7686: my ($path,$fname) = 7687: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)}); 7688: # no path, whole string is fname 7689: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} }; 7690: 7691: $path = $env{'form.currentpath'}.$path; 7692: $fname = &Apache::lonnet::clean_filename($fname); 7693: # See if there is anything left 7694: next if ($fname eq ''); 7695: 7696: # Check if file already exists as a file or directory. 7697: my ($state,$msg); 7698: if ($context eq 'portfolio') { 7699: my $port_path = $dirpath; 7700: if ($group ne '') { 7701: $port_path = "groups/$group/$port_path"; 7702: } 7703: ($state,$msg) = &check_for_upload($path,$fname,$group,'embedded_item_'.$i, 7704: $dir_root,$port_path,$disk_quota, 7705: $current_disk_usage,$uname,$udom); 7706: if ($state eq 'will_exceed_quota' 7707: || $state eq 'file_locked' 7708: || $state eq 'file_exists' ) { 7709: $output .= $msg; 7710: next; 7711: } 7712: } elsif (($context eq 'author') || ($context eq 'testbank')) { 7713: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i); 7714: if ($state eq 'exists') { 7715: $output .= $msg; 7716: next; 7717: } 7718: } 7719: # Check if extension is valid 7720: if (($fname =~ /\.(\w+)$/) && 7721: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) { 7722: $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1); 7723: next; 7724: } elsif (($fname =~ /\.(\w+)$/) && 7725: (!defined(&Apache::loncommon::fileembstyle($1)))) { 7726: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1); 7727: next; 7728: } elsif ($fname=~/\.(\d+)\.(\w+)$/) { 7729: $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2); 7730: next; 7731: } 7732: 7733: $env{'form.embedded_item_'.$i.'.filename'}=$fname; 7734: if ($context eq 'portfolio') { 7735: my $result= 7736: &Apache::lonnet::userfileupload('embedded_item_'.$i,'', 7737: $dirpath.$path); 7738: if ($result !~ m|^/uploaded/|) { 7739: $output .= '<span class="LC_error">' 7740: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].' 7741: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}) 7742: .'</span><br />'; 7743: next; 7744: } else { 7745: $output .= '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'. 7746: $path.$fname.'</span>').'</p>'; 7747: } 7748: } else { 7749: # Save the file 7750: my $target = $env{'form.embedded_item_'.$i}; 7751: my $fullpath = $dir_root.$dirpath.'/'.$path; 7752: my $dest = $fullpath.$fname; 7753: my $url = $url_root.$dirpath.'/'.$path.$fname; 7754: my @parts=split(/\//,$fullpath); 7755: my $count; 7756: my $filepath = $dir_root; 7757: for ($count=4;$count<=$#parts;$count++) { 7758: $filepath .= "/$parts[$count]"; 7759: if ((-e $filepath)!=1) { 7760: mkdir($filepath,0770); 7761: } 7762: } 7763: my $fh; 7764: if (!open($fh,'>'.$dest)) { 7765: &Apache::lonnet::logthis('Failed to create '.$dest); 7766: $output .= '<span class="LC_error">'. 7767: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}). 7768: '</span><br />'; 7769: } else { 7770: if (!print $fh $env{'form.embedded_item_'.$i}) { 7771: &Apache::lonnet::logthis('Failed to write to '.$dest); 7772: $output .= '<span class="LC_error">'. 7773: &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}). 7774: '</span><br />'; 7775: } else { 7776: if ($context eq 'testbank') { 7777: $output .= &mt('Embedded file uploaded successfully:'). 7778: ' <a href="'.$url.'">'. 7779: $orig_uploaded_filename.'</a><br />'; 7780: } else { 7781: $output .= '<span class=\"LC_fontsize_large\">'. 7782: &mt('View embedded file: [_1]','<a href="'.$url.'">'. 7783: $orig_uploaded_filename.'</a>').'</span><br />'; 7784: } 7785: } 7786: close($fh); 7787: } 7788: } 7789: } 7790: return $output; 7791: } 7792: 7793: sub check_for_existing { 7794: my ($path,$fname,$element) = @_; 7795: my ($state,$msg); 7796: if (-d $path.'/'.$fname) { 7797: $state = 'exists'; 7798: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path); 7799: } elsif (-e $path.'/'.$fname) { 7800: $state = 'exists'; 7801: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path); 7802: } 7803: if ($state eq 'exists') { 7804: $msg = '<span class="LC_error">'.$msg.'</span><br />'; 7805: } 7806: return ($state,$msg); 7807: } 7808: 7809: sub check_for_upload { 7810: my ($path,$fname,$group,$element,$portfolio_root,$port_path, 7811: $disk_quota,$current_disk_usage,$uname,$udom) = @_; 7812: my $filesize = (length($env{'form.'.$element})) / 1000; #express in k (1024?) 7813: my $getpropath = 1; 7814: my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname, 7815: $getpropath); 7816: my $found_file = 0; 7817: my $locked_file = 0; 7818: foreach my $line (@dir_list) { 7819: my ($file_name)=split(/\&/,$line,2); 7820: if ($file_name eq $fname){ 7821: $file_name = $path.$file_name; 7822: if ($group ne '') { 7823: $file_name = $group.$file_name; 7824: } 7825: $found_file = 1; 7826: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') { 7827: $locked_file = 1; 7828: } 7829: } 7830: } 7831: if (($current_disk_usage + $filesize) > $disk_quota){ 7832: my $msg = '<span class="LC_error">'. 7833: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'. 7834: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage); 7835: return ('will_exceed_quota',$msg); 7836: } elsif ($found_file) { 7837: if ($locked_file) { 7838: my $msg = '<span class="LC_error">'; 7839: $msg .= &mt('Unable to upload [_1]. A locked file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>','<span class="LC_filename">'.$port_path.$env{'form.currentpath'}.'</span>'); 7840: $msg .= '</span><br />'; 7841: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>'); 7842: return ('file_locked',$msg); 7843: } else { 7844: my $msg = '<span class="LC_error">'; 7845: $msg .= &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$port_path.$env{'form.currentpath'}); 7846: $msg .= '</span>'; 7847: $msg .= '<br />'; 7848: $msg .= &mt('To upload, rename or delete existing [_1] in [_2].','<span class="LC_filename">'.$fname.'</span>', $port_path.$env{'form.currentpath'}); 7849: return ('file_exists',$msg); 7850: } 7851: } 7852: } 7853: 7854: 7855: =pod 7856: 7857: =back 7858: 7859: =head1 CSV Upload/Handling functions 7860: 7861: =over 4 7862: 7863: =item * &upfile_store($r) 7864: 7865: Store uploaded file, $r should be the HTTP Request object, 7866: needs $env{'form.upfile'} 7867: returns $datatoken to be put into hidden field 7868: 7869: =cut 7870: 7871: sub upfile_store { 7872: my $r=shift; 7873: $env{'form.upfile'}=~s/\r/\n/gs; 7874: $env{'form.upfile'}=~s/\f/\n/gs; 7875: $env{'form.upfile'}=~s/\n+/\n/gs; 7876: $env{'form.upfile'}=~s/\n+$//gs; 7877: 7878: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}. 7879: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$; 7880: { 7881: my $datafile = $r->dir_config('lonDaemons'). 7882: '/tmp/'.$datatoken.'.tmp'; 7883: if ( open(my $fh,">$datafile") ) { 7884: print $fh $env{'form.upfile'}; 7885: close($fh); 7886: } 7887: } 7888: return $datatoken; 7889: } 7890: 7891: =pod 7892: 7893: =item * &load_tmp_file($r) 7894: 7895: Load uploaded file from tmp, $r should be the HTTP Request object, 7896: needs $env{'form.datatoken'}, 7897: sets $env{'form.upfile'} to the contents of the file 7898: 7899: =cut 7900: 7901: sub load_tmp_file { 7902: my $r=shift; 7903: my @studentdata=(); 7904: { 7905: my $studentfile = $r->dir_config('lonDaemons'). 7906: '/tmp/'.$env{'form.datatoken'}.'.tmp'; 7907: if ( open(my $fh,"<$studentfile") ) { 7908: @studentdata=<$fh>; 7909: close($fh); 7910: } 7911: } 7912: $env{'form.upfile'}=join('',@studentdata); 7913: } 7914: 7915: =pod 7916: 7917: =item * &upfile_record_sep() 7918: 7919: Separate uploaded file into records 7920: returns array of records, 7921: needs $env{'form.upfile'} and $env{'form.upfiletype'} 7922: 7923: =cut 7924: 7925: sub upfile_record_sep { 7926: if ($env{'form.upfiletype'} eq 'xml') { 7927: } else { 7928: my @records; 7929: foreach my $line (split(/\n/,$env{'form.upfile'})) { 7930: if ($line=~/^\s*$/) { next; } 7931: push(@records,$line); 7932: } 7933: return @records; 7934: } 7935: } 7936: 7937: =pod 7938: 7939: =item * &record_sep($record) 7940: 7941: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'} 7942: 7943: =cut 7944: 7945: sub takeleft { 7946: my $index=shift; 7947: return substr('0000'.$index,-4,4); 7948: } 7949: 7950: sub record_sep { 7951: my $record=shift; 7952: my %components=(); 7953: if ($env{'form.upfiletype'} eq 'xml') { 7954: } elsif ($env{'form.upfiletype'} eq 'space') { 7955: my $i=0; 7956: foreach my $field (split(/\s+/,$record)) { 7957: $field=~s/^(\"|\')//; 7958: $field=~s/(\"|\')$//; 7959: $components{&takeleft($i)}=$field; 7960: $i++; 7961: } 7962: } elsif ($env{'form.upfiletype'} eq 'tab') { 7963: my $i=0; 7964: foreach my $field (split(/\t/,$record)) { 7965: $field=~s/^(\"|\')//; 7966: $field=~s/(\"|\')$//; 7967: $components{&takeleft($i)}=$field; 7968: $i++; 7969: } 7970: } else { 7971: my $separator=','; 7972: if ($env{'form.upfiletype'} eq 'semisv') { 7973: $separator=';'; 7974: } 7975: my $i=0; 7976: # the character we are looking for to indicate the end of a quote or a record 7977: my $looking_for=$separator; 7978: # do not add the characters to the fields 7979: my $ignore=0; 7980: # we just encountered a separator (or the beginning of the record) 7981: my $just_found_separator=1; 7982: # store the field we are working on here 7983: my $field=''; 7984: # work our way through all characters in record 7985: foreach my $character ($record=~/(.)/g) { 7986: if ($character eq $looking_for) { 7987: if ($character ne $separator) { 7988: # Found the end of a quote, again looking for separator 7989: $looking_for=$separator; 7990: $ignore=1; 7991: } else { 7992: # Found a separator, store away what we got 7993: $components{&takeleft($i)}=$field; 7994: $i++; 7995: $just_found_separator=1; 7996: $ignore=0; 7997: $field=''; 7998: } 7999: next; 8000: } 8001: # single or double quotation marks after a separator indicate beginning of a quote 8002: # we are now looking for the end of the quote and need to ignore separators 8003: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) { 8004: $looking_for=$character; 8005: next; 8006: } 8007: # ignore would be true after we reached the end of a quote 8008: if ($ignore) { next; } 8009: if (($just_found_separator) && ($character=~/\s/)) { next; } 8010: $field.=$character; 8011: $just_found_separator=0; 8012: } 8013: # catch the very last entry, since we never encountered the separator 8014: $components{&takeleft($i)}=$field; 8015: } 8016: return %components; 8017: } 8018: 8019: ###################################################### 8020: ###################################################### 8021: 8022: =pod 8023: 8024: =item * &upfile_select_html() 8025: 8026: Return HTML code to select a file from the users machine and specify 8027: the file type. 8028: 8029: =cut 8030: 8031: ###################################################### 8032: ###################################################### 8033: sub upfile_select_html { 8034: my %Types = ( 8035: csv => &mt('CSV (comma separated values, spreadsheet)'), 8036: semisv => &mt('Semicolon separated values'), 8037: space => &mt('Space separated'), 8038: tab => &mt('Tabulator separated'), 8039: # xml => &mt('HTML/XML'), 8040: ); 8041: my $Str = '<input type="file" name="upfile" size="50" />'. 8042: '<br />'.&mt('Type').': <select name="upfiletype">'; 8043: foreach my $type (sort(keys(%Types))) { 8044: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n"; 8045: } 8046: $Str .= "</select>\n"; 8047: return $Str; 8048: } 8049: 8050: sub get_samples { 8051: my ($records,$toget) = @_; 8052: my @samples=({}); 8053: my $got=0; 8054: foreach my $rec (@$records) { 8055: my %temp = &record_sep($rec); 8056: if (! grep(/\S/, values(%temp))) { next; } 8057: if (%temp) { 8058: $samples[$got]=\%temp; 8059: $got++; 8060: if ($got == $toget) { last; } 8061: } 8062: } 8063: return \@samples; 8064: } 8065: 8066: ###################################################### 8067: ###################################################### 8068: 8069: =pod 8070: 8071: =item * &csv_print_samples($r,$records) 8072: 8073: Prints a table of sample values from each column uploaded $r is an 8074: Apache Request ref, $records is an arrayref from 8075: &Apache::loncommon::upfile_record_sep 8076: 8077: =cut 8078: 8079: ###################################################### 8080: ###################################################### 8081: sub csv_print_samples { 8082: my ($r,$records) = @_; 8083: my $samples = &get_samples($records,5); 8084: 8085: $r->print(&mt('Samples').'<br />'.&start_data_table(). 8086: &start_data_table_header_row()); 8087: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) { 8088: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); } 8089: $r->print(&end_data_table_header_row()); 8090: foreach my $hash (@$samples) { 8091: $r->print(&start_data_table_row()); 8092: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) { 8093: $r->print('<td>'); 8094: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); } 8095: $r->print('</td>'); 8096: } 8097: $r->print(&end_data_table_row()); 8098: } 8099: $r->print(&end_data_table().'<br />'."\n"); 8100: } 8101: 8102: ###################################################### 8103: ###################################################### 8104: 8105: =pod 8106: 8107: =item * &csv_print_select_table($r,$records,$d) 8108: 8109: Prints a table to create associations between values and table columns. 8110: 8111: $r is an Apache Request ref, 8112: $records is an arrayref from &Apache::loncommon::upfile_record_sep, 8113: $d is an array of 2 element arrays (internal name, displayed name,defaultcol) 8114: 8115: =cut 8116: 8117: ###################################################### 8118: ###################################################### 8119: sub csv_print_select_table { 8120: my ($r,$records,$d) = @_; 8121: my $i=0; 8122: my $samples = &get_samples($records,1); 8123: $r->print(&mt('Associate columns with student attributes.')."\n". 8124: &start_data_table().&start_data_table_header_row(). 8125: '<th>'.&mt('Attribute').'</th>'. 8126: '<th>'.&mt('Column').'</th>'. 8127: &end_data_table_header_row()."\n"); 8128: foreach my $array_ref (@$d) { 8129: my ($value,$display,$defaultcol)=@{ $array_ref }; 8130: $r->print(&start_data_table_row().'<td>'.$display.'</td>'); 8131: 8132: $r->print('<td><select name=f'.$i. 8133: ' onchange="javascript:flip(this.form,'.$i.');">'); 8134: $r->print('<option value="none"></option>'); 8135: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) { 8136: $r->print('<option value="'.$sample.'"'. 8137: ($sample eq $defaultcol ? ' selected="selected" ' : ''). 8138: '>'.&mt('Column [_1]',($sample+1)).'</option>'); 8139: } 8140: $r->print('</select></td>'.&end_data_table_row()."\n"); 8141: $i++; 8142: } 8143: $r->print(&end_data_table()); 8144: $i--; 8145: return $i; 8146: } 8147: 8148: ###################################################### 8149: ###################################################### 8150: 8151: =pod 8152: 8153: =item * &csv_samples_select_table($r,$records,$d) 8154: 8155: Prints a table of sample values from the upload and can make associate samples to internal names. 8156: 8157: $r is an Apache Request ref, 8158: $records is an arrayref from &Apache::loncommon::upfile_record_sep, 8159: $d is an array of 2 element arrays (internal name, displayed name) 8160: 8161: =cut 8162: 8163: ###################################################### 8164: ###################################################### 8165: sub csv_samples_select_table { 8166: my ($r,$records,$d) = @_; 8167: my $i=0; 8168: # 8169: my $max_samples = 5; 8170: my $samples = &get_samples($records,$max_samples); 8171: $r->print(&start_data_table(). 8172: &start_data_table_header_row().'<th>'. 8173: &mt('Field').'</th><th>'.&mt('Samples').'</th>'. 8174: &end_data_table_header_row()); 8175: 8176: foreach my $key (sort(keys(%{ $samples->[0] }))) { 8177: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'. 8178: ' onchange="javascript:flip(this.form,'.$i.');">'); 8179: foreach my $option (@$d) { 8180: my ($value,$display,$defaultcol)=@{ $option }; 8181: $r->print('<option value="'.$value.'"'. 8182: ($i eq $defaultcol ? ' selected="selected" ':'').'>'. 8183: $display.'</option>'); 8184: } 8185: $r->print('</select></td><td>'); 8186: foreach my $line (0..($max_samples-1)) { 8187: if (defined($samples->[$line]{$key})) { 8188: $r->print($samples->[$line]{$key}."<br />\n"); 8189: } 8190: } 8191: $r->print('</td>'.&end_data_table_row()); 8192: $i++; 8193: } 8194: $r->print(&end_data_table()); 8195: $i--; 8196: return($i); 8197: } 8198: 8199: ###################################################### 8200: ###################################################### 8201: 8202: =pod 8203: 8204: =item * &clean_excel_name($name) 8205: 8206: Returns a replacement for $name which does not contain any illegal characters. 8207: 8208: =cut 8209: 8210: ###################################################### 8211: ###################################################### 8212: sub clean_excel_name { 8213: my ($name) = @_; 8214: $name =~ s/[:\*\?\/\\]//g; 8215: if (length($name) > 31) { 8216: $name = substr($name,0,31); 8217: } 8218: return $name; 8219: } 8220: 8221: =pod 8222: 8223: =item * &check_if_partid_hidden($id,$symb,$udom,$uname) 8224: 8225: Returns either 1 or undef 8226: 8227: 1 if the part is to be hidden, undef if it is to be shown 8228: 8229: Arguments are: 8230: 8231: $id the id of the part to be checked 8232: $symb, optional the symb of the resource to check 8233: $udom, optional the domain of the user to check for 8234: $uname, optional the username of the user to check for 8235: 8236: =cut 8237: 8238: sub check_if_partid_hidden { 8239: my ($id,$symb,$udom,$uname) = @_; 8240: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts', 8241: $symb,$udom,$uname); 8242: my $truth=1; 8243: #if the string starts with !, then the list is the list to show not hide 8244: if ($hiddenparts=~s/^\s*!//) { $truth=undef; } 8245: my @hiddenlist=split(/,/,$hiddenparts); 8246: foreach my $checkid (@hiddenlist) { 8247: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; } 8248: } 8249: return !$truth; 8250: } 8251: 8252: 8253: ############################################################ 8254: ############################################################ 8255: 8256: =pod 8257: 8258: =back 8259: 8260: =head1 cgi-bin script and graphing routines 8261: 8262: =over 4 8263: 8264: =item * &get_cgi_id() 8265: 8266: Inputs: none 8267: 8268: Returns an id which can be used to pass environment variables 8269: to various cgi-bin scripts. These environment variables will 8270: be removed from the users environment after a given time by 8271: the routine &Apache::lonnet::transfer_profile_to_env. 8272: 8273: =cut 8274: 8275: ############################################################ 8276: ############################################################ 8277: my $uniq=0; 8278: sub get_cgi_id { 8279: $uniq=($uniq+1)%100000; 8280: return (time.'_'.$$.'_'.$uniq); 8281: } 8282: 8283: ############################################################ 8284: ############################################################ 8285: 8286: =pod 8287: 8288: =item * &DrawBarGraph() 8289: 8290: Facilitates the plotting of data in a (stacked) bar graph. 8291: Puts plot definition data into the users environment in order for 8292: graph.png to plot it. Returns an <img> tag for the plot. 8293: The bars on the plot are labeled '1','2',...,'n'. 8294: 8295: Inputs: 8296: 8297: =over 4 8298: 8299: =item $Title: string, the title of the plot 8300: 8301: =item $xlabel: string, text describing the X-axis of the plot 8302: 8303: =item $ylabel: string, text describing the Y-axis of the plot 8304: 8305: =item $Max: scalar, the maximum Y value to use in the plot 8306: If $Max is < any data point, the graph will not be rendered. 8307: 8308: =item $colors: array ref holding the colors to be used for the data sets when 8309: they are plotted. If undefined, default values will be used. 8310: 8311: =item $labels: array ref holding the labels to use on the x-axis for the bars. 8312: 8313: =item @Values: An array of array references. Each array reference holds data 8314: to be plotted in a stacked bar chart. 8315: 8316: =item If the final element of @Values is a hash reference the key/value 8317: pairs will be added to the graph definition. 8318: 8319: =back 8320: 8321: Returns: 8322: 8323: An <img> tag which references graph.png and the appropriate identifying 8324: information for the plot. 8325: 8326: =cut 8327: 8328: ############################################################ 8329: ############################################################ 8330: sub DrawBarGraph { 8331: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_; 8332: # 8333: if (! defined($colors)) { 8334: $colors = ['#33ff00', 8335: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933', 8336: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66', 8337: ]; 8338: } 8339: my $extra_settings = {}; 8340: if (ref($Values[-1]) eq 'HASH') { 8341: $extra_settings = pop(@Values); 8342: } 8343: # 8344: my $identifier = &get_cgi_id(); 8345: my $id = 'cgi.'.$identifier; 8346: if (! @Values || ref($Values[0]) ne 'ARRAY') { 8347: return ''; 8348: } 8349: # 8350: my @Labels; 8351: if (defined($labels)) { 8352: @Labels = @$labels; 8353: } else { 8354: for (my $i=0;$i<@{$Values[0]};$i++) { 8355: push (@Labels,$i+1); 8356: } 8357: } 8358: # 8359: my $NumBars = scalar(@{$Values[0]}); 8360: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); } 8361: my %ValuesHash; 8362: my $NumSets=1; 8363: foreach my $array (@Values) { 8364: next if (! ref($array)); 8365: $ValuesHash{$id.'.data.'.$NumSets++} = 8366: join(',',@$array); 8367: } 8368: # 8369: my ($height,$width,$xskip,$bar_width) = (200,120,1,15); 8370: if ($NumBars < 3) { 8371: $width = 120+$NumBars*32; 8372: $xskip = 1; 8373: $bar_width = 30; 8374: } elsif ($NumBars < 5) { 8375: $width = 120+$NumBars*20; 8376: $xskip = 1; 8377: $bar_width = 20; 8378: } elsif ($NumBars < 10) { 8379: $width = 120+$NumBars*15; 8380: $xskip = 1; 8381: $bar_width = 15; 8382: } elsif ($NumBars <= 25) { 8383: $width = 120+$NumBars*11; 8384: $xskip = 5; 8385: $bar_width = 8; 8386: } elsif ($NumBars <= 50) { 8387: $width = 120+$NumBars*8; 8388: $xskip = 5; 8389: $bar_width = 4; 8390: } else { 8391: $width = 120+$NumBars*8; 8392: $xskip = 5; 8393: $bar_width = 4; 8394: } 8395: # 8396: $Max = 1 if ($Max < 1); 8397: if ( int($Max) < $Max ) { 8398: $Max++; 8399: $Max = int($Max); 8400: } 8401: $Title = '' if (! defined($Title)); 8402: $xlabel = '' if (! defined($xlabel)); 8403: $ylabel = '' if (! defined($ylabel)); 8404: $ValuesHash{$id.'.title'} = &escape($Title); 8405: $ValuesHash{$id.'.xlabel'} = &escape($xlabel); 8406: $ValuesHash{$id.'.ylabel'} = &escape($ylabel); 8407: $ValuesHash{$id.'.y_max_value'} = $Max; 8408: $ValuesHash{$id.'.NumBars'} = $NumBars; 8409: $ValuesHash{$id.'.NumSets'} = $NumSets; 8410: $ValuesHash{$id.'.PlotType'} = 'bar'; 8411: $ValuesHash{$id.'.Colors'} = join(',',@{$colors}); 8412: $ValuesHash{$id.'.height'} = $height; 8413: $ValuesHash{$id.'.width'} = $width; 8414: $ValuesHash{$id.'.xskip'} = $xskip; 8415: $ValuesHash{$id.'.bar_width'} = $bar_width; 8416: $ValuesHash{$id.'.labels'} = join(',',@Labels); 8417: # 8418: # Deal with other parameters 8419: while (my ($key,$value) = each(%$extra_settings)) { 8420: $ValuesHash{$id.'.'.$key} = $value; 8421: } 8422: # 8423: &Apache::lonnet::appenv(\%ValuesHash); 8424: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />'; 8425: } 8426: 8427: ############################################################ 8428: ############################################################ 8429: 8430: =pod 8431: 8432: =item * &DrawXYGraph() 8433: 8434: Facilitates the plotting of data in an XY graph. 8435: Puts plot definition data into the users environment in order for 8436: graph.png to plot it. Returns an <img> tag for the plot. 8437: 8438: Inputs: 8439: 8440: =over 4 8441: 8442: =item $Title: string, the title of the plot 8443: 8444: =item $xlabel: string, text describing the X-axis of the plot 8445: 8446: =item $ylabel: string, text describing the Y-axis of the plot 8447: 8448: =item $Max: scalar, the maximum Y value to use in the plot 8449: If $Max is < any data point, the graph will not be rendered. 8450: 8451: =item $colors: Array ref containing the hex color codes for the data to be 8452: plotted in. If undefined, default values will be used. 8453: 8454: =item $Xlabels: Array ref containing the labels to be used for the X-axis. 8455: 8456: =item $Ydata: Array ref containing Array refs. 8457: Each of the contained arrays will be plotted as a separate curve. 8458: 8459: =item %Values: hash indicating or overriding any default values which are 8460: passed to graph.png. 8461: Possible values are: width, xskip, x_ticks, x_tick_offset, among others. 8462: 8463: =back 8464: 8465: Returns: 8466: 8467: An <img> tag which references graph.png and the appropriate identifying 8468: information for the plot. 8469: 8470: =cut 8471: 8472: ############################################################ 8473: ############################################################ 8474: sub DrawXYGraph { 8475: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_; 8476: # 8477: # Create the identifier for the graph 8478: my $identifier = &get_cgi_id(); 8479: my $id = 'cgi.'.$identifier; 8480: # 8481: $Title = '' if (! defined($Title)); 8482: $xlabel = '' if (! defined($xlabel)); 8483: $ylabel = '' if (! defined($ylabel)); 8484: my %ValuesHash = 8485: ( 8486: $id.'.title' => &escape($Title), 8487: $id.'.xlabel' => &escape($xlabel), 8488: $id.'.ylabel' => &escape($ylabel), 8489: $id.'.y_max_value'=> $Max, 8490: $id.'.labels' => join(',',@$Xlabels), 8491: $id.'.PlotType' => 'XY', 8492: ); 8493: # 8494: if (defined($colors) && ref($colors) eq 'ARRAY') { 8495: $ValuesHash{$id.'.Colors'} = join(',',@{$colors}); 8496: } 8497: # 8498: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') { 8499: return ''; 8500: } 8501: my $NumSets=1; 8502: foreach my $array (@{$Ydata}){ 8503: next if (! ref($array)); 8504: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array); 8505: } 8506: $ValuesHash{$id.'.NumSets'} = $NumSets-1; 8507: # 8508: # Deal with other parameters 8509: while (my ($key,$value) = each(%Values)) { 8510: $ValuesHash{$id.'.'.$key} = $value; 8511: } 8512: # 8513: &Apache::lonnet::appenv(\%ValuesHash); 8514: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />'; 8515: } 8516: 8517: ############################################################ 8518: ############################################################ 8519: 8520: =pod 8521: 8522: =item * &DrawXYYGraph() 8523: 8524: Facilitates the plotting of data in an XY graph with two Y axes. 8525: Puts plot definition data into the users environment in order for 8526: graph.png to plot it. Returns an <img> tag for the plot. 8527: 8528: Inputs: 8529: 8530: =over 4 8531: 8532: =item $Title: string, the title of the plot 8533: 8534: =item $xlabel: string, text describing the X-axis of the plot 8535: 8536: =item $ylabel: string, text describing the Y-axis of the plot 8537: 8538: =item $colors: Array ref containing the hex color codes for the data to be 8539: plotted in. If undefined, default values will be used. 8540: 8541: =item $Xlabels: Array ref containing the labels to be used for the X-axis. 8542: 8543: =item $Ydata1: The first data set 8544: 8545: =item $Min1: The minimum value of the left Y-axis 8546: 8547: =item $Max1: The maximum value of the left Y-axis 8548: 8549: =item $Ydata2: The second data set 8550: 8551: =item $Min2: The minimum value of the right Y-axis 8552: 8553: =item $Max2: The maximum value of the left Y-axis 8554: 8555: =item %Values: hash indicating or overriding any default values which are 8556: passed to graph.png. 8557: Possible values are: width, xskip, x_ticks, x_tick_offset, among others. 8558: 8559: =back 8560: 8561: Returns: 8562: 8563: An <img> tag which references graph.png and the appropriate identifying 8564: information for the plot. 8565: 8566: =cut 8567: 8568: ############################################################ 8569: ############################################################ 8570: sub DrawXYYGraph { 8571: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1, 8572: $Ydata2,$Min2,$Max2,%Values)=@_; 8573: # 8574: # Create the identifier for the graph 8575: my $identifier = &get_cgi_id(); 8576: my $id = 'cgi.'.$identifier; 8577: # 8578: $Title = '' if (! defined($Title)); 8579: $xlabel = '' if (! defined($xlabel)); 8580: $ylabel = '' if (! defined($ylabel)); 8581: my %ValuesHash = 8582: ( 8583: $id.'.title' => &escape($Title), 8584: $id.'.xlabel' => &escape($xlabel), 8585: $id.'.ylabel' => &escape($ylabel), 8586: $id.'.labels' => join(',',@$Xlabels), 8587: $id.'.PlotType' => 'XY', 8588: $id.'.NumSets' => 2, 8589: $id.'.two_axes' => 1, 8590: $id.'.y1_max_value' => $Max1, 8591: $id.'.y1_min_value' => $Min1, 8592: $id.'.y2_max_value' => $Max2, 8593: $id.'.y2_min_value' => $Min2, 8594: ); 8595: # 8596: if (defined($colors) && ref($colors) eq 'ARRAY') { 8597: $ValuesHash{$id.'.Colors'} = join(',',@{$colors}); 8598: } 8599: # 8600: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' || 8601: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){ 8602: return ''; 8603: } 8604: my $NumSets=1; 8605: foreach my $array ($Ydata1,$Ydata2){ 8606: next if (! ref($array)); 8607: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array); 8608: } 8609: # 8610: # Deal with other parameters 8611: while (my ($key,$value) = each(%Values)) { 8612: $ValuesHash{$id.'.'.$key} = $value; 8613: } 8614: # 8615: &Apache::lonnet::appenv(\%ValuesHash); 8616: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />'; 8617: } 8618: 8619: ############################################################ 8620: ############################################################ 8621: 8622: =pod 8623: 8624: =back 8625: 8626: =head1 Statistics helper routines? 8627: 8628: Bad place for them but what the hell. 8629: 8630: =over 4 8631: 8632: =item * &chartlink() 8633: 8634: Returns a link to the chart for a specific student. 8635: 8636: Inputs: 8637: 8638: =over 4 8639: 8640: =item $linktext: The text of the link 8641: 8642: =item $sname: The students username 8643: 8644: =item $sdomain: The students domain 8645: 8646: =back 8647: 8648: =back 8649: 8650: =cut 8651: 8652: ############################################################ 8653: ############################################################ 8654: sub chartlink { 8655: my ($linktext, $sname, $sdomain) = @_; 8656: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'. 8657: '&SelectedStudent='.&escape($sname.':'.$sdomain). 8658: '&chartoutputmode='.HTML::Entities::encode('html, with all links'). 8659: '">'.$linktext.'</a>'; 8660: } 8661: 8662: ####################################################### 8663: ####################################################### 8664: 8665: =pod 8666: 8667: =head1 Course Environment Routines 8668: 8669: =over 4 8670: 8671: =item * &restore_course_settings() 8672: 8673: =item * &store_course_settings() 8674: 8675: Restores/Store indicated form parameters from the course environment. 8676: Will not overwrite existing values of the form parameters. 8677: 8678: Inputs: 8679: a scalar describing the data (e.g. 'chart', 'problem_analysis') 8680: 8681: a hash ref describing the data to be stored. For example: 8682: 8683: %Save_Parameters = ('Status' => 'scalar', 8684: 'chartoutputmode' => 'scalar', 8685: 'chartoutputdata' => 'scalar', 8686: 'Section' => 'array', 8687: 'Group' => 'array', 8688: 'StudentData' => 'array', 8689: 'Maps' => 'array'); 8690: 8691: Returns: both routines return nothing 8692: 8693: =back 8694: 8695: =cut 8696: 8697: ####################################################### 8698: ####################################################### 8699: sub store_course_settings { 8700: return &store_settings($env{'request.course.id'},@_); 8701: } 8702: 8703: sub store_settings { 8704: # save to the environment 8705: # appenv the same items, just to be safe 8706: my $udom = $env{'user.domain'}; 8707: my $uname = $env{'user.name'}; 8708: my ($context,$prefix,$Settings) = @_; 8709: my %SaveHash; 8710: my %AppHash; 8711: while (my ($setting,$type) = each(%$Settings)) { 8712: my $basename = join('.','internal',$context,$prefix,$setting); 8713: my $envname = 'environment.'.$basename; 8714: if (exists($env{'form.'.$setting})) { 8715: # Save this value away 8716: if ($type eq 'scalar' && 8717: (! exists($env{$envname}) || 8718: $env{$envname} ne $env{'form.'.$setting})) { 8719: $SaveHash{$basename} = $env{'form.'.$setting}; 8720: $AppHash{$envname} = $env{'form.'.$setting}; 8721: } elsif ($type eq 'array') { 8722: my $stored_form; 8723: if (ref($env{'form.'.$setting})) { 8724: $stored_form = join(',', 8725: map { 8726: &escape($_); 8727: } sort(@{$env{'form.'.$setting}})); 8728: } else { 8729: $stored_form = 8730: &escape($env{'form.'.$setting}); 8731: } 8732: # Determine if the array contents are the same. 8733: if ($stored_form ne $env{$envname}) { 8734: $SaveHash{$basename} = $stored_form; 8735: $AppHash{$envname} = $stored_form; 8736: } 8737: } 8738: } 8739: } 8740: my $put_result = &Apache::lonnet::put('environment',\%SaveHash, 8741: $udom,$uname); 8742: if ($put_result !~ /^(ok|delayed)/) { 8743: &Apache::lonnet::logthis('unable to save form parameters, '. 8744: 'got error:'.$put_result); 8745: } 8746: # Make sure these settings stick around in this session, too 8747: &Apache::lonnet::appenv(\%AppHash); 8748: return; 8749: } 8750: 8751: sub restore_course_settings { 8752: return &restore_settings($env{'request.course.id'},@_); 8753: } 8754: 8755: sub restore_settings { 8756: my ($context,$prefix,$Settings) = @_; 8757: while (my ($setting,$type) = each(%$Settings)) { 8758: next if (exists($env{'form.'.$setting})); 8759: my $envname = 'environment.internal.'.$context.'.'.$prefix. 8760: '.'.$setting; 8761: if (exists($env{$envname})) { 8762: if ($type eq 'scalar') { 8763: $env{'form.'.$setting} = $env{$envname}; 8764: } elsif ($type eq 'array') { 8765: $env{'form.'.$setting} = [ 8766: map { 8767: &unescape($_); 8768: } split(',',$env{$envname}) 8769: ]; 8770: } 8771: } 8772: } 8773: } 8774: 8775: ####################################################### 8776: ####################################################### 8777: 8778: =pod 8779: 8780: =head1 Domain E-mail Routines 8781: 8782: =over 4 8783: 8784: =item * &build_recipient_list() 8785: 8786: Build recipient lists for three types of e-mail: 8787: (a) Error Reports, (b) Package Updates, (c) Help requests, generated by 8788: lonerrorhandler.pm, CHECKRPMS and lonsupportreq.pm respectively. 8789: 8790: Inputs: 8791: defmail (scalar - email address of default recipient), 8792: mailing type (scalar - errormail, packagesmail, or helpdeskmail), 8793: defdom (domain for which to retrieve configuration settings), 8794: origmail (scalar - email address of recipient from loncapa.conf, 8795: i.e., predates configuration by DC via domainprefs.pm 8796: 8797: Returns: comma separated list of addresses to which to send e-mail. 8798: 8799: =back 8800: 8801: =cut 8802: 8803: ############################################################ 8804: ############################################################ 8805: sub build_recipient_list { 8806: my ($defmail,$mailing,$defdom,$origmail) = @_; 8807: my @recipients; 8808: my $otheremails; 8809: my %domconfig = 8810: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom); 8811: if (ref($domconfig{'contacts'}) eq 'HASH') { 8812: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') { 8813: my @contacts = ('adminemail','supportemail'); 8814: foreach my $item (@contacts) { 8815: if ($domconfig{'contacts'}{$mailing}{$item}) { 8816: my $addr = $domconfig{'contacts'}{$item}; 8817: if (!grep(/^\Q$addr\E$/,@recipients)) { 8818: push(@recipients,$addr); 8819: } 8820: } 8821: $otheremails = $domconfig{'contacts'}{$mailing}{'others'}; 8822: } 8823: } 8824: } elsif ($origmail ne '') { 8825: push(@recipients,$origmail); 8826: } 8827: if (defined($defmail)) { 8828: if ($defmail ne '') { 8829: push(@recipients,$defmail); 8830: } 8831: } 8832: if ($otheremails) { 8833: my @others; 8834: if ($otheremails =~ /,/) { 8835: @others = split(/,/,$otheremails); 8836: } else { 8837: push(@others,$otheremails); 8838: } 8839: foreach my $addr (@others) { 8840: if (!grep(/^\Q$addr\E$/,@recipients)) { 8841: push(@recipients,$addr); 8842: } 8843: } 8844: } 8845: my $recipientlist = join(',',@recipients); 8846: return $recipientlist; 8847: } 8848: 8849: ############################################################ 8850: ############################################################ 8851: 8852: =pod 8853: 8854: =head1 Course Catalog Routines 8855: 8856: =over 4 8857: 8858: =item * &gather_categories() 8859: 8860: Converts category definitions - keys of categories hash stored in 8861: coursecategories in configuration.db on the primary library server in a 8862: domain - to an array. Also generates javascript and idx hash used to 8863: generate Domain Coordinator interface for editing Course Categories. 8864: 8865: Inputs: 8866: 8867: categories (reference to hash of category definitions). 8868: 8869: cats (reference to array of arrays/hashes which encapsulates hierarchy of 8870: categories and subcategories). 8871: 8872: idx (reference to hash of counters used in Domain Coordinator interface for 8873: editing Course Categories). 8874: 8875: jsarray (reference to array of categories used to create Javascript arrays for 8876: Domain Coordinator interface for editing Course Categories). 8877: 8878: Returns: nothing 8879: 8880: Side effects: populates cats, idx and jsarray. 8881: 8882: =cut 8883: 8884: sub gather_categories { 8885: my ($categories,$cats,$idx,$jsarray) = @_; 8886: my %counters; 8887: my $num = 0; 8888: foreach my $item (keys(%{$categories})) { 8889: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item); 8890: if ($container eq '' && $depth == 0) { 8891: $cats->[$depth][$categories->{$item}] = $cat; 8892: } else { 8893: $cats->[$depth]{$container}[$categories->{$item}] = $cat; 8894: } 8895: my ($escitem,$tail) = split(/:/,$item,2); 8896: if ($counters{$tail} eq '') { 8897: $counters{$tail} = $num; 8898: $num ++; 8899: } 8900: if (ref($idx) eq 'HASH') { 8901: $idx->{$item} = $counters{$tail}; 8902: } 8903: if (ref($jsarray) eq 'ARRAY') { 8904: push(@{$jsarray->[$counters{$tail}]},$item); 8905: } 8906: } 8907: return; 8908: } 8909: 8910: =pod 8911: 8912: =item * &extract_categories() 8913: 8914: Used to generate breadcrumb trails for course categories. 8915: 8916: Inputs: 8917: 8918: categories (reference to hash of category definitions). 8919: 8920: cats (reference to array of arrays/hashes which encapsulates hierarchy of 8921: categories and subcategories). 8922: 8923: trails (reference to array of breacrumb trails for each category). 8924: 8925: allitems (reference to hash - key is category key 8926: (format: escaped(name):escaped(parent category):depth in hierarchy). 8927: 8928: idx (reference to hash of counters used in Domain Coordinator interface for 8929: editing Course Categories). 8930: 8931: jsarray (reference to array of categories used to create Javascript arrays for 8932: Domain Coordinator interface for editing Course Categories). 8933: 8934: subcats (reference to hash of arrays containing all subcategories within each 8935: category, -recursive) 8936: 8937: Returns: nothing 8938: 8939: Side effects: populates trails and allitems hash references. 8940: 8941: =cut 8942: 8943: sub extract_categories { 8944: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_; 8945: if (ref($categories) eq 'HASH') { 8946: &gather_categories($categories,$cats,$idx,$jsarray); 8947: if (ref($cats->[0]) eq 'ARRAY') { 8948: for (my $i=0; $i<@{$cats->[0]}; $i++) { 8949: my $name = $cats->[0][$i]; 8950: my $item = &escape($name).'::0'; 8951: my $trailstr; 8952: if ($name eq 'instcode') { 8953: $trailstr = &mt('Official courses (with institutional codes)'); 8954: } else { 8955: $trailstr = $name; 8956: } 8957: if ($allitems->{$item} eq '') { 8958: push(@{$trails},$trailstr); 8959: $allitems->{$item} = scalar(@{$trails})-1; 8960: } 8961: my @parents = ($name); 8962: if (ref($cats->[1]{$name}) eq 'ARRAY') { 8963: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) { 8964: my $category = $cats->[1]{$name}[$j]; 8965: if (ref($subcats) eq 'HASH') { 8966: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1'); 8967: } 8968: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats); 8969: } 8970: } else { 8971: if (ref($subcats) eq 'HASH') { 8972: $subcats->{$item} = []; 8973: } 8974: } 8975: } 8976: } 8977: } 8978: return; 8979: } 8980: 8981: =pod 8982: 8983: =item *&recurse_categories() 8984: 8985: Recursively used to generate breadcrumb trails for course categories. 8986: 8987: Inputs: 8988: 8989: cats (reference to array of arrays/hashes which encapsulates hierarchy of 8990: categories and subcategories). 8991: 8992: depth (current depth in hierarchy of categories and sub-categories - 0 indexed). 8993: 8994: category (current course category, for which breadcrumb trail is being generated). 8995: 8996: trails (reference to array of breadcrumb trails for each category). 8997: 8998: allitems (reference to hash - key is category key 8999: (format: escaped(name):escaped(parent category):depth in hierarchy). 9000: 9001: parents (array containing containers directories for current category, 9002: back to top level). 9003: 9004: Returns: nothing 9005: 9006: Side effects: populates trails and allitems hash references 9007: 9008: =cut 9009: 9010: sub recurse_categories { 9011: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_; 9012: my $shallower = $depth - 1; 9013: if (ref($cats->[$depth]{$category}) eq 'ARRAY') { 9014: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) { 9015: my $name = $cats->[$depth]{$category}[$k]; 9016: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower; 9017: my $trailstr = join(' -> ',(@{$parents},$category)); 9018: if ($allitems->{$item} eq '') { 9019: push(@{$trails},$trailstr); 9020: $allitems->{$item} = scalar(@{$trails})-1; 9021: } 9022: my $deeper = $depth+1; 9023: push(@{$parents},$category); 9024: if (ref($subcats) eq 'HASH') { 9025: my $subcat = &escape($name).':'.$category.':'.$depth; 9026: for (my $j=@{$parents}; $j>=0; $j--) { 9027: my $higher; 9028: if ($j > 0) { 9029: $higher = &escape($parents->[$j]).':'. 9030: &escape($parents->[$j-1]).':'.$j; 9031: } else { 9032: $higher = &escape($parents->[$j]).'::'.$j; 9033: } 9034: push(@{$subcats->{$higher}},$subcat); 9035: } 9036: } 9037: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents, 9038: $subcats); 9039: pop(@{$parents}); 9040: } 9041: } else { 9042: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower; 9043: my $trailstr = join(' -> ',(@{$parents},$category)); 9044: if ($allitems->{$item} eq '') { 9045: push(@{$trails},$trailstr); 9046: $allitems->{$item} = scalar(@{$trails})-1; 9047: } 9048: } 9049: return; 9050: } 9051: 9052: =pod 9053: 9054: =item *&assign_categories_table() 9055: 9056: Create a datatable for display of hierarchical categories in a domain, 9057: with checkboxes to allow a course to be categorized. 9058: 9059: Inputs: 9060: 9061: cathash - reference to hash of categories defined for the domain (from 9062: configuration.db) 9063: 9064: currcat - scalar with an & separated list of categories assigned to a course. 9065: 9066: Returns: $output (markup to be displayed) 9067: 9068: =cut 9069: 9070: sub assign_categories_table { 9071: my ($cathash,$currcat) = @_; 9072: my $output; 9073: if (ref($cathash) eq 'HASH') { 9074: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth); 9075: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray); 9076: $maxdepth = scalar(@cats); 9077: if (@cats > 0) { 9078: my $itemcount = 0; 9079: if (ref($cats[0]) eq 'ARRAY') { 9080: $output = &Apache::loncommon::start_data_table(); 9081: my @currcategories; 9082: if ($currcat ne '') { 9083: @currcategories = split('&',$currcat); 9084: } 9085: for (my $i=0; $i<@{$cats[0]}; $i++) { 9086: my $parent = $cats[0][$i]; 9087: my $css_class = $itemcount%2?' class="LC_odd_row"':''; 9088: next if ($parent eq 'instcode'); 9089: my $item = &escape($parent).'::0'; 9090: my $checked = ''; 9091: if (@currcategories > 0) { 9092: if (grep(/^\Q$item\E$/,@currcategories)) { 9093: $checked = ' checked="checked" '; 9094: } 9095: } 9096: $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'. 9097: '<input type="checkbox" name="usecategory" value="'. 9098: $item.'"'.$checked.' />'.$parent.'</span>'. 9099: '<input type="hidden" name="catname" value="'.$parent.'" /></td>'; 9100: my $depth = 1; 9101: push(@path,$parent); 9102: $output .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories); 9103: pop(@path); 9104: $output .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>'; 9105: $itemcount ++; 9106: } 9107: $output .= &Apache::loncommon::end_data_table(); 9108: } 9109: } 9110: } 9111: return $output; 9112: } 9113: 9114: =pod 9115: 9116: =item *&assign_category_rows() 9117: 9118: Create a datatable row for display of nested categories in a domain, 9119: with checkboxes to allow a course to be categorized,called recursively. 9120: 9121: Inputs: 9122: 9123: itemcount - track row number for alternating colors 9124: 9125: cats - reference to array of arrays/hashes which encapsulates hierarchy of 9126: categories and subcategories. 9127: 9128: depth - current depth in hierarchy of categories and sub-categories - 0 indexed. 9129: 9130: parent - parent of current category item 9131: 9132: path - Array containing all categories back up through the hierarchy from the 9133: current category to the top level. 9134: 9135: currcategories - reference to array of current categories assigned to the course 9136: 9137: Returns: $output (markup to be displayed). 9138: 9139: =cut 9140: 9141: sub assign_category_rows { 9142: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_; 9143: my ($text,$name,$item,$chgstr); 9144: if (ref($cats) eq 'ARRAY') { 9145: my $maxdepth = scalar(@{$cats}); 9146: if (ref($cats->[$depth]) eq 'HASH') { 9147: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') { 9148: my $numchildren = @{$cats->[$depth]{$parent}}; 9149: my $css_class = $itemcount%2?' class="LC_odd_row"':''; 9150: $text .= '<td><table class="LC_datatable">'; 9151: for (my $j=0; $j<$numchildren; $j++) { 9152: $name = $cats->[$depth]{$parent}[$j]; 9153: $item = &escape($name).':'.&escape($parent).':'.$depth; 9154: my $deeper = $depth+1; 9155: my $checked = ''; 9156: if (ref($currcategories) eq 'ARRAY') { 9157: if (@{$currcategories} > 0) { 9158: if (grep(/^\Q$item\E$/,@{$currcategories})) { 9159: $checked = ' checked="checked" '; 9160: } 9161: } 9162: } 9163: $text .= '<tr><td><span class="LC_nobreak"><label>'. 9164: '<input type="checkbox" name="usecategory" value="'. 9165: $item.'"'.$checked.' />'.$name.'</label></span>'. 9166: '<input type="hidden" name="catname" value="'.$name.'" />'. 9167: '</td><td>'; 9168: if (ref($path) eq 'ARRAY') { 9169: push(@{$path},$name); 9170: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories); 9171: pop(@{$path}); 9172: } 9173: $text .= '</td></tr>'; 9174: } 9175: $text .= '</table></td>'; 9176: } 9177: } 9178: } 9179: return $text; 9180: } 9181: 9182: ############################################################ 9183: ############################################################ 9184: 9185: 9186: sub commit_customrole { 9187: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_; 9188: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url. 9189: ($start?', '.&mt('starting').' '.localtime($start):''). 9190: ($end?', ending '.localtime($end):'').': <b>'. 9191: &Apache::lonnet::assigncustomrole( 9192: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context). 9193: '</b><br />'; 9194: return $output; 9195: } 9196: 9197: sub commit_standardrole { 9198: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_; 9199: my ($output,$logmsg,$linefeed); 9200: if ($context eq 'auto') { 9201: $linefeed = "\n"; 9202: } else { 9203: $linefeed = "<br />\n"; 9204: } 9205: if ($three eq 'st') { 9206: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end, 9207: $one,$two,$sec,$context); 9208: if (($result =~ /^error/) || ($result eq 'not_in_class') || 9209: ($result eq 'unknown_course') || ($result eq 'refused')) { 9210: $output = $logmsg.' '.&mt('Error: ').$result."\n"; 9211: } else { 9212: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url. 9213: ($start?', '.&mt('starting').' '.localtime($start):''). 9214: ($end?', '.&mt('ending').' '.localtime($end):'').': '; 9215: if ($context eq 'auto') { 9216: $output .= $result.$linefeed.&mt('Add to classlist').': ok'; 9217: } else { 9218: $output .= '<b>'.$result.'</b>'.$linefeed. 9219: &mt('Add to classlist').': <b>ok</b>'; 9220: } 9221: $output .= $linefeed; 9222: } 9223: } else { 9224: $output = &mt('Assigning').' '.$three.' in '.$url. 9225: ($start?', '.&mt('starting').' '.localtime($start):''). 9226: ($end?', '.&mt('ending').' '.localtime($end):'').': '; 9227: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context); 9228: if ($context eq 'auto') { 9229: $output .= $result.$linefeed; 9230: } else { 9231: $output .= '<b>'.$result.'</b>'.$linefeed; 9232: } 9233: } 9234: return $output; 9235: } 9236: 9237: sub commit_studentrole { 9238: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_; 9239: my ($result,$linefeed,$oldsecurl,$newsecurl); 9240: if ($context eq 'auto') { 9241: $linefeed = "\n"; 9242: } else { 9243: $linefeed = '<br />'."\n"; 9244: } 9245: if (defined($one) && defined($two)) { 9246: my $cid=$one.'_'.$two; 9247: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid); 9248: my $secchange = 0; 9249: my $expire_role_result; 9250: my $modify_section_result; 9251: if ($oldsec ne '-1') { 9252: if ($oldsec ne $sec) { 9253: $secchange = 1; 9254: my $now = time; 9255: my $uurl='/'.$cid; 9256: $uurl=~s/\_/\//g; 9257: if ($oldsec) { 9258: $uurl.='/'.$oldsec; 9259: } 9260: $oldsecurl = $uurl; 9261: $expire_role_result = 9262: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context); 9263: if ($env{'request.course.sec'} ne '') { 9264: if ($expire_role_result eq 'refused') { 9265: my @roles = ('st'); 9266: my @statuses = ('previous'); 9267: my @roledoms = ($one); 9268: my $withsec = 1; 9269: my %roleshash = 9270: &Apache::lonnet::get_my_roles($uname,$udom,'userroles', 9271: \@statuses,\@roles,\@roledoms,$withsec); 9272: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) { 9273: my ($oldstart,$oldend) = 9274: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec}); 9275: if ($oldend > 0 && $oldend <= $now) { 9276: $expire_role_result = 'ok'; 9277: } 9278: } 9279: } 9280: } 9281: $result = $expire_role_result; 9282: } 9283: } 9284: if (($expire_role_result eq 'ok') || ($secchange == 0)) { 9285: $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context); 9286: if ($modify_section_result =~ /^ok/) { 9287: if ($secchange == 1) { 9288: if ($sec eq '') { 9289: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed; 9290: } else { 9291: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed; 9292: } 9293: } elsif ($oldsec eq '-1') { 9294: if ($sec eq '') { 9295: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed; 9296: } else { 9297: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed; 9298: } 9299: } else { 9300: if ($sec eq '') { 9301: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed; 9302: } else { 9303: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed; 9304: } 9305: } 9306: } else { 9307: if ($secchange) { 9308: $$logmsg .= &mt('Error when attempting section change for [_1] from old section "[_2]" to new section: "[_3]" in course [_4] -error:',$uname,$oldsec,$sec,$cid).' '.$modify_section_result.$linefeed; 9309: } else { 9310: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed; 9311: } 9312: } 9313: $result = $modify_section_result; 9314: } elsif ($secchange == 1) { 9315: if ($oldsec eq '') { 9316: $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed; 9317: } else { 9318: $$logmsg .= &mt('Error when attempting to expire existing role for [_1] in section [_2] in course [_3] -error: ',$uname,$oldsec,$cid).' '.$expire_role_result.$linefeed; 9319: } 9320: if ($expire_role_result eq 'refused') { 9321: my $newsecurl = '/'.$cid; 9322: $newsecurl =~ s/\_/\//g; 9323: if ($sec ne '') { 9324: $newsecurl.='/'.$sec; 9325: } 9326: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) { 9327: if ($sec eq '') { 9328: $$logmsg .= &mt('Although your current role has privileges to add students to section "[_1]", you do not have privileges to modify existing enrollments unaffiliated with any section.',$sec).$linefeed; 9329: } else { 9330: $$logmsg .= &mt('Although your current role has privileges to add students to section "[_1]", you do not have privileges to modify existing enrollments in other sections.',$sec).$linefeed; 9331: } 9332: } 9333: } 9334: } 9335: } else { 9336: $$logmsg .= &mt('Incomplete course id defined.').$linefeed.&mt('Addition of user [_1] from domain [_2] to course [_3], section [_4] not completed.',$uname,$udom,$one.'_'.$two,$sec).$linefeed; 9337: $result = "error: incomplete course id\n"; 9338: } 9339: return $result; 9340: } 9341: 9342: ############################################################ 9343: ############################################################ 9344: 9345: sub check_clone { 9346: my ($args,$linefeed) = @_; 9347: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'}; 9348: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid); 9349: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom); 9350: my $clonemsg; 9351: my $can_clone = 0; 9352: 9353: if ($clonehome eq 'no_host') { 9354: $clonemsg = &mt('No new course created.').$linefeed.&mt('A new course could not be cloned from the specified original - [_1] - because it is a non-existent course.',$args->{'clonecourse'}.':'.$args->{'clonedomain'}); 9355: } else { 9356: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1}); 9357: if ($env{'request.role.domain'} eq $args->{'clonedomain'}) { 9358: $can_clone = 1; 9359: } else { 9360: my %clonehash = &Apache::lonnet::get('environment',['cloners'], 9361: $args->{'clonedomain'},$args->{'clonecourse'}); 9362: my @cloners = split(/,/,$clonehash{'cloners'}); 9363: if (grep(/^\*$/,@cloners)) { 9364: $can_clone = 1; 9365: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) { 9366: $can_clone = 1; 9367: } else { 9368: my %roleshash = 9369: &Apache::lonnet::get_my_roles($args->{'ccuname'}, 9370: $args->{'ccdomain'}, 9371: 'userroles',['active'],['cc'], 9372: [$args->{'clonedomain'}]); 9373: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':cc'}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) { 9374: $can_clone = 1; 9375: } else { 9376: $clonemsg = &mt('No new course created.').$linefeed.&mt('The new course could not be cloned from the existing course because the new course owner ([_1]) does not have cloning rights in the existing course ([_2]).',$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'}); 9377: } 9378: } 9379: } 9380: } 9381: return ($can_clone, $clonemsg, $cloneid, $clonehome); 9382: } 9383: 9384: sub construct_course { 9385: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context) = @_; 9386: my $outcome; 9387: my $linefeed = '<br />'."\n"; 9388: if ($context eq 'auto') { 9389: $linefeed = "\n"; 9390: } 9391: 9392: # 9393: # Are we cloning? 9394: # 9395: my ($can_clone, $clonemsg, $cloneid, $clonehome); 9396: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) { 9397: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed); 9398: if ($context ne 'auto') { 9399: if ($clonemsg ne '') { 9400: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>'; 9401: } 9402: } 9403: $outcome .= $clonemsg.$linefeed; 9404: 9405: if (!$can_clone) { 9406: return (0,$outcome); 9407: } 9408: } 9409: 9410: # 9411: # Open course 9412: # 9413: my $crstype = lc($args->{'crstype'}); 9414: my %cenv=(); 9415: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'}, 9416: $args->{'cdescr'}, 9417: $args->{'curl'}, 9418: $args->{'course_home'}, 9419: $args->{'nonstandard'}, 9420: $args->{'crscode'}, 9421: $args->{'ccuname'}.':'. 9422: $args->{'ccdomain'}, 9423: $args->{'crstype'}); 9424: 9425: # Note: The testing routines depend on this being output; see 9426: # Utils::Course. This needs to at least be output as a comment 9427: # if anyone ever decides to not show this, and Utils::Course::new 9428: # will need to be suitably modified. 9429: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed; 9430: # 9431: # Check if created correctly 9432: # 9433: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid); 9434: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom); 9435: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed; 9436: 9437: # 9438: # Do the cloning 9439: # 9440: if ($can_clone && $cloneid) { 9441: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome); 9442: if ($context ne 'auto') { 9443: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>'; 9444: } 9445: $outcome .= $clonemsg.$linefeed; 9446: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum); 9447: # Copy all files 9448: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'}); 9449: # Restore URL 9450: $cenv{'url'}=$oldcenv{'url'}; 9451: # Restore title 9452: $cenv{'description'}=$oldcenv{'description'}; 9453: # Mark as cloned 9454: $cenv{'clonedfrom'}=$cloneid; 9455: # Need to clone grading mode 9456: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum); 9457: $cenv{'grading'}=$newenv{'grading'}; 9458: # Do not clone these environment entries 9459: &Apache::lonnet::del('environment', 9460: ['default_enrollment_start_date', 9461: 'default_enrollment_end_date', 9462: 'question.email', 9463: 'policy.email', 9464: 'comment.email', 9465: 'pch.users.denied', 9466: 'plc.users.denied', 9467: 'hidefromcat', 9468: 'categories'], 9469: $$crsudom,$$crsunum); 9470: } 9471: 9472: # 9473: # Set environment (will override cloned, if existing) 9474: # 9475: my @sections = (); 9476: my @xlists = (); 9477: if ($args->{'crstype'}) { 9478: $cenv{'type'}=$args->{'crstype'}; 9479: } 9480: if ($args->{'crsid'}) { 9481: $cenv{'courseid'}=$args->{'crsid'}; 9482: } 9483: if ($args->{'crscode'}) { 9484: $cenv{'internal.coursecode'}=$args->{'crscode'}; 9485: } 9486: if ($args->{'crsquota'} ne '') { 9487: $cenv{'internal.coursequota'}=$args->{'crsquota'}; 9488: } else { 9489: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20; 9490: } 9491: if ($args->{'ccuname'}) { 9492: $cenv{'internal.courseowner'} = $args->{'ccuname'}. 9493: ':'.$args->{'ccdomain'}; 9494: } else { 9495: $cenv{'internal.courseowner'} = $args->{'curruser'}; 9496: } 9497: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner. 9498: if ($args->{'crssections'}) { 9499: $cenv{'internal.sectionnums'} = ''; 9500: if ($args->{'crssections'} =~ m/,/) { 9501: @sections = split/,/,$args->{'crssections'}; 9502: } else { 9503: $sections[0] = $args->{'crssections'}; 9504: } 9505: if (@sections > 0) { 9506: foreach my $item (@sections) { 9507: my ($sec,$gp) = split/:/,$item; 9508: my $class = $args->{'crscode'}.$sec; 9509: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'}); 9510: $cenv{'internal.sectionnums'} .= $item.','; 9511: unless ($addcheck eq 'ok') { 9512: push @badclasses, $class; 9513: } 9514: } 9515: $cenv{'internal.sectionnums'} =~ s/,$//; 9516: } 9517: } 9518: # do not hide course coordinator from staff listing, 9519: # even if privileged 9520: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'}; 9521: # add crosslistings 9522: if ($args->{'crsxlist'}) { 9523: $cenv{'internal.crosslistings'}=''; 9524: if ($args->{'crsxlist'} =~ m/,/) { 9525: @xlists = split/,/,$args->{'crsxlist'}; 9526: } else { 9527: $xlists[0] = $args->{'crsxlist'}; 9528: } 9529: if (@xlists > 0) { 9530: foreach my $item (@xlists) { 9531: my ($xl,$gp) = split/:/,$item; 9532: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'}); 9533: $cenv{'internal.crosslistings'} .= $item.','; 9534: unless ($addcheck eq 'ok') { 9535: push @badclasses, $xl; 9536: } 9537: } 9538: $cenv{'internal.crosslistings'} =~ s/,$//; 9539: } 9540: } 9541: if ($args->{'autoadds'}) { 9542: $cenv{'internal.autoadds'}=$args->{'autoadds'}; 9543: } 9544: if ($args->{'autodrops'}) { 9545: $cenv{'internal.autodrops'}=$args->{'autodrops'}; 9546: } 9547: # check for notification of enrollment changes 9548: my @notified = (); 9549: if ($args->{'notify_owner'}) { 9550: if ($args->{'ccuname'} ne '') { 9551: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'}); 9552: } 9553: } 9554: if ($args->{'notify_dc'}) { 9555: if ($uname ne '') { 9556: push(@notified,$uname.':'.$udom); 9557: } 9558: } 9559: if (@notified > 0) { 9560: my $notifylist; 9561: if (@notified > 1) { 9562: $notifylist = join(',',@notified); 9563: } else { 9564: $notifylist = $notified[0]; 9565: } 9566: $cenv{'internal.notifylist'} = $notifylist; 9567: } 9568: if (@badclasses > 0) { 9569: my %lt=&Apache::lonlocal::texthash( 9570: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course. However, if automated course roster updates are enabled for this class, these particular sections/crosslistings will not contribute towards enrollment, because the user identified as the course owner for this LON-CAPA course', 9571: 'dnhr' => 'does not have rights to access enrollment in these classes', 9572: 'adby' => 'as determined by the policies of your institution on access to official classlists' 9573: ); 9574: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}. 9575: ' ('.$lt{'adby'}.')'; 9576: if ($context eq 'auto') { 9577: $outcome .= $badclass_msg.$linefeed; 9578: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n"; 9579: foreach my $item (@badclasses) { 9580: if ($context eq 'auto') { 9581: $outcome .= " - $item\n"; 9582: } else { 9583: $outcome .= "<li>$item</li>\n"; 9584: } 9585: } 9586: if ($context eq 'auto') { 9587: $outcome .= $linefeed; 9588: } else { 9589: $outcome .= "</ul><br /><br /></div>\n"; 9590: } 9591: } 9592: } 9593: if ($args->{'no_end_date'}) { 9594: $args->{'endaccess'} = 0; 9595: } 9596: $cenv{'internal.autostart'}=$args->{'enrollstart'}; 9597: $cenv{'internal.autoend'}=$args->{'enrollend'}; 9598: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'}; 9599: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'}; 9600: if ($args->{'showphotos'}) { 9601: $cenv{'internal.showphotos'}=$args->{'showphotos'}; 9602: } 9603: $cenv{'internal.authtype'} = $args->{'authtype'}; 9604: $cenv{'internal.autharg'} = $args->{'autharg'}; 9605: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) { 9606: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') { 9607: my $krb_msg = &mt('As you did not include the default Kerberos domain to be used for authentication in this class, the institutional data used by the automated enrollment process must include the Kerberos domain for each new student'); 9608: if ($context eq 'auto') { 9609: $outcome .= $krb_msg; 9610: } else { 9611: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>'; 9612: } 9613: $outcome .= $linefeed; 9614: } 9615: } 9616: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) { 9617: if ($args->{'setpolicy'}) { 9618: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'}; 9619: } 9620: if ($args->{'setcontent'}) { 9621: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'}; 9622: } 9623: } 9624: if ($args->{'reshome'}) { 9625: $cenv{'reshome'}=$args->{'reshome'}.'/'; 9626: $cenv{'reshome'}=~s/\/+$/\//; 9627: } 9628: # 9629: # course has keyed access 9630: # 9631: if ($args->{'setkeys'}) { 9632: $cenv{'keyaccess'}='yes'; 9633: } 9634: # if specified, key authority is not course, but user 9635: # only active if keyaccess is yes 9636: if ($args->{'keyauth'}) { 9637: my ($user,$domain) = split(':',$args->{'keyauth'}); 9638: $user = &LONCAPA::clean_username($user); 9639: $domain = &LONCAPA::clean_username($domain); 9640: if ($user ne '' && $domain ne '') { 9641: $cenv{'keyauth'}=$user.':'.$domain; 9642: } 9643: } 9644: 9645: if ($args->{'disresdis'}) { 9646: $cenv{'pch.roles.denied'}='st'; 9647: } 9648: if ($args->{'disablechat'}) { 9649: $cenv{'plc.roles.denied'}='st'; 9650: } 9651: 9652: # Record we've not yet viewed the Course Initialization Helper for this 9653: # course 9654: $cenv{'course.helper.not.run'} = 1; 9655: # 9656: # Use new Randomseed 9657: # 9658: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();; 9659: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();; 9660: # 9661: # The encryption code and receipt prefix for this course 9662: # 9663: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999)); 9664: $cenv{'internal.encpref'}=100+int(9*rand(99)); 9665: # 9666: # By default, use standard grading 9667: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; } 9668: 9669: $outcome .= $linefeed.&mt('Setting environment').': '. 9670: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed; 9671: # 9672: # Open all assignments 9673: # 9674: if ($args->{'openall'}) { 9675: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate'; 9676: my %storecontent = ($storeunder => time, 9677: $storeunder.'.type' => 'date_start'); 9678: 9679: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput 9680: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed; 9681: } 9682: # 9683: # Set first page 9684: # 9685: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank') 9686: || ($cloneid)) { 9687: use LONCAPA::map; 9688: $outcome .= &mt('Setting first resource').': '; 9689: 9690: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence'; 9691: my ($errtext,$fatal)=&LONCAPA::map::mapread($map); 9692: 9693: $outcome .= ($fatal?$errtext:'read ok').' - '; 9694: my $title; my $url; 9695: if ($args->{'firstres'} eq 'syl') { 9696: $title=&mt('Syllabus'); 9697: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus'; 9698: } else { 9699: $title=&mt('Navigate Contents'); 9700: $url='/adm/navmaps'; 9701: } 9702: 9703: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res'; 9704: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1); 9705: 9706: if ($errtext) { $fatal=2; } 9707: $outcome .= ($fatal?$errtext:'write ok').$linefeed; 9708: } 9709: 9710: return (1,$outcome); 9711: } 9712: 9713: ############################################################ 9714: ############################################################ 9715: 9716: sub course_type { 9717: my ($cid) = @_; 9718: if (!defined($cid)) { 9719: $cid = $env{'request.course.id'}; 9720: } 9721: if (defined($env{'course.'.$cid.'.type'})) { 9722: return $env{'course.'.$cid.'.type'}; 9723: } else { 9724: return 'Course'; 9725: } 9726: } 9727: 9728: sub group_term { 9729: my $crstype = &course_type(); 9730: my %names = ( 9731: 'Course' => 'group', 9732: 'Group' => 'team', 9733: ); 9734: return $names{$crstype}; 9735: } 9736: 9737: sub icon { 9738: my ($file)=@_; 9739: my $curfext = lc((split(/\./,$file))[-1]); 9740: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif'; 9741: my $embstyle = &Apache::loncommon::fileembstyle($curfext); 9742: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) { 9743: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'. 9744: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'. 9745: $curfext.".gif") { 9746: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'. 9747: $curfext.".gif"; 9748: } 9749: } 9750: return &lonhttpdurl($iconname); 9751: } 9752: 9753: sub lonhttpdurl { 9754: # 9755: # Had been used for "small fry" static images on separate port 8080. 9756: # Modify here if lightweight http functionality desired again. 9757: # Currently eliminated due to increasing firewall issues. 9758: # 9759: my ($url)=@_; 9760: return $url; 9761: } 9762: 9763: sub connection_aborted { 9764: my ($r)=@_; 9765: $r->print(" ");$r->rflush(); 9766: my $c = $r->connection; 9767: return $c->aborted(); 9768: } 9769: 9770: # Escapes strings that may have embedded 's that will be put into 9771: # strings as 'strings'. 9772: sub escape_single { 9773: my ($input) = @_; 9774: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)> 9775: $input =~ s/\'/\\\'/g; # Esacpe the 's.... 9776: return $input; 9777: } 9778: 9779: # Same as escape_single, but escape's "'s This 9780: # can be used for "strings" 9781: sub escape_double { 9782: my ($input) = @_; 9783: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)> 9784: $input =~ s/\"/\\\"/g; # Esacpe the "s.... 9785: return $input; 9786: } 9787: 9788: # Escapes the last element of a full URL. 9789: sub escape_url { 9790: my ($url) = @_; 9791: my @urlslices = split(/\//, $url,-1); 9792: my $lastitem = &escape(pop(@urlslices)); 9793: return join('/',@urlslices).'/'.$lastitem; 9794: } 9795: 9796: # -------------------------------------------------------- Initliaze user login 9797: sub init_user_environment { 9798: my ($r, $username, $domain, $authhost, $form, $args) = @_; 9799: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'}; 9800: 9801: my $public=($username eq 'public' && $domain eq 'public'); 9802: 9803: # See if old ID present, if so, remove 9804: 9805: my ($filename,$cookie,$userroles); 9806: my $now=time; 9807: 9808: if ($public) { 9809: my $max_public=100; 9810: my $oldest; 9811: my $oldest_time=0; 9812: for(my $next=1;$next<=$max_public;$next++) { 9813: if (-e $lonids."/publicuser_$next.id") { 9814: my $mtime=(stat($lonids."/publicuser_$next.id"))[9]; 9815: if ($mtime<$oldest_time || !$oldest_time) { 9816: $oldest_time=$mtime; 9817: $oldest=$next; 9818: } 9819: } else { 9820: $cookie="publicuser_$next"; 9821: last; 9822: } 9823: } 9824: if (!$cookie) { $cookie="publicuser_$oldest"; } 9825: } else { 9826: # if this isn't a robot, kill any existing non-robot sessions 9827: if (!$args->{'robot'}) { 9828: opendir(DIR,$lonids); 9829: while ($filename=readdir(DIR)) { 9830: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) { 9831: unlink($lonids.'/'.$filename); 9832: } 9833: } 9834: closedir(DIR); 9835: } 9836: # Give them a new cookie 9837: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'} 9838: : $now.$$.int(rand(10000))); 9839: $cookie="$username\_$id\_$domain\_$authhost"; 9840: 9841: # Initialize roles 9842: 9843: $userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost); 9844: } 9845: # ------------------------------------ Check browser type and MathML capability 9846: 9847: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml, 9848: $clientunicode,$clientos) = &decode_user_agent($r); 9849: 9850: # -------------------------------------- Any accessibility options to remember? 9851: if (($form->{'interface'}) && ($form->{'remember'} eq 'true')) { 9852: foreach my $option ('imagesuppress','appletsuppress', 9853: 'embedsuppress','fontenhance','blackwhite') { 9854: if ($form->{$option} eq 'true') { 9855: &Apache::lonnet::put('environment',{$option => 'on'}, 9856: $domain,$username); 9857: } else { 9858: &Apache::lonnet::del('environment',[$option], 9859: $domain,$username); 9860: } 9861: } 9862: } 9863: # ------------------------------------------------------------- Get environment 9864: 9865: my %userenv = &Apache::lonnet::dump('environment',$domain,$username); 9866: my ($tmp) = keys(%userenv); 9867: if ($tmp !~ /^(con_lost|error|no_such_host)/i) { 9868: # default remote control to off 9869: if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; } 9870: } else { 9871: undef(%userenv); 9872: } 9873: if (($userenv{'interface'}) && (!$form->{'interface'})) { 9874: $form->{'interface'}=$userenv{'interface'}; 9875: } 9876: $env{'environment.remote'}=$userenv{'remote'}; 9877: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; } 9878: 9879: # --------------- Do not trust query string to be put directly into environment 9880: foreach my $option ('imagesuppress','appletsuppress', 9881: 'embedsuppress','fontenhance','blackwhite', 9882: 'interface','localpath','localres') { 9883: $form->{$option}=~s/[\n\r\=]//gs; 9884: } 9885: # --------------------------------------------------------- Write first profile 9886: 9887: { 9888: my %initial_env = 9889: ("user.name" => $username, 9890: "user.domain" => $domain, 9891: "user.home" => $authhost, 9892: "browser.type" => $clientbrowser, 9893: "browser.version" => $clientversion, 9894: "browser.mathml" => $clientmathml, 9895: "browser.unicode" => $clientunicode, 9896: "browser.os" => $clientos, 9897: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'}, 9898: "request.course.fn" => '', 9899: "request.course.uri" => '', 9900: "request.course.sec" => '', 9901: "request.role" => 'cm', 9902: "request.role.adv" => $env{'user.adv'}, 9903: "request.host" => $ENV{'REMOTE_ADDR'},); 9904: 9905: if ($form->{'localpath'}) { 9906: $initial_env{"browser.localpath"} = $form->{'localpath'}; 9907: $initial_env{"browser.localres"} = $form->{'localres'}; 9908: } 9909: 9910: if ($public) { 9911: $initial_env{"environment.remote"} = "off"; 9912: } 9913: if ($form->{'interface'}) { 9914: $form->{'interface'}=~s/\W//gs; 9915: $initial_env{"browser.interface"} = $form->{'interface'}; 9916: $env{'browser.interface'}=$form->{'interface'}; 9917: foreach my $option ('imagesuppress','appletsuppress', 9918: 'embedsuppress','fontenhance','blackwhite') { 9919: if (($form->{$option} eq 'true') || 9920: ($userenv{$option} eq 'on')) { 9921: $initial_env{"browser.$option"} = "on"; 9922: } 9923: } 9924: } 9925: 9926: foreach my $tool ('aboutme','blog','portfolio') { 9927: $userenv{'availabletools.'.$tool} = 9928: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload'); 9929: } 9930: 9931: $env{'user.environment'} = "$lonids/$cookie.id"; 9932: 9933: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id", 9934: &GDBM_WRCREAT(),0640)) { 9935: &_add_to_env(\%disk_env,\%initial_env); 9936: &_add_to_env(\%disk_env,\%userenv,'environment.'); 9937: &_add_to_env(\%disk_env,$userroles); 9938: if (ref($args->{'extra_env'})) { 9939: &_add_to_env(\%disk_env,$args->{'extra_env'}); 9940: } 9941: untie(%disk_env); 9942: } else { 9943: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ". 9944: 'Could not create environment storage in lonauth: '.$!.'</span>'); 9945: return 'error: '.$!; 9946: } 9947: } 9948: $env{'request.role'}='cm'; 9949: $env{'request.role.adv'}=$env{'user.adv'}; 9950: $env{'browser.type'}=$clientbrowser; 9951: 9952: return $cookie; 9953: 9954: } 9955: 9956: sub _add_to_env { 9957: my ($idf,$env_data,$prefix) = @_; 9958: if (ref($env_data) eq 'HASH') { 9959: while (my ($key,$value) = each(%$env_data)) { 9960: $idf->{$prefix.$key} = $value; 9961: $env{$prefix.$key} = $value; 9962: } 9963: } 9964: } 9965: 9966: # --- Get the symbolic name of a problem and the url 9967: sub get_symb { 9968: my ($request,$silent) = @_; 9969: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--; 9970: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url))); 9971: if ($symb eq '') { 9972: if (!$silent) { 9973: $request->print("Unable to handle ambiguous references:$url:."); 9974: return (); 9975: } 9976: } 9977: &Apache::lonenc::check_decrypt(\$symb); 9978: return ($symb); 9979: } 9980: 9981: # --------------------------------------------------------------Get annotation 9982: 9983: sub get_annotation { 9984: my ($symb,$enc) = @_; 9985: 9986: my $key = $symb; 9987: if (!$enc) { 9988: $key = 9989: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]); 9990: } 9991: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]); 9992: return $annotation{$key}; 9993: } 9994: 9995: sub clean_symb { 9996: my ($symb,$delete_enc) = @_; 9997: 9998: &Apache::lonenc::check_decrypt(\$symb); 9999: my $enc = $env{'request.enc'}; 10000: if ($delete_enc) { 10001: delete($env{'request.enc'}); 10002: } 10003: 10004: return ($symb,$enc); 10005: } 10006: 10007: =pod 10008: 10009: =back 10010: 10011: =cut 10012: 10013: 1; 10014: __END__; 10015: