--- loncom/interface/loncommon.pm 2007/03/03 01:40:28 1.513 +++ loncom/interface/loncommon.pm 2007/08/23 22:21:15 1.567 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # a pile of common routines # -# $Id: loncommon.pm,v 1.513 2007/03/03 01:40:28 albertel Exp $ +# $Id: loncommon.pm,v 1.567 2007/08/23 22:21:15 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -68,8 +68,12 @@ use Apache::lontexconvert(); use Apache::lonclonecourse(); use LONCAPA qw(:DEFAULT :match); +# ---------------------------------------------- Designs +use vars qw(%defaultdesign); + my $readit; + ## ## Global Variables ## @@ -82,10 +86,6 @@ my %scprtag; my %fe; my %fd; my %fm; my %category_extensions; -# ---------------------------------------------- Designs - -my %designhash; - # ---------------------------------------------- Thesaurus variables # # %Keywords: @@ -151,30 +151,18 @@ BEGIN { } } -# -------------------------------------------------------------- domain designs - - my $filename; +# -------------------------------------------------------------- default domain designs my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors'; - opendir(DIR,$designdir); - while ($filename=readdir(DIR)) { - if ($filename!~/\.tab$/) { next; } - my ($domain)=($filename=~/^($match_domain)\./); - { - my $designfile = $designdir.'/'.$filename; - if ( open (my $fh,"<$designfile") ) { - while (my $line = <$fh>) { - next if ($line =~ /^\#/); - chomp($line); - my ($key,$val)=(split(/\=/,$line)); - if ($val) { $designhash{$domain.'.'.$key}=$val; } - } - close($fh); - } - } - + my $designfile = $designdir.'/default.tab'; + if ( open (my $fh,"<$designfile") ) { + while (my $line = <$fh>) { + next if ($line =~ /^\#/); + chomp($line); + my ($key,$val)=(split(/\=/,$line)); + if ($val) { $defaultdesign{$key}=$val; } + } + close($fh); } - closedir(DIR); - # ------------------------------------------------------------- file categories { @@ -346,10 +334,12 @@ sub studentbrowser_javascript { return (<<'ENDSTDBRW'); +RESIZE + +} + +=pod + +=back + =head1 Excel and CSV file utility routines =over 4 @@ -1224,7 +1276,7 @@ sub create_workbook { =item * create_text_file -Create a file to write to and eventually make available to the usre. +Create a file to write to and eventually make available to the user. If file creation fails, outputs an error message on the request object and return undefs. @@ -1270,12 +1322,14 @@ sub create_text_file { sub domain_select { my ($name,$value,$multiple)=@_; my %domains=map { - $_ => $_.' '.$Apache::lonnet::domaindescription{$_} + $_ => $_.' '. &Apache::lonnet::domain($_,'description') } &Apache::lonnet::all_domains(); if ($multiple) { $domains{''}=&mt('Any domain'); + $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))]; return &multiple_select_form($name,$value,4,\%domains); } else { + $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))]; return &select_form($name,$value,%domains); } } @@ -1284,6 +1338,12 @@ sub domain_select { =pod +=head1 Routines for form select boxes + +=over 4 + +=cut + =item * multiple_select_form($name,$value,$size,$hash,$order) Returns a string containing a form to allow a user to select the domain to preform an operation in. @@ -1430,18 +1490,28 @@ See loncreateuser.pm for an example invo If the $includeempty flag is set, it also includes an empty choice ("no domain selected"); +If the $showdomdesc flag is set, the domain name is followed by the domain description. + =cut #------------------------------------------- sub select_dom_form { - my ($defdom,$name,$includeempty) = @_; - my @domains = &Apache::lonnet::all_domains(); + my ($defdom,$name,$includeempty,$showdomdesc) = @_; + my @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains()); if ($includeempty) { @domains=('',@domains); } my $selectdomain = ""; return $selectdomain; @@ -1473,7 +1543,7 @@ sub home_server_option_list { =pod -=back +=back =cut @@ -1863,7 +1933,9 @@ If target_domain is not found in domain. #------------------------------------------- sub get_auth_defaults { my $domain=shift; - return ($Apache::lonnet::domain_auth_def{$domain},$Apache::lonnet::domain_auth_arg_def{$domain}); + return (&Apache::lonnet::domain($domain,'auth_def'), + &Apache::lonnet::domain($domain,'auth_arg_def')); + } ############################################################### ## End Get Authentication Defaults for Domain ## @@ -2058,6 +2130,7 @@ if $first is set to 'lastname' then it r ############################################################### sub plainname { my ($uname,$udom,$first)=@_; + return if (!defined($uname) || !defined($udom)); my %names=&getnames($uname,$udom); my $name=&Apache::lonnet::format_name($names{'firstname'}, $names{'middlename'}, @@ -2089,6 +2162,7 @@ if the user does not sub nickname { my ($uname,$udom)=@_; + return if (!defined($uname) || !defined($udom)); my %names=&getnames($uname,$udom); my $name=$names{'nickname'}; if ($name) { @@ -2104,6 +2178,7 @@ sub nickname { sub getnames { my ($uname,$udom)=@_; + return if (!defined($uname) || !defined($udom)); if ($udom eq 'public' && $uname eq 'public') { return ('lastname' => &mt('Public')); } @@ -2120,6 +2195,19 @@ sub getnames { } } +# -------------------------------------------------------------------- getemails +=pod + +=item * getemails($uname,$udom) + +Gets a user's email information and returns it as a hash with keys: +notification, critnotification, permanentemail + +For notification and critnotification, values are comma-separated lists +of e-mail address(es); for permanentemail, value is a single e-mail address. + +=cut + sub getemails { my ($uname,$udom)=@_; if ($udom eq 'public' && $uname eq 'public') { @@ -2141,6 +2229,15 @@ sub getemails { } } +sub flush_email_cache { + my ($uname,$udom)=@_; + if (!$udom) { $udom =$env{'user.domain'}; } + if (!$uname) { $uname=$env{'user.name'}; } + return if ($udom eq 'public' && $uname eq 'public'); + my $id=$uname.':'.$udom; + &Apache::lonnet::devalidate_cache_new('emailscache',$id); +} + # ------------------------------------------------------------------ Screenname =pod @@ -2214,7 +2311,8 @@ sub track_student_link { $target = ''; } if ($start) { $link.='&start='.$start; } - + $title = &mt($title); + $linktext = &mt($linktext); return qq{$linktext}. &help_open_topic('View_recent_activity'); } @@ -2447,19 +2545,21 @@ sub preferred_languages { if ($browser) { @languages=(@languages,split(/\s*(\,|\;|\:)\s*/,$browser)); } - if ($Apache::lonnet::domain_lang_def{$env{'user.domain'}}) { + if (&Apache::lonnet::domain($env{'user.domain'},'lang_def')) { @languages=(@languages, - $Apache::lonnet::domain_lang_def{$env{'user.domain'}}); + &Apache::lonnet::domain($env{'user.domain'}, + 'lang_def')); } - if ($Apache::lonnet::domain_lang_def{$env{'request.role.domain'}}) { + if (&Apache::lonnet::domain($env{'request.role.domain'},'lang_def')) { @languages=(@languages, - $Apache::lonnet::domain_lang_def{$env{'request.role.domain'}}); + &Apache::lonnet::domain($env{'request.role.domain'}, + 'lang_def')); } - if ($Apache::lonnet::domain_lang_def{ - $Apache::lonnet::perlvar{'lonDefDomain'}}) { + if (&Apache::lonnet::domain($Apache::lonnet::perlvar{'lonDefDomain'}, + 'lang_def')) { @languages=(@languages, - $Apache::lonnet::domain_lang_def{ - $Apache::lonnet::perlvar{'lonDefDomain'}}); + &Apache::lonnet::domain($Apache::lonnet::perlvar{'lonDefDomain'}, + 'lang_def')); } # turn "en-ca" into "en-ca,en" my @genlanguages; @@ -2665,7 +2765,6 @@ sub get_student_answers { $moreenv{'grade_target'}='answer'; %moreenv=(%form,%moreenv); $feedurl = &Apache::lonnet::clutter($feedurl); - &Apache::lonenc::check_encrypt(\$feedurl); my $userview=&Apache::lonnet::ssi($feedurl,%moreenv); return $userview; } @@ -2916,7 +3015,7 @@ sub blockcheck { } my $no_ownblock = 0; my $no_userblock = 0; - if ($otheruser) { + if ($otheruser && $activity ne 'com') { # Check if current user has 'evb' priv for this if (defined($own_courses{$course})) { foreach my $sec (keys(%{$own_courses{$course}})) { @@ -3169,7 +3268,7 @@ Returns: Determines which domain should ############################################### sub determinedomain { my $domain=shift; - if (! $domain) { + if (! $domain) { # Determine domain if we have not been given one $domain = $Apache::lonnet::perlvar{'lonDefDomain'}; if ($env{'user.domain'}) { $domain=$env{'user.domain'}; } @@ -3180,6 +3279,60 @@ sub determinedomain { return $domain; } ############################################### + +sub devalidate_domconfig_cache { + my ($udom)=@_; + &Apache::lonnet::devalidate_cache_new('domainconfig',$udom); +} + +# ---------------------- Get domain configuration for a domain +sub get_domainconf { + my ($udom) = @_; + my $cachetime=1800; + my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom); + if (defined($cached)) { return %{$result}; } + + my %domconfig = &Apache::lonnet::get_dom('configuration', + ['login','rolecolors'],$udom); + my %designhash; + if (keys(%domconfig) > 0) { + if (ref($domconfig{'login'}) eq 'HASH') { + foreach my $key (keys(%{$domconfig{'login'}})) { + $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key}; + } + } + if (ref($domconfig{'rolecolors'}) eq 'HASH') { + foreach my $role (keys(%{$domconfig{'rolecolors'}})) { + if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') { + foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) { + $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item}; + } + } + } + } + } else { + my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors'; + my $designfile = $designdir.'/'.$udom.'.tab'; + if (-e $designfile) { + if ( open (my $fh,"<$designfile") ) { + while (my $line = <$fh>) { + next if ($line =~ /^\#/); + chomp($line); + my ($key,$val)=(split(/\=/,$line)); + if ($val) { $designhash{$udom.'.'.$key}=$val; } + } + close($fh); + } + } + if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') { + $designhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif"; + } + } + &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash, + $cachetime); + return %designhash; +} + =pod =item * &domainlogo() @@ -3193,13 +3346,21 @@ If the domain logo does not exist, a des ############################################### sub domainlogo { - my $domain = &determinedomain(shift); - # See if there is a logo - if (-e '/home/httpd/html/adm/lonDomLogos/'.$domain.'.gif') { - my $logo=&lonhttpdurl("/adm/lonDomLogos/$domain.gif"); - return ''.$domain.''; - } elsif(exists($Apache::lonnet::domaindescription{$domain})) { - return $Apache::lonnet::domaindescription{$domain}; + my $domain = &determinedomain(shift); + my %designhash = &get_domainconf($domain); + # See if there is a logo + if ($designhash{$domain.'.login.domlogo'} ne '') { + my $imgsrc = $designhash{$domain.'.login.domlogo'}; + if ($imgsrc =~ m{^/(adm|res)/}) { + if ($imgsrc =~ m{^/res/}) { + my $local_name = &Apache::lonnet::filelocation('',$imgsrc); + &Apache::lonnet::repcopy($local_name); + } + $imgsrc = &lonhttpdurl($imgsrc); + } + return ''.$domain.''; + } elsif (defined(&Apache::lonnet::domain($domain,'description'))) { + return &Apache::lonnet::domain($domain,'description'); } else { return ''; } @@ -3235,11 +3396,24 @@ sub designparm { return $env{'environment.color.'.$which}; } $domain=&determinedomain($domain); - if (exists($designhash{$domain.'.'.$which})) { - return $designhash{$domain.'.'.$which}; + my %domdesign = &get_domainconf($domain); + my $output; + if ($domdesign{$domain.'.'.$which} ne '') { + $output = $domdesign{$domain.'.'.$which}; } else { - return $designhash{'default.'.$which}; + $output = $defaultdesign{$which}; + } + if (($which =~ /^(student|coordinator|author|admin)\.img$/) || + ($which =~ /login\.(img|logo|domlogo)/)) { + if ($output =~ m{^/(adm|res)/}) { + if ($output =~ m{^/res/}) { + my $local_name = &Apache::lonnet::filelocation('',$output); + &Apache::lonnet::repcopy($local_name); + } + $output = &lonhttpdurl($output); + } } + return $output; } ############################################### @@ -3249,7 +3423,7 @@ sub designparm { =back -=head1 HTTP Helpers +=head1 HTML Helpers =over 4 @@ -3290,6 +3464,9 @@ Inputs: =item * $args, optional argument valid values are no_auto_mt_title -> prevents &mt()ing the title arg + inherit_jsmath -> when creating popup window in a page, + should it have jsmath forced on by the + current page =back @@ -3346,11 +3523,9 @@ sub bodytag { # construct main body tag my $bodytag = "". - &Apache::lontexconvert::init_math_support(); + &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'}); - if ($bodyonly - || ($env{'request.state'} eq 'construct' - && $env{'environment.remote'} ne 'off' )) { + if ($bodyonly) { return $bodytag; } elsif ($env{'browser.interface'} eq 'textual') { # Accessibility @@ -3458,8 +3633,11 @@ ENDROLE # Top frame rendering, Remote is up # - my $upperleft=''.$function.''; + my $imgsrc = $img; + if ($img =~ /^\/adm/) { + $imgsrc = 'http://'.$ENV{'HTTP_HOST'}.':'.$lonhttpdPort.$img; + } + my $upperleft=''.$function.''; # Explicit link to get inline menu my $menu= ($no_inline_link?'' @@ -3542,20 +3720,12 @@ sub make_attr_string { =pod -=back - -=head1 HTML Helpers - -=over 4 - =item * &endbodytag() Returns a uniform footer for LON-CAPA web pages. Inputs: none -=back - =cut sub endbodytag { @@ -3572,8 +3742,6 @@ sub endbodytag { =pod -=over 4 - =item * &standard_css() Returns a style sheet @@ -3584,8 +3752,6 @@ Inputs: (all optional) function -> force usage of a specific rolish color scheme bgcolor -> override the default page bgcolor -=back - =cut sub standard_css { @@ -3624,20 +3790,18 @@ sub standard_css { my $border = ($env{'browser.type'} eq 'explorer') ? '0px 2px 0px 2px' : '0px 3px 0px 4px'; + return < prevent &mt()ing the title arg -=back - =cut sub headtag { @@ -4288,16 +4661,12 @@ ADDMETA =pod -=over 4 - =item * &font_settings() Returns neccessary to set the proper encoding Inputs: none -=back - =cut sub font_settings { @@ -4314,16 +4683,12 @@ sub font_settings { =pod -=over 4 - =item * &xml_begin() Returns the needed doctype and Inputs: none -=back - =cut sub xml_begin { @@ -4348,16 +4713,12 @@ sub xml_begin { =pod -=over 4 - =item * &endheadtag() Returns a uniform for LON-CAPA web pages. Inputs: none -=back - =cut sub endheadtag { @@ -4366,8 +4727,6 @@ sub endheadtag { =pod -=over 4 - =item * &head() Returns a uniform complete .. section for LON-CAPA web pages. @@ -4375,8 +4734,6 @@ Returns a uniform complete .. -=back - =cut sub head { @@ -4386,8 +4743,6 @@ sub head { =pod -=over 4 - =item * &start_page() Returns a complete .. section for LON-CAPA web pages. @@ -4426,7 +4781,9 @@ Inputs: $title - optional title for the no_auto_mt_title -> prevent &mt()ing the title arg -=back + inherit_jsmath -> when creating popup window in a page, + should it have jsmath forced on by the + current page =cut @@ -4479,8 +4836,6 @@ sub start_page { =pod -=over 4 - =item * &head() Returns a complete section for LON-CAPA web pages. @@ -4638,10 +4993,61 @@ sub simple_error_page { } } +=pod + +=item * &inhibit_menu_check($arg) + +Checks for a inhibitmenu state and generates output to preserve it + +Inputs: $arg - can be any of + - undef - in which case the return value is a string + to add into arguments list of a uri + - 'input' - in which case the return value is a HTML +
field of type hidden to + preserve the value + - a url - in which case the return value is the url with + the neccesary cgi args added to preserve the + inhibitmenu state + - a ref to a url - no return value, but the string is + updated to include the neccessary cgi + args to preserve the inhibitmenu state + +=cut + +sub inhibit_menu_check { + my ($arg) = @_; + &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']); + if ($arg eq 'input') { + if ($env{'form.inhibitmenu'}) { + return ''; + } else { + return + } + } + if ($env{'form.inhibitmenu'}) { + if (ref($arg)) { + $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'}; + } elsif ($arg eq '') { + $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'}; + } else { + $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'}; + } + } + if (!ref($arg)) { + return $arg; + } +} + ############################################### =pod +=back + +=head1 User Information Routines + +=over 4 + =item * &get_users_function() Used by &bodytag to determine the current users primary role. @@ -4669,7 +5075,7 @@ sub get_users_function { =pod -=item * &check_user_status +=item * &check_user_status() Determines current status of supplied role for a specific user. Roles can be active, previous or future. @@ -5030,11 +5436,18 @@ Incoming parameters: 2. user's domain Returns: -1. Disk quota (in Mb) assigned to student. +1. Disk quota (in Mb) assigned to student. +2. (Optional) Type of setting: custom or default + (individually assigned or default for user's + institutional status). +3. (Optional) - User's institutional status (e.g., faculty, staff + or student - types as defined in localenroll::inst_usertypes + for user's domain, which determines default quota for user. +4. (Optional) - Default quota which would apply to the user. If a value has been stored in the user's environment, -it will return that, otherwise it returns the default -for users in the domain. +it will return that, otherwise it returns the maximal default +defined for the user's instituional status(es) in the domain. =cut @@ -5043,7 +5456,7 @@ for users in the domain. sub get_user_quota { my ($uname,$udom) = @_; - my $quota; + my ($quota,$quotatype,$settingstatus,$defquota); if (!defined($udom)) { $udom = $env{'user.domain'}; } @@ -5053,23 +5466,38 @@ sub get_user_quota { if (($udom eq '' || $uname eq '') || ($udom eq 'public') && ($uname eq 'public')) { $quota = 0; + $quotatype = 'default'; + $defquota = 0; } else { + my $inststatus; if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) { $quota = $env{'environment.portfolioquota'}; + $inststatus = $env{'environment.inststatus'}; } else { - my %userenv = &Apache::lonnet::dump('environment',$udom,$uname); + my %userenv = + &Apache::lonnet::get('environment',['portfolioquota', + 'inststatus'],$udom,$uname); my ($tmp) = keys(%userenv); if ($tmp !~ /^(con_lost|error|no_such_host)/i) { $quota = $userenv{'portfolioquota'}; + $inststatus = $userenv{'inststatus'}; } else { undef(%userenv); } } + ($defquota,$settingstatus) = &default_quota($udom,$inststatus); if ($quota eq '') { - $quota = &default_quota($udom); + $quota = $defquota; + $quotatype = 'default'; + } else { + $quotatype = 'custom'; } } - return $quota; + if (wantarray) { + return ($quota,$quotatype,$settingstatus,$defquota); + } else { + return $quota; + } } ############################################### @@ -5078,32 +5506,68 @@ sub get_user_quota { =item * &default_quota() -Retrieves default quota assigned for storage of user portfolio files +Retrieves default quota assigned for storage of user portfolio files, +given an (optional) user's institutional status. Incoming parameters: 1. domain +2. (Optional) institutional status(es). This is a : separated list of + status types (e.g., faculty, staff, student etc.) + which apply to the user for whom the default is being retrieved. + If the institutional status string in undefined, the domain + default quota will be returned. Returns: 1. Default disk quota (in Mb) for user portfolios in the domain. +2. (Optional) institutional type which determined the value of the + default quota. If a value has been stored in the domain's configuration db, it will return that, otherwise it returns 20 (for backwards compatibility with domains which have not set up a configuration db file; the original statically defined portfolio quota was 20 Mb). +If the user's status includes multiple types (e.g., staff and student), +the largest default quota which applies to the user determines the +default quota returned. + =cut ############################################### sub default_quota { - my ($udom) = @_; - my %defaults = &Apache::lonnet::get_dom('configuration', - ['portfolioquota'],$udom); - if ($defaults{'portfolioquota'} ne '') { - return $defaults{'portfolioquota'}; + my ($udom,$inststatus) = @_; + my ($defquota,$settingstatus); + my %quotahash = &Apache::lonnet::get_dom('configuration', + ['quota'],$udom); + if (ref($quotahash{'quota'}) eq 'HASH') { + if ($inststatus ne '') { + my @statuses = split(/:/,$inststatus); + foreach my $item (@statuses) { + if ($quotahash{'quota'}{$item} ne '') { + if ($defquota eq '') { + $defquota = $quotahash{'quota'}{$item}; + $settingstatus = $item; + } elsif ($quotahash{'quota'}{$item} > $defquota) { + $defquota = $quotahash{'quota'}{$item}; + $settingstatus = $item; + } + } + } + } + if ($defquota eq '') { + $defquota = $quotahash{'quota'}{'default'}; + $settingstatus = 'default'; + } } else { - return '20'; + $settingstatus = 'default'; + $defquota = 20; + } + if (wantarray) { + return ($defquota,$settingstatus); + } else { + return $defquota; } } @@ -5144,8 +5608,216 @@ sub get_secgrprole_info { return (\@sections,\@groups,$allroles,$rolehash,$accesshash); } +sub user_picker { + my ($dom,$srch,$forcenewuser) = @_; + my $currdom = $dom; + my %curr_selected = ( + srchin => 'dom', + srchby => 'uname', + ); + my $srchterm; + if (ref($srch) eq 'HASH') { + if ($srch->{'srchby'} ne '') { + $curr_selected{'srchby'} = $srch->{'srchby'}; + } + if ($srch->{'srchin'} ne '') { + $curr_selected{'srchin'} = $srch->{'srchin'}; + } + if ($srch->{'srchtype'} ne '') { + $curr_selected{'srchtype'} = $srch->{'srchtype'}; + } + if ($srch->{'srchdomain'} ne '') { + $currdom = $srch->{'srchdomain'}; + } + $srchterm = $srch->{'srchterm'}; + } + my %lt=&Apache::lonlocal::texthash( + 'doma' => 'Domain/institution to search', + 'uname' => 'username', + 'lastname' => 'last name', + 'lastfirst' => 'last name, first name', + 'crs' => 'in this course', + 'dom' => 'in this domain', + 'alc' => 'all LON-CAPA', + 'instd' => 'in institutional directory', + 'exact' => 'is', + 'contains' => 'contains', + ); + my $domform = &select_dom_form($currdom,'srchdomain',1,1); + my $srchinsel = ' \n"; + + my $srchbysel = ' \n"; + + my $srchtypesel = ' \n"; + + my ($newuserscript,$new_user_create); + + if ($forcenewuser) { + $new_user_create = '

