--- loncom/interface/loncommon.pm 2014/08/23 18:43:56 1.1075.2.82 +++ loncom/interface/loncommon.pm 2012/12/22 15:37:02 1.1106 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # a pile of common routines # -# $Id: loncommon.pm,v 1.1075.2.82 2014/08/23 18:43:56 raeburn Exp $ +# $Id: loncommon.pm,v 1.1106 2012/12/22 15:37:02 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -67,16 +67,12 @@ use Apache::lonhtmlcommon(); use Apache::loncoursedata(); use Apache::lontexconvert(); use Apache::lonclonecourse(); -use Apache::lonuserutils(); -use Apache::lonuserstate(); -use Apache::courseclassifier(); use LONCAPA qw(:DEFAULT :match); use DateTime::TimeZone; use DateTime::Locale::Catalog; +use Text::Aspell; use Authen::Captcha; use Captcha::reCAPTCHA; -use Crypt::DES; -use DynaLoader; # for Crypt::DES version # ---------------------------------------------- Designs use vars qw(%defaultdesign); @@ -161,6 +157,7 @@ sub ssi_with_retries { # ----------------------------------------------- Filetypes/Languages/Copyright my %language; my %supported_language; +my %supported_codes; my %latex_language; # For choosing hyphenation in my %latex_language_bykey; # for choosing hyphenation from metadata my %cprtag; @@ -195,14 +192,15 @@ BEGIN { while (my $line = <$fh>) { next if ($line=~/^\#/); chomp($line); - my ($key,$two,$country,$three,$enc,$val,$sup,$latex)=(split(/\t/,$line)); + my ($key,$code,$country,$three,$enc,$val,$sup,$latex)=(split(/\t/,$line)); $language{$key}=$val.' - '.$enc; if ($sup) { $supported_language{$key}=$sup; + $supported_codes{$key} = $code; } if ($latex) { $latex_language_bykey{$key} = $latex; - $latex_language{$two} = $latex; + $latex_language{$code} = $latex; } } close($fh); @@ -531,8 +529,7 @@ ENDAUTHORBRW } sub coursebrowser_javascript { - my ($domainfilter,$sec_element,$formname,$role_element,$crstype, - $credits_element) = @_; + my ($domainfilter,$sec_element,$formname,$role_element,$crstype) = @_; my $wintitle = 'Course_Browser'; if ($crstype eq 'Community') { $wintitle = 'Community_Browser'; @@ -595,9 +592,8 @@ sub coursebrowser_javascript { } $id_functions ENDSTDBRW - if (($sec_element ne '') || ($role_element ne '') || ($credits_element ne '')) { - $output .= &setsec_javascript($sec_element,$formname,$role_element, - $credits_element); + if (($sec_element ne '') || ($role_element ne '')) { + $output .= &setsec_javascript($sec_element,$formname,$role_element); } $output .= ' // ]]> @@ -666,7 +662,7 @@ if (!Array.prototype.indexOf) { var n = 0; if (arguments.length > 0) { n = Number(arguments[1]); - if (n !== n) { // shortcut for verifying if it's NaN + if (n !== n) { // shortcut for verifying if it is NaN n = 0; } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) { n = (n > 0 || -1) * Math.floor(Math.abs(n)); @@ -754,7 +750,7 @@ ENDUSERBRW } sub setsec_javascript { - my ($sec_element,$formname,$role_element,$credits_element) = @_; + my ($sec_element,$formname,$role_element) = @_; my (@courserolenames,@communityrolenames,$rolestr,$courserolestr, $communityrolestr); if ($role_element ne '') { @@ -849,14 +845,6 @@ function setRole(crstype) { } |; } - if ($credits_element) { - $setsections .= qq| -function setCredits(defaultcredits) { - document.$formname.$credits_element.value = defaultcredits; - return; -} -|; - } return $setsections; } @@ -902,12 +890,12 @@ sub check_uncheck_jscript { function checkAll(field) { if (field.length > 0) { for (i = 0; i < field.length; i++) { - if (!field[i].disabled) { + if (!field[i].disabled) { field[i].checked = true; } } } else { - if (!field.disabled) { + if (!field.disabled) { field.checked = true; } } @@ -1011,12 +999,38 @@ sub select_language { $langchoices{$code} = &plainlanguagedescription($id); } } - %langchoices = &Apache::lonlocal::texthash(%langchoices); return &select_form($selected,$name,\%langchoices); } =pod + +=item * &list_languages() + +Returns an array reference that is suitable for use in language prompters. +Each array element is itself a two element array. The first element +is the language code. The second element a descsriptiuon of the +language itself. This is suitable for use in e.g. +&Apache::edit::select_arg (once dereferenced that is). + +=cut + +sub list_languages { + my @lang_choices; + + foreach my $id (&languageids()) { + my $code = &supportedlanguagecode($id); + if ($code) { + my $selector = $supported_codes{$id}; + my $description = &plainlanguagedescription($id); + push (@lang_choices, [$selector, $description]); + } + } + return \@lang_choices; +} + +=pod + =item * &linked_select_forms(...) linked_select_forms returns a string containing a block @@ -1043,12 +1057,6 @@ linked_select_forms takes the following =item * $menuorder, the order of values in the first menu -=item * $onchangefirst, additional javascript call to execute for an onchange - event for the first tag - =back Below is an example of such a hash. Only the 'text', 'default', and @@ -1102,8 +1110,6 @@ sub linked_select_forms { $secondselectname, $hashref, $menuorder, - $onchangefirst, - $onchangesecond ) = @_; my $second = "document.$formname.$secondselectname"; my $first = "document.$formname.$firstselectname"; @@ -1160,7 +1166,7 @@ function select1_changed() { END # output the initial values for the selection lists - $result .= "\n"; my @order = sort(keys(%{$hashref})); if (ref($menuorder) eq 'ARRAY') { @order = @{$menuorder}; @@ -1173,11 +1179,7 @@ END $result .= "\n"; my %select2 = %{$hashref->{$firstdefault}->{'select2'}}; $result .= $middletext; - $result .= " form to allow a user to select the domain to preform an operation in. @@ -2192,31 +2179,25 @@ If the $showdomdesc flag is set, the dom The optional $onchange argument specifies what should occur if the domain selector is changed, e.g., 'this.form.submit()' if the form is to be automatically submitted. -The optional $incdoms is a reference to an array of domains which will be the only available options. - -The optional $excdoms is a reference to an array of domains which will be excluded from the available options. +The optional $incdoms is a reference to an array of domains which will be the only available options. =cut #------------------------------------------- sub select_dom_form { - my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms) = @_; + my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms) = @_; if ($onchange) { $onchange = ' onchange="'.$onchange.'"'; } - my (@domains,%exclude); + my @domains; if (ref($incdoms) eq 'ARRAY') { @domains = sort {lc($a) cmp lc($b)} (@{$incdoms}); } else { @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains()); } if ($includeempty) { @domains=('',@domains); } - if (ref($excdoms) eq 'ARRAY') { - map { $exclude{$_} = 1; } @{$excdoms}; - } my $selectdomain = "'."\n"; @@ -10329,57 +9903,17 @@ sub ask_for_embedded_content { } elsif ($actionurl eq '/adm/dependencies') { $output .= ''; } - $output .= ''."\n".''."\n"; + $output .= ''."\n".''."\n"; } elsif ($numpathchg) { my %pathchange = (); $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output); if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) { $output .= '

'.&mt('or').'

'; - } + } } return ($output,$counter,$numpathchg); } -=pod - -=item * clean_path($name) - -Performs clean-up of directories, subdirectories and filename in an -embedded object, referenced in an HTML file which is being uploaded -to a course or portfolio, where -"Upload embedded images/multimedia files if HTML file" checkbox was -checked. - -Clean-up is similar to replacements in lonnet::clean_filename() -except each / between sub-directory and next level is preserved. - -=cut - -sub clean_path { - my ($embed_file) = @_; - $embed_file =~s{^/+}{}; - my @contents; - if ($embed_file =~ m{/}) { - @contents = split(/\//,$embed_file); - } else { - @contents = ($embed_file); - } - my $lastidx = scalar(@contents)-1; - for (my $i=0; $i<=$lastidx; $i++) { - $contents[$i]=~s{\\}{/}g; - $contents[$i]=~s/\s+/\_/g; - $contents[$i]=~s{[^/\w\.\-]}{}g; - if ($i == $lastidx) { - $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g; - } - } - if ($lastidx > 0) { - return join('/',@contents); - } else { - return $contents[0]; - } -} - sub embedded_file_element { my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_; return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') && @@ -10504,31 +10038,28 @@ sub upload_embedded { # Check if extension is valid if (($fname =~ /\.(\w+)$/) && (&Apache::loncommon::fileembstyle($1) eq 'hdn')) { - $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1) - .' '.&mt('Rename the file with a different extension and re-upload.').'
'; + $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1).'
'; next; } elsif (($fname =~ /\.(\w+)$/) && (!defined(&Apache::loncommon::fileembstyle($1)))) { $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'
'; next; } elsif ($fname=~/\.(\d+)\.(\w+)$/) { - $output .= &mt('Filename not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2).'
'; + $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2).'
'; next; } $env{'form.embedded_item_'.$i.'.filename'}=$fname; - my $subdir = $path; - $subdir =~ s{/+$}{}; if ($context eq 'portfolio') { my $result; if ($state eq 'existingfile') { $result= &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile', - $dirpath.$env{'form.currentpath'}.$subdir); + $dirpath.$env{'form.currentpath'}.$path); } else { $result= &Apache::lonnet::userfileupload('embedded_item_'.$i,'', $dirpath. - $env{'form.currentpath'}.$subdir); + $env{'form.currentpath'}.$path); if ($result !~ m|^/uploaded/|) { $output .= '' .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].' @@ -10540,11 +10071,10 @@ sub upload_embedded { $path.$fname.'').'
'; } } - } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) { - my $extendedsubdir = $dirpath.'/'.$subdir; - $extendedsubdir =~ s{/+$}{}; + } elsif ($context eq 'coursedoc') { my $result = - &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir); + &Apache::lonnet::userfileupload('embedded_item_'.$i,'coursedoc', + $dirpath.'/'.$path); if ($result !~ m|^/uploaded/|) { $output .= '' .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].' @@ -10554,9 +10084,6 @@ sub upload_embedded { } else { $output .= &mt('Uploaded [_1]',''. $path.$fname.'').'
'; - if ($context eq 'syllabus') { - &Apache::lonnet::make_public_indefinitely($result); - } } } else { # Save the file @@ -10688,7 +10215,7 @@ sub modify_html_form { } sub modify_html_refs { - my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_; + my ($context,$dirpath,$uname,$udom,$dir_root) = @_; my $container; if ($context eq 'portfolio') { $container = $env{'form.container'}; @@ -10697,14 +10224,12 @@ sub modify_html_refs { } elsif ($context eq 'manage_dependencies') { (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'}); $container = "/$container"; - } elsif ($context eq 'syllabus') { - $container = $url; } else { $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'}; } my (%allfiles,%codebase,$output,$content); my @changes = &get_env_multiple('form.namechange'); - unless ((@changes > 0) || ($context eq 'syllabus')) { + unless (@changes > 0) { if (wantarray) { return ('',0,0); } else { @@ -10712,7 +10237,7 @@ sub modify_html_refs { } } if (($context eq 'portfolio') || ($context eq 'coursedoc') || - ($context eq 'manage_dependencies') || ($context eq 'syllabus')) { + ($context eq 'manage_dependencies')) { unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) { if (wantarray) { return ('',0,0); @@ -10768,8 +10293,6 @@ sub modify_html_refs { if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) { my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi); $count += $numchg; - $allfiles{$newname} = $allfiles{$ref}; - delete($allfiles{$ref}); } if ($env{'form.embedded_codebase_'.$i} ne '') { $codebase = &unescape($env{'form.embedded_codebase_'.$i}); @@ -10778,11 +10301,10 @@ sub modify_html_refs { } } } - my $skiprewrites; if ($count || $codebasecount) { my $saveresult; if (($context eq 'portfolio') || ($context eq 'coursedoc') || - ($context eq 'manage_dependencies') || ($context eq 'syllabus')) { + ($context eq 'manage_dependencies')) { my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult); if ($url eq $container) { my ($fname) = ($container =~ m{/([^/]+)$}); @@ -10795,11 +10317,6 @@ sub modify_html_refs { ''. $container.'').'

'; } - if ($context eq 'syllabus') { - unless ($saveresult eq 'ok') { - $skiprewrites = 1; - } - } } else { if (open(my $fh,">$container")) { print $fh $content; @@ -10815,47 +10332,6 @@ sub modify_html_refs { } } } - if (($context eq 'syllabus') && (!$skiprewrites)) { - my ($actionurl,$state); - $actionurl = "/public/$udom/$uname/syllabus"; - my ($ignore,$num,$numpathchanges,$existing,$mapping) = - &ask_for_embedded_content($actionurl,$state,\%allfiles, - \%codebase, - {'context' => 'rewrites', - 'ignore_remote_references' => 1,}); - if (ref($mapping) eq 'HASH') { - my $rewrites = 0; - foreach my $key (keys(%{$mapping})) { - next if ($key =~ m{^https?://}); - my $ref = $mapping->{$key}; - my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key"; - my $attrib; - if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') { - $attrib = join('|',@{$allfiles{$mapping->{$key}}}); - } - if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) { - my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi); - $rewrites += $numchg; - } - } - if ($rewrites) { - my $saveresult; - my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult); - if ($url eq $container) { - my ($fname) = ($container =~ m{/([^/]+)$}); - $output .= '

'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].', - $count,''. - $fname.'').'

'; - } else { - $output .= '

'. - &mt('Error: could not update links in [_1].', - ''. - $container.'').'