&"').'" onclick="javascript:setSearch(\'1\');" />

'; + $newuserscript = <<"ENDSCRIPT"; + +function setSearch(createnew) { + if (createnew == 1) { + for (var i=0; i +function validateEntry() { + + var checkok = 1; + var srchin; + for (var i=0; i + +$new_user_create + + + + + + + + + +
$srchbysel + $srchtypesel + + $srchinsel +
$lt{'doma'}: $domform
+
+END_BLOCK + + return $output; +} + + + =pod +=back + +=head1 HTTP Helpers + +=over 4 + =item * get_unprocessed_cgi($query,$possible_names) Modify the %env hash to contain unprocessed CGI form parameters held in @@ -5395,28 +6067,50 @@ sub record_sep { $i++; } } else { - my @allfields; + my $separator=','; if ($env{'form.upfiletype'} eq 'semisv') { - @allfields=split(/;/,$record,-1); - } else { - @allfields=split(/\,/,$record,-1); + $separator=';'; } my $i=0; - my $j; - for ($j=0;$j<=$#allfields;$j++) { - my $field=$allfields[$j]; - if ($field=~/^\s*(\"|\')/) { - my $delimiter=$1; - while (($field!~/$delimiter$/) && ($j<$#allfields)) { - $j++; - $field.=','.$allfields[$j]; - } - $field=~s/^\s*$delimiter//; - $field=~s/$delimiter\s*$//; - } - $components{&takeleft($i)}=$field; - $i++; +# the character we are looking for to indicate the end of a quote or a record + my $looking_for=$separator; +# do not add the characters to the fields + my $ignore=0; +# we just encountered a separator (or the beginning of the record) + my $just_found_separator=1; +# store the field we are working on here + my $field=''; +# work our way through all characters in record + foreach my $character ($record=~/(.)/g) { + if ($character eq $looking_for) { + if ($character ne $separator) { +# Found the end of a quote, again looking for separator + $looking_for=$separator; + $ignore=1; + } else { +# Found a separator, store away what we got + $components{&takeleft($i)}=$field; + $i++; + $just_found_separator=1; + $ignore=0; + $field=''; + } + next; + } +# single or double quotation marks after a separator indicate beginning of a quote +# we are now looking for the end of the quote and need to ignore separators + if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) { + $looking_for=$character; + next; + } +# ignore would be true after we reached the end of a quote + if ($ignore) { next; } + if (($just_found_separator) && ($character=~/\s/)) { next; } + $field.=$character; + $just_found_separator=0; } +# catch the very last entry, since we never encountered the separator + $components{&takeleft($i)}=$field; } return %components; } @@ -6183,35 +6877,53 @@ sub commit_customrole { } sub commit_standardrole { - my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec) = @_; - my $output; - my $logmsg; + my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_; + my ($output,$logmsg,$linefeed); + if ($context eq 'auto') { + $linefeed = "\n"; + } else { + $linefeed = "
\n"; + } if ($three eq 'st') { - my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec); - if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course')) { + my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end, + $one,$two,$sec,$context); + if (($result =~ /^error/) || ($result eq 'not_in_class') || + ($result eq 'unknown_course')) { $output = "Error: $result\n"; } else { - $output = &mt('Assigning').' '.$three.' in '.$url. + $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url. ($start?', '.&mt('starting').' '.localtime($start):''). - ($end?', '.&mt('ending').' '.localtime($end):''). - ': '.$result.'
'. - &mt('Add to classlist').': ok
'; + ($end?', '.&mt('ending').' '.localtime($end):'').': '; + if ($context eq 'auto') { + $output .= $result.$linefeed.&mt('Add to classlist').': ok'; + } else { + $output .= ''.$result.''.$linefeed. + &mt('Add to classlist').': ok'; + } + $output .= $linefeed; } } else { $output = &mt('Assigning').' '.$three.' in '.$url. ($start?', '.&mt('starting').' '.localtime($start):''). - ($end?', '.&mt('ending').' '.localtime($end):'').': '. - &Apache::lonnet::assignrole( - $udom,$uname,$url,$three,$end,$start). - '
'; + ($end?', '.&mt('ending').' '.localtime($end):'').': '; + my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start); + if ($context eq 'auto') { + $output .= $result.$linefeed; + } else { + $output .= ''.$result.''.$linefeed; + } } return $output; } sub commit_studentrole { - my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec) = @_; - my $linefeed = '
'."\n"; - my $result; + my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_; + my ($result,$linefeed); + if ($context eq 'auto') { + $linefeed = "\n"; + } else { + $linefeed = '
'."\n"; + } if (defined($one) && defined($two)) { my $cid=$one.'_'.$two; my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid); @@ -6257,9 +6969,63 @@ sub commit_studentrole { ############################################################ ############################################################ +sub check_clone { + my ($args) = @_; + my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'}; + my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid); + my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom); + my $clonemsg; + my $can_clone = 0; + + if ($clonehome eq 'no_host') { + $clonemsg = &mt('Attempting to clone non-existing [_1]', + $args->{'crstype'}); + } else { + my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1}); + if ($env{'request.role.domain'} eq $args->{'form.clonedomain'}) { + $can_clone = 1; + } else { + my %clonehash = &Apache::lonnet::get('environment',['cloners'], + $args->{'clonedomain'},$args->{'clonecourse'}); + my @cloners = split(/,/,$clonehash{'cloners'}); + my %roleshash = + &Apache::lonnet::get_my_roles($args->{'ccuname'}, + $args->{'ccdomain'},'userroles',['active'],['cc'], + [$args->{'clonedomain'}]); + if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':cc'}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) { + $can_clone = 1; + } else { + $clonemsg = &mt('The new course was not cloned from an existing course because the new course owner ([_1]) does not have cloning rights in the existing course ([_2]).',$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'}); + } + } + } + + return ($can_clone, $clonemsg, $cloneid, $clonehome); +} + sub construct_course { - my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname) = @_; + my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context) = @_; my $outcome; + my $linefeed = '
'."\n"; + if ($context eq 'auto') { + $linefeed = "\n"; + } + +# +# Are we cloning? +# + my ($can_clone, $clonemsg, $cloneid, $clonehome); + if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) { + ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args); + if ($context ne 'auto') { + $clonemsg = ''.$clonemsg.''; + } + $outcome .= $clonemsg.$linefeed; + + if (!$can_clone) { + return (0,$outcome); + } + } # # Open course @@ -6280,44 +7046,40 @@ sub construct_course { # Utils::Course. This needs to at least be output as a comment # if anyone ever decides to not show this, and Utils::Course::new # will need to be suitably modified. - $outcome .= &mt('New LON-CAPA [_1] ID: [_2]
',$crstype,$$courseid); + $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed; # # Check if created correctly # ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid); my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom); - $outcome .= &mt('Created on').': '.$crsuhome.'
'; -# -# Are we cloning? + $outcome .= &mt('Created on').': '.$crsuhome.$linefeed; + # - my $cloneid=''; - if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) { - $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'}; - my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid); - my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom); - if ($clonehome eq 'no_host') { - $outcome .= - '
'.&mt('Attempting to clone non-existing [_1]',$crstype).' '.$cloneid.''; - } else { - $outcome .= - '
'.&mt('Cloning [_1] from [_2]',$crstype,$clonehome).''; - my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum); +# Do the cloning +# + if ($can_clone && $cloneid) { + $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome); + if ($context ne 'auto') { + $clonemsg = ''.$clonemsg.''; + } + $outcome .= $clonemsg.$linefeed; + my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum); # Copy all files - &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid); + &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid); # Restore URL - $cenv{'url'}=$oldcenv{'url'}; + $cenv{'url'}=$oldcenv{'url'}; # Restore title - $cenv{'description'}=$oldcenv{'description'}; + $cenv{'description'}=$oldcenv{'description'}; # restore grading mode - if (defined($oldcenv{'grading'})) { - $cenv{'grading'}=$oldcenv{'grading'}; - } -# Mark as cloned - $cenv{'clonedfrom'}=$cloneid; - delete($cenv{'default_enrollment_start_date'}); - delete($cenv{'default_enrollment_end_date'}); + if (defined($oldcenv{'grading'})) { + $cenv{'grading'}=$oldcenv{'grading'}; } +# Mark as cloned + $cenv{'clonedfrom'}=$cloneid; + delete($cenv{'default_enrollment_start_date'}); + delete($cenv{'default_enrollment_end_date'}); } + # # Set environment (will override cloned, if existing) # @@ -6421,11 +7183,24 @@ sub construct_course { 'dnhr' => 'does not have rights to access enrollment in these classes', 'adby' => 'as determined by the policies of your institution on access to official classlists' ); - $outcome .= ''.$lt{'tclb'}.' ('.$cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.' ('.$lt{'adby'}.').
    '."\n"; - foreach (@badclasses) { - $outcome .= "
  • $_
  • \n"; - } - $outcome .= "


\n"; + my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}. + ' ('.$lt{'adby'}.')'; + if ($context eq 'auto') { + $outcome .= $badclass_msg.$linefeed; + $outcome .= '
'.$badclass_msg.$linefeed.'
    '."\n"; + foreach my $item (@badclasses) { + if ($context eq 'auto') { + $outcome .= " - $item\n"; + } else { + $outcome .= "
  • $item
  • \n"; + } + } + if ($context eq 'auto') { + $outcome .= $linefeed; + } else { + $outcome .= "


\n"; + } + } } if ($args->{'no_end_date'}) { $args->{'endaccess'} = 0; @@ -6441,8 +7216,13 @@ sub construct_course { $cenv{'internal.autharg'} = $args->{'autharg'}; if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) { if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') { - $outcome .= ''. - &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').'

'; + 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'); + if ($context eq 'auto') { + $outcome .= $krb_msg; + } else { + $outcome .= ''.$krb_msg.''; + } + $outcome .= $linefeed; } } if (($args->{'ccdomain'}) && ($args->{'ccuname'})) { @@ -6498,8 +7278,8 @@ sub construct_course { # By default, use standard grading if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; } - $outcome .= ('
'.&mt('Setting environment').': '. - &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).'
'); + $outcome .= $linefeed.&mt('Setting environment').': '. + &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed; # # Open all assignments # @@ -6509,7 +7289,7 @@ sub construct_course { $storeunder.'.type' => 'date_start'); $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput - ('resourcedata',\%storecontent,$$crsudom,$$crsunum).'
'; + ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed; } # # Set first page @@ -6536,9 +7316,10 @@ sub construct_course { (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1); if ($errtext) { $fatal=2; } - $outcome .= ($fatal?$errtext:'write ok').'
'; + $outcome .= ($fatal?$errtext:'write ok').$linefeed; } - return $outcome; + + return (1,$outcome); } ############################################################