'; - - } - } - } - } } else { &logthis('Failed to parse '.$container. ' to modify references: '.$parse_result); @@ -10945,11 +10421,11 @@ sub check_for_upload { if ($currsize < $filesize) { my $extra = $filesize - $currsize; if (($current_disk_usage + $extra) > $disk_quota) { - my $msg = '

'. + my $msg = ''. &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded if existing (smaller) file with same name (size = [_3] kilobytes) is replaced.', - ''.$fname.'',$filesize,$currsize).'

'. - '

'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.', - $disk_quota,$current_disk_usage).'

'; + ''.$fname.'',$filesize,$currsize).'
'. + '
'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.', + $disk_quota,$current_disk_usage); return ('will_exceed_quota',$msg); } } @@ -10958,21 +10434,21 @@ sub check_for_upload { } } if (($current_disk_usage + $filesize) > $disk_quota){ - my $msg = '

'. - &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.',''.$fname.'',$filesize).'

'. - '

'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'

'; + my $msg = ''. + &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.',''.$fname.'',$filesize).''. + '
'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage); return ('will_exceed_quota',$msg); } elsif ($found_file) { if ($locked_file) { - my $msg = '

'; + my $msg = ''; $msg .= &mt('Unable to upload [_1]. A locked file by that name was found in [_2].',''.$fname.'',''.$port_path.$env{'form.currentpath'}.''); - $msg .= '

'; + $msg .= '
'; $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.',''.$fname.''); return ('file_locked',$msg); } else { - my $msg = '

'; + my $msg = ''; $msg .= &mt(' A file by that name: [_1] was found in [_2].',''.$fname.'',$port_path.$env{'form.currentpath'}); - $msg .= '

'; + $msg .= ''; return ('existingfile',$msg); } } @@ -11063,66 +10539,16 @@ sub decompress_form { } } if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) { - my @camtasia6 = ("$topdir/","$topdir/index.html", + my @camtasia = ("$topdir/","$topdir/index.html", "$topdir/media/", "$topdir/media/$topdir.mp4", "$topdir/media/FirstFrame.png", "$topdir/media/player.swf", "$topdir/media/swfobject.js", "$topdir/media/expressInstall.swf"); - my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html", - "$topdir/$topdir.mp4", - "$topdir/$topdir\_config.xml", - "$topdir/$topdir\_controller.swf", - "$topdir/$topdir\_embed.css", - "$topdir/$topdir\_First_Frame.png", - "$topdir/$topdir\_player.html", - "$topdir/$topdir\_Thumbnails.png", - "$topdir/playerProductInstall.swf", - "$topdir/scripts/", - "$topdir/scripts/config_xml.js", - "$topdir/scripts/handlebars.js", - "$topdir/scripts/jquery-1.7.1.min.js", - "$topdir/scripts/jquery-ui-1.8.15.custom.min.js", - "$topdir/scripts/modernizr.js", - "$topdir/scripts/player-min.js", - "$topdir/scripts/swfobject.js", - "$topdir/skins/", - "$topdir/skins/configuration_express.xml", - "$topdir/skins/express_show/", - "$topdir/skins/express_show/player-min.css", - "$topdir/skins/express_show/spritesheet.png"); - my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html", - "$topdir/$topdir.mp4", - "$topdir/$topdir\_config.xml", - "$topdir/$topdir\_controller.swf", - "$topdir/$topdir\_embed.css", - "$topdir/$topdir\_First_Frame.png", - "$topdir/$topdir\_player.html", - "$topdir/$topdir\_Thumbnails.png", - "$topdir/playerProductInstall.swf", - "$topdir/scripts/", - "$topdir/scripts/config_xml.js", - "$topdir/scripts/techsmith-smart-player.min.js", - "$topdir/skins/", - "$topdir/skins/configuration_express.xml", - "$topdir/skins/express_show/", - "$topdir/skins/express_show/spritesheet.min.css", - "$topdir/skins/express_show/spritesheet.png", - "$topdir/skins/express_show/techsmith-smart-player.min.css"); - my @diffs = &compare_arrays(\@paths,\@camtasia6); + my @diffs = &compare_arrays(\@paths,\@camtasia); if (@diffs == 0) { - $is_camtasia = 6; - } else { - @diffs = &compare_arrays(\@paths,\@camtasia8_1); - if (@diffs == 0) { - $is_camtasia = 8; - } else { - @diffs = &compare_arrays(\@paths,\@camtasia8_4); - if (@diffs == 0) { - $is_camtasia = 8; - } - } + $is_camtasia = 1; } } my $output; @@ -11134,7 +10560,8 @@ sub decompress_form { function camtasiaToggle() { for (var i=0; i'. ''.$lt{'proa'}.' 
'. @@ -11319,9 +10746,9 @@ sub decompress_uploaded_file { sub process_decompression { my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_; my ($dir,$error,$warning,$output); - if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) { - $error = &mt('Filename not a supported archive file type.'). - '
'.&mt('Filename should end with one of: [_1].', + if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/) { + $error = &mt('File name not a supported archive file type.'). + '
'.&mt('File name should end with one of: [_1].', '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz'); } else { my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom); @@ -11429,7 +10856,6 @@ sub process_decompression { \%titles,\%children); } if ($env{'form.autoextract_camtasia'}) { - my $version = $env{'form.autoextract_camtasia'}; my %displayed; my $total = 1; $env{'form.archive_directory'} = []; @@ -11448,15 +10874,12 @@ sub process_decompression { $env{'form.archive_'.$i} = 'display'; $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'}; $displayed{'folder'} = $i; - } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) || - (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) { + } elsif ($item eq "$contents[0]/index.html") { $env{'form.archive_'.$i} = 'display'; $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'}; $displayed{'web'} = $i; } else { - if ((($item eq "$contents[0]/media") && ($version == 6)) || - ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") || - ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) { + if ($item eq "$contents[0]/media") { push(@{$env{'form.archive_directory'}},$i); } $env{'form.archive_'.$i} = 'dependency'; @@ -11901,7 +11324,7 @@ sub process_extracted_files { $folders{'0'} = $items[-2]; if ($env{'form.folderpath'} =~ /\:1$/) { $containers{'0'}='page'; - } else { + } else { $containers{'0'}='sequence'; } } @@ -12021,7 +11444,7 @@ sub process_extracted_files { } } } else { - $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'
'; + $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'
'; } } for (my $i=1; $i<=$numitems; $i++) { @@ -12043,7 +11466,7 @@ sub process_extracted_files { } if ($itemidx eq '') { $itemidx = 0; - } + } if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) { if ($mapinner{$referrer{$i}}) { $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}"; @@ -12090,12 +11513,12 @@ sub process_extracted_files { $showpath = "$relpath/$title"; } else { $showpath = "/$title"; - } + } $result .= '
  • '.&mt('[_1] included as a dependency',$showpath).'
  • '."\n"; - } + } unless ($ishome) { my $fetch = "$fullpath/$title"; - $fetch =~ s/^\Q$prefix$dir\E//; + $fetch =~ s/^\Q$prefix$dir\E//; $prompttofetch{$fetch} = 1; } } @@ -12105,7 +11528,7 @@ sub process_extracted_files { $path,$env{'form.archive_content_'.$referrer{$i}}).'
    '; } } else { - $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'
    '; + $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'
    '; } } if (keys(%todelete)) { @@ -12164,7 +11587,7 @@ sub cleanup_empty_dirs { my $numitems = 0; foreach my $item (@dircontents) { if (-d "$path/$item") { - &cleanup_empty_dirs("$path/$item"); + &recurse_dirs("$path/$item"); if (-e "$path/$item") { $numitems ++; } @@ -12183,7 +11606,7 @@ sub cleanup_empty_dirs { =pod -=item * &get_folder_hierarchy() +=item &get_folder_hierarchy() Provides hierarchy of names of folders/sub-folders containing the current item, @@ -12211,7 +11634,7 @@ sub get_folder_hierarchy { my @pcs = split(/,/,$pcslist); foreach my $pc (@pcs) { if ($pc == 1) { - push(@pathitems,&mt('Main Content')); + push(@pathitems,&mt('Main Course Documents')); } else { my $res = $navmap->getByMapPc($pc); if (ref($res)) { @@ -12226,7 +11649,7 @@ sub get_folder_hierarchy { } if ($showitem) { if ($mapres->{ID} eq '0.0') { - push(@pathitems,&mt('Main Content')); + push(@pathitems,&mt('Main Course Documents')); } else { my $maptitle = $mapres->compTitle(); $maptitle =~ s/\W+/_/g; @@ -12293,9 +11716,6 @@ sub get_turnedin_filepath { my $title = $res->compTitle(); $title =~ s/\W+/_/g; if ($title ne '') { - if (($pc > 1) && (length($title) > 12)) { - $title = substr($title,0,12); - } push(@pathitems,$title); } } @@ -12304,9 +11724,6 @@ sub get_turnedin_filepath { my $maptitle = $mapres->compTitle(); $maptitle =~ s/\W+/_/g; if ($maptitle ne '') { - if (length($maptitle) > 12) { - $maptitle = substr($maptitle,0,12); - } push(@pathitems,$maptitle); } unless ($env{'request.state'} eq 'construct') { @@ -12347,9 +11764,6 @@ sub get_turnedin_filepath { $restitle = time; } } - if (length($restitle) > 12) { - $restitle = substr($restitle,0,12); - } push(@pathitems,$restitle); $path .= join('/',@pathitems); } @@ -13287,22 +12701,18 @@ sub restore_settings { =item * &build_recipient_list() -Build recipient lists for following types of e-mail: +Build recipient lists for five types of e-mail: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors -(d) Help requests, (e) Course requests needing approval, (f) loncapa -module change checking, student/employee ID conflict checks, as -generated by lonerrorhandler.pm, CHECKRPMS, loncron, -lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively. +(d) Help requests, (e) Course requests needing approval, generated by +lonerrorhandler.pm, CHECKRPMS, loncron, lonsupportreq.pm and +loncoursequeueadmin.pm respectively. Inputs: -defmail (scalar - email address of default recipient), -mailing type (scalar: errormail, packagesmail, helpdeskmail, -requestsmail, updatesmail, or idconflictsmail). - +defmail (scalar - email address of default recipient), +mailing type (scalar - errormail, packagesmail, or helpdeskmail), defdom (domain for which to retrieve configuration settings), - -origmail (scalar - email address of recipient from loncapa.conf, -i.e., predates configuration by DC via domainprefs.pm +origmail (scalar - email address of recipient from loncapa.conf, +i.e., predates configuration by DC via domainprefs.pm Returns: comma separated list of addresses to which to send e-mail. @@ -13496,7 +12906,7 @@ sub extract_categories { =pod -=item * &recurse_categories() +=item *&recurse_categories() Recursively used to generate breadcrumb trails for course categories. @@ -13567,7 +12977,7 @@ sub recurse_categories { =pod -=item * &assign_categories_table() +=item *&assign_categories_table() Create a datatable for display of hierarchical categories in a domain, with checkboxes to allow a course to be categorized. @@ -13644,7 +13054,7 @@ sub assign_categories_table { =pod -=item * &assign_category_rows() +=item *&assign_category_rows() Create a datatable row for display of nested categories in a domain, with checkboxes to allow a course to be categorized,called recursively. @@ -13678,7 +13088,7 @@ sub assign_category_rows { if (ref($cats->[$depth]{$parent}) eq 'ARRAY') { my $numchildren = @{$cats->[$depth]{$parent}}; my $css_class = $itemcount%2?' class="LC_odd_row"':''; - $text .= ''; + $text .= '
    '; for (my $j=0; $j<$numchildren; $j++) { $name = $cats->[$depth]{$parent}[$j]; $item = &escape($name).':'.&escape($parent).':'.$depth; @@ -13710,12 +13120,6 @@ sub assign_category_rows { return $text; } -=pod - -=back - -=cut - ############################################################ ############################################################ @@ -13732,7 +13136,7 @@ sub commit_customrole { } sub commit_standardrole { - my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_; + my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_; my ($output,$logmsg,$linefeed); if ($context eq 'auto') { $linefeed = "\n"; @@ -13741,7 +13145,7 @@ sub commit_standardrole { } if ($three eq 'st') { my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end, - $one,$two,$sec,$context,$credits); + $one,$two,$sec,$context); if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) { $output = $logmsg.' '.&mt('Error: ').$result."\n"; @@ -13772,8 +13176,7 @@ sub commit_standardrole { } sub commit_studentrole { - my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context, - $credits) = @_; + my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_; my ($result,$linefeed,$oldsecurl,$newsecurl); if ($context eq 'auto') { $linefeed = "\n"; @@ -13820,11 +13223,7 @@ sub commit_studentrole { } } if (($expire_role_result eq 'ok') || ($secchange == 0)) { - $modify_section_result = - &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef, - undef,undef,undef,$sec, - $end,$start,'','',$cid, - '',$context,$credits); + $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context); if ($modify_section_result =~ /^ok/) { if ($secchange == 1) { if ($sec eq '') { @@ -13881,26 +13280,6 @@ sub commit_studentrole { return $result; } -sub show_role_extent { - my ($scope,$context,$role) = @_; - $scope =~ s{^/}{}; - my @courseroles = &Apache::lonuserutils::roles_by_context('course',1); - push(@courseroles,'co'); - my @authorroles = &Apache::lonuserutils::roles_by_context('author'); - if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) { - $scope =~ s{/}{_}; - return ''.$env{'course.'.$scope.'.description'}.''; - } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) { - my ($audom,$auname) = split(/\//,$scope); - return &mt('[_1] Author Space',''. - &Apache::loncommon::plainname($auname,$audom).''); - } else { - $scope =~ s{/$}{}; - return &mt('Domain: [_1]',''. - &Apache::lonnet::domain($scope,'description').''); - } -} - ############################################################ ############################################################ @@ -13968,7 +13347,7 @@ sub check_clone { } sub construct_course { - my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category,$coderef) = @_; + my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category) = @_; my $outcome; my $linefeed = '
    '."\n"; if ($context eq 'auto') { @@ -14064,13 +13443,8 @@ sub construct_course { 'pch.users.denied', 'plc.users.denied', 'hidefromcat', - 'checkforpriv', - 'categories', - 'internal.uniquecode'], + 'categories'], $$crsudom,$$crsunum); - if ($args->{'textbook'}) { - $cenv{'internal.textbook'} = $args->{'textbook'}; - } } # @@ -14098,9 +13472,6 @@ sub construct_course { } else { $cenv{'internal.courseowner'} = $args->{'curruser'}; } - if ($args->{'defaultcredits'}) { - $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'}; - } my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner. if ($args->{'crssections'}) { $cenv{'internal.sectionnums'} = ''; @@ -14125,11 +13496,6 @@ sub construct_course { # do not hide course coordinator from staff listing, # even if privileged $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'}; -# add course coordinator's domain to domains to check for privileged users -# if different to course domain - if ($$crsudom ne $args->{'ccdomain'}) { - $cenv{'checkforpriv'} = $args->{'ccdomain'}; - } # add crosslistings if ($args->{'crsxlist'}) { $cenv{'internal.crosslistings'}=''; @@ -14254,25 +13620,6 @@ sub construct_course { } } -# -# generate and store uniquecode (available to course requester), if course should have one. -# - if ($args->{'uniquecode'}) { - my ($code,$error) = &make_unique_code($$crsudom,$$crsunum); - if ($code) { - $cenv{'internal.uniquecode'} = $code; - my %crsinfo = - &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.'); - if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') { - $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code; - my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime'); - } - if (ref($coderef)) { - $$coderef = $code; - } - } - } - if ($args->{'disresdis'}) { $cenv{'pch.roles.denied'}='st'; } @@ -14341,60 +13688,6 @@ sub construct_course { return (1,$outcome); } -sub make_unique_code { - my ($cdom,$cnum) = @_; - # get lock on uniquecodes db - my $lockhash = { - $cnum."\0".'uniquecodes' => $env{'user.name'}. - ':'.$env{'user.domain'}, - }; - my $tries = 0; - my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom); - my ($code,$error); - - while (($gotlock ne 'ok') && ($tries<3)) { - $tries ++; - sleep 1; - $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom); - } - if ($gotlock eq 'ok') { - my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom); - my $gotcode; - my $attempts = 0; - while ((!$gotcode) && ($attempts < 100)) { - $code = &generate_code(); - if (!exists($currcodes{$code})) { - $gotcode = 1; - unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') { - $error = 'nostore'; - } - } - $attempts ++; - } - my @del_lock = ($cnum."\0".'uniquecodes'); - my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom); - } else { - $error = 'nolock'; - } - return ($code,$error); -} - -sub generate_code { - my $code; - my @letts = qw(B C D G H J K M N P Q R S T V W X Z); - for (my $i=0; $i<6; $i++) { - my $lettnum = int (rand 2); - my $item = ''; - if ($lettnum) { - $item = $letts[int( rand(18) )]; - } else { - $item = 1+int( rand(8) ); - } - $code .= $item; - } - return $code; -} - ############################################################ ############################################################ @@ -14422,12 +13715,11 @@ sub group_term { } sub course_types { - my @types = ('official','unofficial','community','textbook'); + my @types = ('official','unofficial','community'); my %typename = ( official => 'Official course', unofficial => 'Unofficial course', community => 'Community', - textbook => 'Textbook course', ); return (\@types,\%typename); } @@ -14559,8 +13851,8 @@ sub init_user_environment { } # ------------------------------------ Check browser type and MathML capability - my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode, - $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r); + my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml, + $clientunicode,$clientos) = &decode_user_agent($r); # ------------------------------------------------------------- Get environment @@ -14591,9 +13883,6 @@ sub init_user_environment { "browser.mathml" => $clientmathml, "browser.unicode" => $clientunicode, "browser.os" => $clientos, - "browser.mobile" => $clientmobile, - "browser.info" => $clientinfo, - "browser.osversion" => $clientosversion, "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'}, "request.course.fn" => '', "request.course.uri" => '', @@ -14613,12 +13902,6 @@ sub init_user_environment { $env{'browser.interface'}=$form->{'interface'}; } - if ($form->{'iptoken'}) { - my $lonhost = $r->dir_config('lonHostID'); - $initial_env{"user.noloadbalance"} = $lonhost; - $env{'user.noloadbalance'} = $lonhost; - } - my %is_adv = ( is_adv => $env{'user.adv'} ); my %domdef; unless ($domain eq 'public') { @@ -14631,7 +13914,7 @@ sub init_user_environment { undef,\%userenv,\%domdef,\%is_adv); } - foreach my $crstype ('official','unofficial','community','textbook') { + foreach my $crstype ('official','unofficial','community') { $userenv{'canrequest.'.$crstype} = &Apache::lonnet::usertools_access($username,$domain,$crstype, 'reload','requestcourses', @@ -14645,7 +13928,7 @@ sub init_user_environment { my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'], $domain,$username); my $reqstatus = $reqauthor{'author_status'}; - if ($reqstatus eq 'approval' || $reqstatus eq 'approved') { + if ($reqstatus eq 'approval' || $reqstatus eq 'approved') { if (ref($reqauthor{'author'}) eq 'HASH') { $userenv{'requestauthorqueued'} = $reqstatus.':'. $reqauthor{'author'}{'timestamp'}; @@ -14736,540 +14019,36 @@ sub clean_symb { return ($symb,$enc); } -############################################################ -############################################################ - -=pod - -=head1 Routines for building display used to search for courses - - -=over 4 - -=item * &build_filters() - -Create markup for a table used to set filters to use when selecting -courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm -and quotacheck.pl - - -Inputs: - -filterlist - anonymous array of fields to include as potential filters - -crstype - course type - -roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used - to pop-open a course selector (will contain "extra element"). - -multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1 - -filter - anonymous hash of criteria and their values - -action - form action - -numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number) - -caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm) - -cloneruname - username of owner of new course who wants to clone - -clonerudom - domain of owner of new course who wants to clone - -typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community) - -codetitlesref - reference to array of titles of components in institutional codes (official courses) - -codedom - domain - -formname - value of form element named "form". - -fixeddom - domain, if fixed. - -prevphase - value to assign to form element named "phase" when going back to the previous screen - -cnameelement - name of form element in form on opener page which will receive title of selected course - -cnumelement - name of form element in form on opener page which will receive courseID of selected course - -cdomelement - name of form element in form on opener page which will receive domain of selected course - -setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file - -clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course - -clonewarning - warning message about missing information for intended course owner when DC creates a course - - -Returns: $output - HTML for display of search criteria, and hidden form elements. - - -Side Effects: None - -=cut - -# ---------------------------------------------- search for courses based on last activity etc. - -sub build_filters { - my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action, - $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement, - $codetitlesref,$codedom,$formname,$fixeddom,$prevphase, - $cnameelement,$cnumelement,$cdomelement,$setroles, - $clonetext,$clonewarning) = @_; - my ($list,$jscript); - my $onchange = 'javascript:updateFilters(this)'; - my ($domainselectform,$sincefilterform,$createdfilterform, - $ownerdomselectform,$persondomselectform,$instcodeform, - $typeselectform,$instcodetitle); - if ($formname eq '') { - $formname = $caller; - } - foreach my $item (@{$filterlist}) { - unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') || - ($item eq 'sincefilter') || ($item eq 'createdfilter')) { - if ($item eq 'domainfilter') { - $filter->{$item} = &LONCAPA::clean_domain($filter->{$item}); - } elsif ($item eq 'coursefilter') { - $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item}); - } elsif ($item eq 'ownerfilter') { - $filter->{$item} = &LONCAPA::clean_username($filter->{$item}); - } elsif ($item eq 'ownerdomfilter') { - $filter->{'ownerdomfilter'} = - &LONCAPA::clean_domain($filter->{$item}); - $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'}, - 'ownerdomfilter',1); - } elsif ($item eq 'personfilter') { - $filter->{$item} = &LONCAPA::clean_username($filter->{$item}); - } elsif ($item eq 'persondomfilter') { - $persondomselectform = &select_dom_form($filter->{'persondomfilter'}, - 'persondomfilter',1); +sub build_release_hashes { + my ($checkparms,$checkresponsetypes,$checkcrstypes,$anonsurvey,$randomizetry) = @_; + return unless((ref($checkparms) eq 'HASH') && (ref($checkresponsetypes) eq 'HASH') && + (ref($checkcrstypes) eq 'HASH') && (ref($anonsurvey) eq 'HASH') && + (ref($randomizetry) eq 'HASH')); + foreach my $key (keys(%Apache::lonnet::needsrelease)) { + my ($item,$name,$value) = split(/:/,$key); + if ($item eq 'parameter') { + if (ref($checkparms->{$name}) eq 'ARRAY') { + unless(grep(/^\Q$name\E$/,@{$checkparms->{$name}})) { + push(@{$checkparms->{$name}},$value); + } } else { - $filter->{$item} =~ s/\W//g; + push(@{$checkparms->{$name}},$value); } - if (!$filter->{$item}) { - $filter->{$item} = ''; + } elsif ($item eq 'resourcetag') { + if ($name eq 'responsetype') { + $checkresponsetypes->{$value} = $Apache::lonnet::needsrelease{$key} } - } - if ($item eq 'domainfilter') { - my $allow_blank = 1; - if ($formname eq 'portform') { - $allow_blank=0; - } elsif ($formname eq 'studentform') { - $allow_blank=0; + } elsif ($item eq 'course') { + if ($name eq 'crstype') { + $checkcrstypes->{$value} = $Apache::lonnet::needsrelease{$key}; } - if ($fixeddom) { - $domainselectform = ''. - &Apache::lonnet::domain($codedom,'description'); - } else { - $domainselectform = &select_dom_form($filter->{$item}, - 'domainfilter', - $allow_blank,'',$onchange); - } - } else { - $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"'); - } - } - - # last course activity filter and selection - $sincefilterform = &timebased_select_form('sincefilter',$filter); - - # course created filter and selection - if (exists($filter->{'createdfilter'})) { - $createdfilterform = &timebased_select_form('createdfilter',$filter); - } - - my %lt = &Apache::lonlocal::texthash( - 'cac' => "$crstype Activity", - 'ccr' => "$crstype Created", - 'cde' => "$crstype Title", - 'cdo' => "$crstype Domain", - 'ins' => 'Institutional Code', - 'inc' => 'Institutional Categorization', - 'cow' => "$crstype Owner/Co-owner", - 'cop' => "$crstype Personnel Includes", - 'cog' => 'Type', - ); - - if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) { - my $typeval = 'Course'; - if ($crstype eq 'Community') { - $typeval = 'Community'; - } - $typeselectform = ''; - } else { - $typeselectform = '"; - } - - my ($cloneableonlyform,$cloneabletitle); - if (exists($filter->{'cloneableonly'})) { - my $cloneableon = ''; - my $cloneableoff = ' checked="checked"'; - if ($filter->{'cloneableonly'}) { - $cloneableon = $cloneableoff; - $cloneableoff = ''; - } - $cloneableonlyform = ''.(' 'x3).''; - if ($formname eq 'ccrs') { - $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom); - } else { - $cloneabletitle = &mt('Cloneable by you'); - } - } - my $officialjs; - if ($crstype eq 'Course') { - if (exists($filter->{'instcodefilter'})) { -# if (($fixeddom) || ($formname eq 'requestcrs') || -# ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) { - if ($codedom) { - $officialjs = 1; - ($instcodeform,$jscript,$$numtitlesref) = - &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker', - $officialjs,$codetitlesref); - if ($jscript) { - $jscript = ''."\n"; - } - } - if ($instcodeform eq '') { - $instcodeform = - ''; - $instcodetitle = $lt{'ins'}; - } else { - $instcodetitle = $lt{'inc'}; - } - if ($fixeddom) { - $instcodetitle .= '
    ('.$codedom.')'; - } - } - } - my $output = qq| - - -|; - if ($formname eq 'modifycourse') { - $output .= ''."\n". - ''."\n"; - } elsif ($formname eq 'quotacheck') { - $output .= qq| - - -|; - } else { - my $name_input; - if ($cnameelement ne '') { - $name_input = ''; - } - $output .= qq| - - -$name_input -$roleelement -$multelement -$typeelement -|; - if ($formname eq 'portform') { - $output .= ''."\n"; } } - if ($fixeddom) { - $output .= ''."\n"; - } - $output .= "
    \n".&Apache::lonhtmlcommon::start_pick_box(); - if ($sincefilterform) { - $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'}) - .$sincefilterform - .&Apache::lonhtmlcommon::row_closure(); - } - if ($createdfilterform) { - $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'}) - .$createdfilterform - .&Apache::lonhtmlcommon::row_closure(); - } - if ($domainselectform) { - $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'}) - .$domainselectform - .&Apache::lonhtmlcommon::row_closure(); - } - if ($typeselectform) { - if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) { - $output .= $typeselectform; - } else { - $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'}) - .$typeselectform - .&Apache::lonhtmlcommon::row_closure(); - } - } - if ($instcodeform) { - $output .= &Apache::lonhtmlcommon::row_title($instcodetitle) - .$instcodeform - .&Apache::lonhtmlcommon::row_closure(); - } - if (exists($filter->{'ownerfilter'})) { - $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}). - '
    '.&mt('Username').'
    '. - '
    '.&mt('Domain').'
    '. - $ownerdomselectform.'
    '. - &Apache::lonhtmlcommon::row_closure(); - } - if (exists($filter->{'personfilter'})) { - $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}). - '
    '.&mt('Username').'
    '. - '
    '.&mt('Domain').'
    '. - $persondomselectform.'
    '. - &Apache::lonhtmlcommon::row_closure(); - } - if (exists($filter->{'coursefilter'})) { - $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID')) - .'' - .&Apache::lonhtmlcommon::row_closure(); - } - if ($cloneableonlyform) { - $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle). - $cloneableonlyform.&Apache::lonhtmlcommon::row_closure(); - } - if (exists($filter->{'descriptfilter'})) { - $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'}) - .'' - .&Apache::lonhtmlcommon::row_closure(1); - } - $output .= &Apache::lonhtmlcommon::end_pick_box().'

    '.$clonetext."\n". - ''."\n". - '

    '."\n".''."\n".'
    '."\n"; - return $jscript.$clonewarning.$output; -} - -=pod - -=item * &timebased_select_form() - -Create markup for a dropdown list used to select a time-based -filter e.g., Course Activity, Course Created, when searching for courses -or communities - -Inputs: - -item - name of form element (sincefilter or createdfilter) - -filter - anonymous hash of criteria and their values - -Returns: HTML for a select box contained a blank, then six time selections, - with value set in incoming form variables currently selected. - -Side Effects: None - -=cut - -sub timebased_select_form { - my ($item,$filter) = @_; - if (ref($filter) eq 'HASH') { - $filter->{$item} =~ s/[^\d-]//g; - if (!$filter->{$item}) { $filter->{$item}=-1; } - return &select_form( - $filter->{$item}, - $item, - { '-1' => '', - '86400' => &mt('today'), - '604800' => &mt('last week'), - '2592000' => &mt('last month'), - '7776000' => &mt('last three months'), - '15552000' => &mt('last six months'), - '31104000' => &mt('last year'), - 'select_form_order' => - ['-1','86400','604800','2592000','7776000', - '15552000','31104000']}); - } -} - -=pod - -=item * &js_changer() - -Create script tag containing Javascript used to submit course search form -when course type or domain is changed, and also to hide 'Searching ...' on -page load completion for page showing search result. - -Inputs: None - -Returns: markup containing updateFilters() and hideSearching() javascript functions. - -Side Effects: None - -=cut - -sub js_changer { - return < -// {major},$anonsurvey->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:anonsurvey'}); + ($randomizetry->{major},$randomizetry->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:randomizetry'}); return; } -// ]]> - - -ENDJS -} - -=pod - -=item * &search_courses() - -Process selected filters form course search form and pass to lonnet::courseiddump -to retrieve a hash for which keys are courseIDs which match the selected filters. - -Inputs: - -dom - domain being searched - -type - course type ('Course' or 'Community' or '.' if any). - -filter - anonymous hash of criteria and their values - -numtitles - for institutional codes - number of categories - -cloneruname - optional username of new course owner - -clonerudom - optional domain of new course owner - -domcloner - Optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by, - (used when DC is using course creation form) - -codetitles - reference to array of titles of components in institutional codes (official courses). - - -Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type. - - -Side Effects: None - -=cut - - -sub search_courses { - my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles) = @_; - my (%courses,%showcourses,$cloner); - if (($filter->{'ownerfilter'} ne '') || - ($filter->{'ownerdomfilter'} ne '')) { - $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'. - $filter->{'ownerdomfilter'}; - } - foreach my $item ('descriptfilter','coursefilter','combownerfilter') { - if (!$filter->{$item}) { - $filter->{$item}='.'; - } - } - my $now = time; - my $timefilter = - ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'}); - my ($createdbefore,$createdafter); - if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) { - $createdbefore = $now; - $createdafter = $now-$filter->{'createdfilter'}; - } - my ($instcodefilter,$regexpok); - if ($numtitles) { - if ($env{'form.official'} eq 'on') { - $instcodefilter = - &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles); - $regexpok = 1; - } elsif ($env{'form.official'} eq 'off') { - $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles); - unless ($instcodefilter eq '') { - $regexpok = -1; - } - } - } else { - $instcodefilter = $filter->{'instcodefilter'}; - } - if ($instcodefilter eq '') { $instcodefilter = '.'; } - if ($type eq '') { $type = '.'; } - - if (($clonerudom ne '') && ($cloneruname ne '')) { - $cloner = $cloneruname.':'.$clonerudom; - } - %courses = &Apache::lonnet::courseiddump($dom, - $filter->{'descriptfilter'}, - $timefilter, - $instcodefilter, - $filter->{'combownerfilter'}, - $filter->{'coursefilter'}, - undef,undef,$type,$regexpok,undef,undef, - undef,undef,$cloner,$env{'form.cc_clone'}, - $filter->{'cloneableonly'}, - $createdbefore,$createdafter,undef, - $domcloner); - if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) { - my $ccrole; - if ($type eq 'Community') { - $ccrole = 'co'; - } else { - $ccrole = 'cc'; - } - my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'}, - $filter->{'persondomfilter'}, - 'userroles',undef, - [$ccrole,'in','ad','ep','ta','cr'], - $dom); - foreach my $role (keys(%rolehash)) { - my ($cnum,$cdom,$courserole) = split(':',$role); - my $cid = $cdom.'_'.$cnum; - if (exists($courses{$cid})) { - if (ref($courses{$cid}) eq 'HASH') { - if (ref($courses{$cid}{roles}) eq 'ARRAY') { - if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) { - push (@{$courses{$cid}{roles}},$courserole); - } - } else { - $courses{$cid}{roles} = [$courserole]; - } - $showcourses{$cid} = $courses{$cid}; - } - } - } - %courses = %showcourses; - } - return %courses; -} - - -=pod - -=back - -=cut - - sub update_content_constraints { my ($cdom,$cnum,$chome,$cid) = @_; my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired'); @@ -15307,32 +14086,6 @@ sub update_content_constraints { return; } -sub allmaps_incourse { - my ($cdom,$cnum,$chome,$cid) = @_; - if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') { - $cid = $env{'request.course.id'}; - $cdom = $env{'course.'.$cid.'.domain'}; - $cnum = $env{'course.'.$cid.'.num'}; - $chome = $env{'course.'.$cid.'.home'}; - } - my %allmaps = (); - my $lastchange = - &Apache::lonnet::get_coursechange($cdom,$cnum); - if ($lastchange > $env{'request.course.tied'}) { - my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum"); - unless ($ferr) { - &update_content_constraints($cdom,$cnum,$chome,$cid); - } - } - my $navmap = Apache::lonnavmaps::navmap->new(); - if (defined($navmap)) { - foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) { - $allmaps{$res->src()} = 1; - } - } - return \%allmaps; -} - sub parse_supplemental_title { my ($title) = @_; @@ -15356,30 +14109,6 @@ sub parse_supplemental_title { return $title; } -sub recurse_supplemental { - my ($cnum,$cdom,$suppmap,$numfiles,$errors) = @_; - if ($suppmap) { - my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap); - if ($fatal) { - $errors ++; - } else { - if ($#LONCAPA::map::resources > 0) { - foreach my $res (@LONCAPA::map::resources) { - my ($title,$src,$ext,$type,$status)=split(/\:/,$res); - if (($src ne '') && ($status eq 'res')) { - if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) { - ($numfiles,$errors) = &recurse_supplemental($cnum,$cdom,$1,$numfiles,$errors); - } else { - $numfiles ++; - } - } - } - } - } - } - return ($numfiles,$errors); -} - sub symb_to_docspath { my ($symb) = @_; return unless ($symb); @@ -15409,7 +14138,7 @@ sub symb_to_docspath { my $thistitle = $res->title(); $path .= '&'. &Apache::lonhtmlcommon::entity_encode($thisurl).'&'. - &escape($thistitle). + &Apache::lonhtmlcommon::entity_encode($thistitle). ':'.$res->randompick(). ':'.$res->randomout(). ':'.$res->encrypted(). @@ -15421,11 +14150,11 @@ sub symb_to_docspath { $path =~ s/^\&//; my $maptitle = $mapresobj->title(); if ($mapurl eq 'default') { - $maptitle = 'Main Content'; + $maptitle = 'Main Course Documents'; } $path .= (($path ne '')? '&' : ''). &Apache::lonhtmlcommon::entity_encode($mapurl).'&'. - &escape($maptitle). + &Apache::lonhtmlcommon::entity_encode($maptitle). ':'.$mapresobj->randompick(). ':'.$mapresobj->randomout(). ':'.$mapresobj->encrypted(). @@ -15435,14 +14164,14 @@ sub symb_to_docspath { my $maptitle = &Apache::lonnet::gettitle($mapurl); my $ispage = (($type eq 'page')? 1 : ''); if ($mapurl eq 'default') { - $maptitle = 'Main Content'; + $maptitle = 'Main Course Documents'; } $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'. - &escape($maptitle).':::::'.$ispage; + &Apache::lonhtmlcommon::entity_encode($maptitle).':::::'.$ispage; } unless ($mapurl eq 'default') { $path = 'default&'. - &escape('Main Content'). + &Apache::lonhtmlcommon::entity_encode('Main Course Documents'). ':::::&'.$path; } return $path; @@ -15455,15 +14184,15 @@ sub captcha_display { if ($captcha eq 'original') { $output = &create_captcha(); unless ($output) { - $error = 'captcha'; + $error = 'captcha'; } } elsif ($captcha eq 'recaptcha') { $output = &create_recaptcha($pubkey); unless ($output) { - $error = 'recaptcha'; + $error = 'recaptcha'; } } - return ($output,$error,$captcha); + return ($output,$error); } sub captcha_response { @@ -15539,9 +14268,8 @@ sub create_captcha { if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') { $output = ''."\n". &mt('Type in the letters/numbers shown below').' '. - ''. - '
    '. - 'captcha'; + '
    '. + ''; last; } } @@ -15567,7 +14295,7 @@ sub check_captcha { output_folder => $captcha_params{'output_dir'}, data_folder => $captcha_params{'db_dir'}, ); - $captcha_chk = $captcha->check_code($code,$md5sum); + my $captcha_chk = $captcha->check_code($code,$md5sum); my %captcha_hash = ( 0 => 'Code not checked (file error)', -1 => 'Failed: code expired', @@ -15582,15 +14310,11 @@ sub check_captcha { sub create_recaptcha { my ($pubkey) = @_; - my $use_ssl; - if ($ENV{'SERVER_PORT'} == 443) { - $use_ssl = 1; - } my $captcha = Captcha::reCAPTCHA->new; return $captcha->get_options_setter({theme => 'white'})."\n". - $captcha->get_html($pubkey,undef,$use_ssl). + $captcha->get_html($pubkey). &mt('If either word is hard to read, [_1] will replace them.', - 'reCAPTCHA refresh'). + 'reCAPTCHA refresh'). '

    '; } @@ -15611,102 +14335,11 @@ sub check_recaptcha { return $captcha_chk; } -sub emailusername_info { - my @fields = ('firstname','lastname','institution','web','location','officialemail'); - my %titles = &Apache::lonlocal::texthash ( - lastname => 'Last Name', - firstname => 'First Name', - institution => 'School/college/university', - location => "School's city, state/province, country", - web => "School's web address", - officialemail => 'E-mail address at institution (if different)', - ); - return (\@fields,\%titles); -} +=pod -sub cleanup_html { - my ($incoming) = @_; - my $outgoing; - if ($incoming ne '') { - $outgoing = $incoming; - $outgoing =~ s/;/;/g; - $outgoing =~ s/\#/#/g; - $outgoing =~ s/\&/&/g; - $outgoing =~ s//>/g; - $outgoing =~ s/\(/(/g; - $outgoing =~ s/\)/)/g; - $outgoing =~ s/"/"/g; - $outgoing =~ s/'/'/g; - $outgoing =~ s/\$/$/g; - $outgoing =~ s{/}{/}g; - $outgoing =~ s/=/=/g; - $outgoing =~ s/\\/\/g - } - return $outgoing; -} - -# Checks for critical messages and returns a redirect url if one exists. -# $interval indicates how often to check for messages. -sub critical_redirect { - my ($interval) = @_; - if ((time-$env{'user.criticalcheck.time'})>$interval) { - my @what=&Apache::lonnet::dump('critical', $env{'user.domain'}, - $env{'user.name'}); - &Apache::lonnet::appenv({'user.criticalcheck.time'=>time}); - my $redirecturl; - if ($what[0]) { - if (($what[0] ne 'con_lost') && ($what[0]!~/^error\:/)) { - $redirecturl='/adm/email?critical=display'; - my $url=&Apache::lonnet::absolute_url().$redirecturl; - return (1, $url); - } - } - } - return (); -} +=back -# Use: -# my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver); -# -################################################## -# password associated functions # -################################################## -sub des_keys { - # Make a new key for DES encryption. - # Each key has two parts which are returned separately. - # Please note: Each key must be passed through the &hex function - # before it is output to the web browser. The hex versions cannot - # be used to decrypt. - my @hexstr=('0','1','2','3','4','5','6','7', - '8','9','a','b','c','d','e','f'); - my $lkey=''; - for (0..7) { - $lkey.=$hexstr[rand(15)]; - } - my $ukey=''; - for (0..7) { - $ukey.=$hexstr[rand(15)]; - } - return ($lkey,$ukey); -} - -sub des_decrypt { - my ($key,$cyphertext) = @_; - my $keybin=pack("H16",$key); - my $cypher; - if ($Crypt::DES::VERSION>=2.03) { - $cypher=new Crypt::DES $keybin; - } else { - $cypher=new DES $keybin; - } - my $plaintext= - $cypher->decrypt(unpack("a8",pack("H16",substr($cyphertext,0,16)))); - $plaintext.= - $cypher->decrypt(unpack("a8",pack("H16",substr($cyphertext,16,16)))); - $plaintext=substr($plaintext,1,ord(substr($plaintext,0,1)) ); - return $plaintext; -} +=cut 1; __END__;