--- loncom/interface/lonrequestcourse.pm 2014/06/16 01:42:22 1.85 +++ loncom/interface/lonrequestcourse.pm 2015/06/14 00:02:43 1.90 @@ -1,7 +1,7 @@ # The LearningOnline Network # Request a course # -# $Id: lonrequestcourse.pm,v 1.85 2014/06/16 01:42:22 raeburn Exp $ +# $Id: lonrequestcourse.pm,v 1.90 2015/06/14 00:02:43 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -768,7 +768,7 @@ END "; } } - my %lt = &Apache::lonlocal::texthash( + my %js_lt = &Apache::lonlocal::texthash( official => 'You are not permitted to request creation of an official course in this domain.', unofficial => 'You are not permitted to request creation of an unofficial course in this domain.', community => 'You are not permitted to request creation of a community in this domain.', @@ -776,33 +776,34 @@ END all => 'You must choose a specific course type when making a new course request.', allt => '"All types" is not allowed.', ); + &js_escape(\%js_lt); $js .= <<END; if (crschoice == 'official') { if (official != 1) { - alert("$lt{'official'}"); + alert("$js_lt{'official'}"); return false; } } else { if (crschoice == 'unofficial') { if (unofficial != 1) { - alert("$lt{'unofficial'}"); + alert("$js_lt{'unofficial'}"); return false; } } else { if (crschoice == 'community') { if (community != 1) { - alert("$lt{'community'}"); + alert("$js_lt{'community'}"); return false; } } else { if (crschoice == 'textbook') { if (textbook != 1) { - alert("$lt{'community'}"); + alert("$js_lt{'textbook'}"); return false; } } else { if (actionchoice == 'new') { - alert('$lt{'all'}'+'\\n'+'$lt{'allt'}'); + alert('$js_lt{'all'}'+'\\n'+'$js_lt{'allt'}'); return false; } } @@ -939,7 +940,8 @@ END if ($action eq 'new') { my $jsextra; if (($state eq 'courseinfo') || ($state eq 'codepick')) { - $jsextra = "\n".&Apache::loncommon::coursebrowser_javascript($dom); + $jsextra = "\n".&Apache::loncommon::coursebrowser_javascript($dom,'','','','','', + $newinstcode); } elsif ($state eq 'enrollment') { if (($env{'form.crstype'} eq 'official') && (&Apache::lonnet::auto_run('',$dom))) { @@ -1174,6 +1176,8 @@ sub enrollment_lcsec_js { my %alerts = §ion_check_alerts(); my $secname = $alerts{'badsec'}; my $secnone = $alerts{'reserved'}; + &js_escape(\$secname); + &js_escape(\$secnone); my $output = ' function validateEnrollSections(formname,nextstate) { var badsectotal = 0; @@ -1231,8 +1235,10 @@ function validateEnrollSections(formname sub personnel_lcsec_js { my %alerts = §ion_check_alerts(); - my $secname = $alerts{'badsec'}.'\\n'.$alerts{'separate'}; + my $secname = $alerts{'badsec'}."\n".$alerts{'separate'}; my $secnone = $alerts{'reserved'}; + &js_escape(\$secname); + &js_escape(\$secnone); my $output = ' function validatePersonnelSections(formname,nextstate) { var badsectotal = 0; @@ -1568,8 +1574,8 @@ sub print_request_form { \%cat_order,\@code_order); } my $lonhost = $r->dir_config('lonHostID'); - my ($storeresult,$result) = &print_request_outcome($r,$lonhost,$dom,\@codetitles, - \@code_order,$instcredits); + my ($storeresult,$result,$customized) = &print_request_outcome($r,$lonhost,$dom,\@codetitles, + \@code_order,$instcredits); $r->print($result); if (($storeresult eq 'ok') || ($storeresult eq 'created')) { if ($storeresult eq 'ok') { @@ -1578,10 +1584,14 @@ sub print_request_form { '<a href="/adm/requestcourse">'.&mt('Make another request').'</a></p>'); } if (&Apache::loncoursequeueadmin::author_prompt()) { - &print_author_prompt($r,$env{'form.action'},$env{'form.cnum'},$env{'form.showdom'}, - $env{'form.crstype'},$storeresult); + unless ($customized) { + &print_author_prompt($r,$env{'form.action'},$env{'form.cnum'},$env{'form.showdom'}, + $env{'form.crstype'},$storeresult); + } } elsif ($storeresult eq 'created') { - $r->print('<p><a href="/adm/requestcourse">'.&mt('Make another request').'</a></p>'); + unless ($customized) { + $r->print('<p><a href="/adm/requestcourse">'.&mt('Make another request').'</a></p>'); + } } } } elsif ($state eq 'reqauthor') { @@ -2415,8 +2425,9 @@ ENDJS } sub viewcancel_javascript { - my $alert = &mt('Are you sure you want to cancel this request?').'\\n'. + my $alert = &mt('Are you sure you want to cancel this request?')."\n". &mt('Your request will be removed.'); + &js_escape(\$alert); return << "ENDJS"; function nextPage(formname,nextstate) { if (confirm('$alert')) { @@ -2788,6 +2799,7 @@ sub print_review { my $enrollrow_title = &mt('Default Access Dates').'<br />'. '('.&Apache::lonnet::plaintext('st',$category).')'; + my $instcode; if ($env{'form.crstype'} eq 'official') { if ((ref($codetitles) eq 'ARRAY') && (ref($cat_titles) eq 'HASH')) { foreach my $title (@{$codetitles}) { @@ -2803,6 +2815,11 @@ sub print_review { } } } + if (ref($code_order) eq 'ARRAY') { + foreach my $item (@{$code_order}) { + $instcode .= $env{'form.instcode_'.$item}; + } + } $inst_headers .= '<th>'.&mt('Credits').'</th>'; if ($instcredits) { $inst_values .= '<td>'.$instcredits.'</td>'; @@ -2890,7 +2907,7 @@ sub print_review { ($env{'form.clonedom'} =~ /^$match_domain$/)) { my $canclone = &Apache::loncoursequeueadmin::can_clone_course($uname, $udom,$env{'form.clonecrs'},$env{'form.clonedom'}, - $env{'form.crstype'}); + $env{'form.crstype'},$dom,$instcode); if ($canclone) { my %courseenv = &Apache::lonnet::userenvironment($env{'form.clonedom'}, $env{'form.clonecrs'},('description','internal.coursecode')); @@ -3052,19 +3069,20 @@ sub dates_from_form { sub courseinfo_form { my ($dom,$formname,$crstype,$next,$description) = @_; - my %lt = &Apache::lonlocal::texthash( + my %js_lt = &Apache::lonlocal::texthash( official => 'You must provide a (brief) course description.', community => 'You must provide a (brief) community description.' ); - $lt{'unofficial'} = $lt{'official'}; - $lt{'textbook'} = $lt{'official'}; + &js_escape(\%js_lt); + $js_lt{'unofficial'} = $js_lt{'official'}; + $js_lt{'textbook'} = $js_lt{'official'}; my $js_validate = <<"ENDJS"; <script type="text/javascript"> // <![CDATA[' function validateForm() { if ((document.$formname.cdescr.value == "") || (document.$formname.cdescr.value == "undefined")) { - alert('$lt{$crstype}'); + alert('$js_lt{$crstype}'); return; } nextPage(document.$formname,'$next'); @@ -3588,7 +3606,7 @@ sub print_request_outcome { my $canclone = &Apache::loncoursequeueadmin::can_clone_course($env{'user.name'}, $env{'user.domain'},$env{'form.clonecrs'},$env{'form.clonedom'}, - $crstype); + $crstype,$dom,$instcode); if ($canclone) { $clonecrs = $env{'form.clonecrs'}; $clonedom = $env{'form.clonedom'}; @@ -3622,15 +3640,15 @@ sub print_request_outcome { accessend => $accessend, personnel => \%personnel, }; - my ($result,$output) = &process_request($r,$lonhost,$dom,$cnum,$crstype,$now,$details,$instcode, - $req_notifylist,\@instsections,\%domconfig); - return ($result,$output); + my ($result,$output,$customized) = &process_request($r,$lonhost,$dom,$cnum,$crstype,$now,$details, + $instcode,$req_notifylist,\@instsections,\%domconfig); + return ($result,$output,$customized); } sub process_request { my ($r,$lonhost,$dom,$cnum,$crstype,$now,$details,$instcode,$req_notifylist,$instsections, $domconfig) = @_; - my (@inststatuses,$storeresult,$creationresult,$output); + my (@inststatuses,$storeresult,$creationresult,$output,$customized); my $val = &Apache::loncoursequeueadmin::get_processtype('course',$env{'user.name'}, $env{'user.domain'},$env{'user.adv'}, @@ -3649,7 +3667,7 @@ sub process_request { } $storeresult = 'notpermitted'; } else { - my ($disposition,$message,$reqstatus,$coursedesc); + my ($disposition,$message,$reqstatus,$coursedesc,%customvalidation); my %reqhash = ( reqtime => $now, crstype => $crstype, @@ -3669,7 +3687,12 @@ sub process_request { $disposition = &check_autolimit($env{'user.name'},$env{'user.domain'}, $dom,$crstype,$limit,\$message); } elsif ($val eq 'validate') { - my ($inststatuslist,$validationchk,$validation,%custominfo); + my ($inststatuslist,$validationchk,$validation); + if (ref($details) eq 'HASH') { + if ($details->{'clonecrs'}) { + $customvalidation{'_LC_clonefrom'} = $details->{'clonedom'}.'_'.$details->{'clonecrs'}; + } + } if (@inststatuses > 0) { $inststatuslist = join(',',@inststatuses); } @@ -3679,27 +3702,18 @@ sub process_request { $instseclist = join(',',@{$instsections}); } } +# +# Retrieve any custom form information used for validation +# my $preprocess = &Apache::lonnet::auto_crsreq_update($dom,$cnum,$crstype,'prevalidate',$env{'user.name'}, $env{'user.domain'},$fullname,$coursedesc); if (ref($preprocess) eq 'HASH') { - if (ref($preprocess->{'formitems'}) eq 'HASH') { - foreach my $key (keys(%{$preprocess->{'formitems'}})) { - if ($preprocess->{'formitems'}->{$key} eq 'multiple') { - if (exists($env{'form.'.$key})) { - @{$custominfo{$key}} = &Apache::loncommon::get_env_multiple($env{'form.'.$key}); - } - } else { - if (exists($env{'form.'.$key})) { - $custominfo{$key} = $env{'form.'.$key}; - } - } - } - } + &custom_formitems($preprocess,\%customvalidation); } $validationchk = &Apache::lonnet::auto_courserequest_validation($dom, $env{'user.name'}.':'.$env{'user.domain'},$crstype, - $inststatuslist,$instcode,$instseclist,\%custominfo); + $inststatuslist,$instcode,$instseclist,\%customvalidation); if ($validationchk =~ /:/) { ($validation,$message) = split(':',$validationchk); } else { @@ -3719,21 +3733,15 @@ sub process_request { my ($modified,$queued,$coursedesc,$token,%customitems); unless ($disposition eq 'rejected') { my $inprocess = &Apache::lonnet::auto_crsreq_update($dom,$cnum,$crstype,'process',$env{'user.name'}, - $env{'user.domain'},$fullname,$coursedesc); + $env{'user.domain'},$fullname,$coursedesc,undef, + undef,undef,\%customvalidation); +# +# Retrieve any custom form information submitted with review page and include in request details. +# if (ref($inprocess) eq 'HASH') { - if (ref($inprocess->{'formitems'}) eq 'HASH') { - foreach my $key (keys(%{$inprocess->{'formitems'}})) { - if ($inprocess->{'formitems'}->{$key} eq 'multiple') { - if (exists($env{'form.'.$key})) { - @{$customitems{$key}} = &Apache::loncommon::get_env_multiple($env{'form.'.$key}); - } - } else { - if (exists($env{'form.'.$key})) { - $customitems{$key} = $env{'form.'.$key}; - $reqhash{'custom'}{$key} = $customitems{$key}; - } - } - } + &custom_formitems($inprocess,\%customitems); + foreach my $key (keys(%customitems)) { + $reqhash{'custom'}{$key} = $customitems{$key}; } } } @@ -3762,10 +3770,29 @@ sub process_request { &mt('Your request is being processed; this page will update when processing is complete.'). '</div>'); $r->rflush(); + if (ref($details) eq 'HASH') { + if ($details->{'clonecrs'}) { + $customitems{'_LC_clonefrom'} = $details->{'clonedom'}.'_'.$details->{'clonecrs'}; + } + } + $customitems{'_LC_ownerfullname'} = &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'},'first'); + my $owneremail; + my %emails = &Apache::loncommon::getemails(); + foreach my $email ('permanentemail','critnotification','notification') { + $owneremail = $emails{$email}; + last if ($owneremail ne ''); + } + if ($owneremail ne '') { + $customitems{'_LC_owneremail'} = $owneremail; + } + $customitems{'_LC_coursedomainname'} = &Apache::lonnet::domain($dom,'description'); my ($result,$postprocess) = &Apache::loncoursequeueadmin::course_creation($dom,$cnum, 'autocreate',$details,\$logmsg,\$newusermsg,\$addresult, \$enrollcount,\$response,\$keysmsg,\%domdefs,\%longroles, \$code,\%customitems); + if (ref($postprocess) eq 'HASH') { + $customized = $postprocess->{'createdcustomized'}; + } if ($result eq 'created') { $disposition = 'created'; $reqstatus = 'created'; @@ -3792,7 +3819,10 @@ sub process_request { } } } - $output .= '<br />'.$role_result.'</p>'; + unless ($customized) { + $output .= '<br />'.$role_result; + } + $output .= '</p>'; $creationresult = 'created'; } else { $output = '<span class="LC_error">'; @@ -3897,6 +3927,7 @@ sub process_request { if ((ref($postprocess) eq 'HASH') && ((ref($postprocess->{'queuedmsg'}) eq 'HASH') || ($postprocess->{'queuedweb'}))) { ¬ification_information($disposition,undef,$dom,$cnum,$now,undef,$postprocess); + $customized = $postprocess->{'createdcustomized'}; } } elsif ($disposition eq 'pending') { my $pendingform; @@ -3909,6 +3940,9 @@ sub process_request { } else { $output .= ¬ification_information($disposition,undef,$dom,$cnum,$now,undef,$postprocess); } + if (ref($postprocess) eq 'HASH') { + $customized = $postprocess->{'createdcustomized'}; + } } } if ($validationerror ne '') { @@ -3919,9 +3953,34 @@ sub process_request { } } if ($creationresult ne '') { - return ($creationresult,$output); + return ($creationresult,$output,$customized); } else { - return ($storeresult,$output); + return ($storeresult,$output,$customized); + } +} + +sub custom_formitems { + my ($preprocess,$customhash) = @_; + return unless ((ref($preprocess) eq 'HASH') && (ref($customhash) eq 'HASH')); + if (ref($preprocess->{'formitems'}) eq 'HASH') { + foreach my $key (keys(%{$preprocess->{'formitems'}})) { + if ($preprocess->{'formitems'}->{$key} eq 'multiple') { + if (exists($env{'form.'.$key})) { + my @items = &Apache::loncommon::get_env_multiple($env{'form.'.$key}); + foreach my $item (@items) { + $item =~ s/(`)/'/g; + $item =~ s/\$/\(\$\)/g; + push(@{$customhash->{$key}},$item); + } + } + } else { + if (exists($env{'form.'.$key})) { + $customhash->{$key} = $env{'form.'.$key}; + $customhash->{$key} =~ s/(`)/'/g; + $customhash->{$key} =~ s/\$/\(\$\)/g; + } + } + } } } @@ -4452,7 +4511,7 @@ sub print_textbook_form { my ($clonedom,$clonecrs) = split(/_/,$item); if (ref($prefab{$type}{$item}) eq 'HASH') { if (&Apache::loncoursequeueadmin::can_clone_course($env{'user.name'}, - $env{'user.domain'},$clonecrs,$clonedom,$crstype)) { + $env{'user.domain'},$clonecrs,$clonedom,$crstype,$dom)) { my $num = $prefab{$type}{$item}{'order'}; $ordered{$type}{$num} = $item; @@ -4475,16 +4534,19 @@ sub print_textbook_form { } # -# Retrieve information about courses owned by user, or in which user has an active or future -# Course Coordinator role +# Retrieve information about courses owned by user, or in which user has an active +# Course Coordinator role # my $numcurrent; my %cloneable = &Apache::lonnet::courseiddump($dom,'.',1,'.',$env{'user.name'}.':'.$env{'user.domain'}, - undef,undef,undef,'Course'); + '.',undef,undef,'Course'); my %ccroles = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles', - ['active','future'],['cc']); + ['active'],['cc']); + + my $cc_clone = ''; foreach my $role (keys(%ccroles)) { my ($cnum,$cdom,$rest) = split(/:/,$role,3); + $cc_clone .= $cdom.':'.$cnum.'&'; unless (exists($cloneable{$cdom.'_'.$cnum})) { my %courseinfo = &Apache::lonnet::coursedescription($cdom.'_'.$cnum,{'one_time' => 1}); $cloneable{$cdom.'_'.$cnum} = \%courseinfo; @@ -4493,9 +4555,59 @@ sub print_textbook_form { my $numcurrent = scalar(keys(%cloneable)); - my $jscript = &textbook_request_javascript(\%numprefab,$numcurrent); +# +# Retrieve information about courses from user's domain which user can clone, but which not owned +# or cloneable based on Course Coordinator role. +# + my ($numdomcourses,%domcloneable); + my %allcloneable = &Apache::lonnet::courseiddump($dom,'.',1,'.','.','.',undef,undef,'Course', + undef,undef,undef,undef,undef, + $env{'user.name'}.':'.$env{'user.domain'}, + $cc_clone,1); + foreach my $cid (keys(%allcloneable)) { + unless (exists($cloneable{$cid})) { + $domcloneable{$cid} = $allcloneable{$cid}; + } + } + $numdomcourses = scalar(keys(%domcloneable)); + + my $fullname = &Apache::loncommon::plainname($env{'user.name'}, + $env{'user.domain'}); + +# +# Retrieve any custom form information prior to rendering page +# + + my $initprocess = &Apache::lonnet::auto_crsreq_update($dom,undef,$crstype,'initializereview',$env{'user.name'}, + $env{'user.domain'},$fullname); + my %custominit; + if (ref($initprocess) eq 'HASH') { + &custom_formitems($initprocess,\%custominit); + } + +# +# Retrieve any custom onload actions or javascript used for page before rendering +# + + my ($customonload,$customjs,$customvalidationjs); + my $inprocess = &Apache::lonnet::auto_crsreq_update($dom,undef,$crstype,'prereview',$env{'user.name'}, + $env{'user.domain'},$fullname,undef,undef, + undef,undef,\%custominit); + if (ref($inprocess) eq 'HASH') { + $customonload = $inprocess->{'onload'}; + $customjs = $inprocess->{'javascript'}; + $customvalidationjs = $inprocess->{'validationjs'}; + } + + my $postprocess = &Apache::lonnet::auto_crsreq_update($dom,undef,$crstype,'review', + $env{'user.name'}, + $env{'user.domain'},$fullname,undef,undef, + undef,undef,\%custominit); + + my $jscript = &textbook_request_javascript(\%numprefab,$numcurrent,$numdomcourses,$customvalidationjs); + $jscript .= $customjs; my %loaditems; - $loaditems{'onload'} = 'javascript:uncheckAllRadio();'; + $loaditems{'onload'} = 'javascript:uncheckAllRadio();'.$customonload; $r->print(&header('Course Request',$jscript,\%loaditems)); if (ref($can_request) eq 'HASH') { @@ -4540,7 +4652,7 @@ sub print_textbook_form { # # Content source selection, if more than one available # - if (keys(%cloneable) || keys(%ordered)) { + if (keys(%cloneable) || keys(%ordered) || keys(%domcloneable)) { $r->print('<div>'. '<fieldset><legend>'.&mt('Course Content').'</legend>'); if (keys(%ordered)) { @@ -4560,6 +4672,11 @@ sub print_textbook_form { '<input type="radio" name="cloning" value="existing" onclick="javascript:cloneChoice();" />'. &mt('Copy one of your courses').'</label></span>'.(' 'x2).' '); } + if (keys(%domcloneable)) { + $r->print('<span class="LC_nobreak"><label>'. + '<input type="radio" name="cloning" value="colleague" onclick="javascript:cloneChoice();" />'. + &mt("Copy a colleague's course").'</label></span>'.(' 'x2).' '); + } $r->print('<span class="LC_nobreak"><label>'. '<input type="radio" name="cloning" value="none" checked="checked" onclick="javascript:cloneChoice();" />'. &mt('Empty course shell').'</label></span>'); @@ -4621,90 +4738,39 @@ sub print_textbook_form { # # Table of user's current courses (owner and/or course coordinator) # + my %lt = &clone_text(); if (keys(%cloneable)) { - my %lt = &clone_text(); $r->print('<div id="showexisting" style="display:none">'. - &Apache::loncommon::start_data_table(). - &Apache::loncommon::start_data_table_header_row(). - '<th>'.&mt('Title').'</th>'. - '<th>'.&mt('Owner/co-owner(s)').'</th>'. - &Apache::loncommon::end_data_table_header_row()); - my %allownernames; - my %sortbytitle; - foreach my $cid (sort(keys(%cloneable))) { - if (ref($cloneable{$cid}) eq 'HASH') { - my $cdesc = $cloneable{$cid}{'description'}; - $cdesc =~ s/`/'/g; - if ($cdesc ne '') { - push(@{$sortbytitle{$cdesc}},$cid); - } - } - } - foreach my $title (sort(keys(%sortbytitle))) { - if (ref($sortbytitle{$title}) eq 'ARRAY') { - foreach my $cid (sort(@{$sortbytitle{$title}})) { - my $cleantitle=&HTML::Entities::encode($title,'<>&"'); - $cleantitle=~s/'/\\'/g; - $cleantitle =~ s/^\s+//; - my ($namestr,@owners,%ownernames); - my $singleowner = $cloneable{$cid}{'internal.courseowner'}; - push(@owners,$singleowner); - if ($cloneable{$cid}{'co-owners'} ne '') { - foreach my $item (split(/,/,$cloneable{$cid}{'internal.co-owners'})) { - push(@owners,$item); - } - } - foreach my $owner (@owners) { - my ($ownername,$ownerdom); - if ($owner =~ /:/) { - ($ownername,$ownerdom) = split(/:/,$owner); - } else { - $ownername = $owner; - if ($owner ne '') { - $ownerdom = $dom; - } - } - if ($ownername ne '' && $ownerdom ne '') { - if (exists($allownernames{$ownername.':'.$ownerdom})) { - $ownernames{$ownername.':'.$ownerdom} = $allownernames{$ownername.':'.$ownerdom}; - } else { - my %namehash=&Apache::loncommon::getnames($ownername,$ownerdom); - $ownernames{$ownername.':'.$ownerdom} = \%namehash; - $allownernames{$ownername.':'.$ownerdom} = $ownernames{$ownername.':'.$ownerdom}; - } - } - } - my @lastnames; - foreach my $owner (keys(%ownernames)) { - if (ref($ownernames{$owner}) eq 'HASH') { - push(@lastnames,$ownernames{$owner}{'lastname'}); - } - } - if (@lastnames) { - $namestr = join(', ',sort(@lastnames)); - } - $r->print(&Apache::loncommon::start_data_table_row(). - '<td><label><input type="radio" name="owned" value="'.$cid.'" />'. - ' '.$cleantitle.'</label></td>'. - '<td>'.$namestr.'</td>'. - &Apache::loncommon::end_data_table_row()); - } - } - } - $r->print(&Apache::loncommon::end_data_table(). - '<p><input type="radio" name="datemode" value="delete" /> '.$lt{'ncd'}. - '</label><br /><label>'. - '<input type="radio" name="datemode" value="preserve" /> '.$lt{'prd'}. - '</label><br /><label>'. - '<input type="radio" name="datemode" value="shift" checked="checked" /> '. - $lt{'shd'}.'</label>'. - '<input type="text" size="5" name="dateshift" value="365" />'. - '</div>'); + &clone_selection_table($dom,'owned',\%cloneable). + '<p><input type="radio" name="datemode" value="delete" /> '.$lt{'ncd'}. + '</label><br /><label>'. + '<input type="radio" name="datemode" value="preserve" /> '.$lt{'prd'}. + '</label><br /><label>'. + '<input type="radio" name="datemode" value="shift" checked="checked" /> '. + $lt{'shd'}.'</label>'. + '<input type="text" size="5" name="dateshift" value="365" />'. + '</div>'); } # +# Table of other cloneable courses from user's domain (exclude own courses) +# + if (keys(%domcloneable)) { + $r->print('<div id="showcolleague" style="display:none">'. + &clone_selection_table($dom,'colleague',\%domcloneable). + '<p><input type="radio" name="datemode" value="delete" /> '.$lt{'ncd'}. + '</label><br /><label>'. + '<input type="radio" name="datemode" value="preserve" /> '.$lt{'prd'}. + '</label><br /><label>'. + '<input type="radio" name="datemode" value="shift" checked="checked" /> '. + $lt{'shd'}.'</label>'. + '<input type="text" size="5" name="dateshift" value="365" />'. + '</div>'); + } + +# # End of content selector # - if (keys(%cloneable) || keys(%ordered)) { + if (keys(%cloneable) || keys(%domcloneable) || keys(%ordered)) { $r->print('</fieldset></div>'); } @@ -4735,11 +4801,6 @@ sub print_textbook_form { # # Display any custom fields for this course type # - my $fullname = &Apache::loncommon::plainname($env{'user.name'}, - $env{'user.domain'}); - my $postprocess = &Apache::lonnet::auto_crsreq_update($dom,undef,$crstype,'review', - $env{'user.name'}, - $env{'user.domain'},$fullname); if (ref($postprocess) eq 'HASH') { if ($postprocess->{'reviewweb'}) { $r->print($postprocess->{'reviewweb'}); @@ -4762,6 +4823,84 @@ sub print_textbook_form { return; } +sub clone_selection_table { + my ($dom,$name,$cloneableref) = @_; + return unless ((ref($cloneableref) eq 'HASH') && (($name eq 'owned') || ($name eq 'colleague'))); + my %allownernames; + my %sortbytitle; + my $output; + foreach my $cid (sort(keys(%{$cloneableref}))) { + if (ref($cloneableref->{$cid}) eq 'HASH') { + my $cdesc = $cloneableref->{$cid}{'description'}; + $cdesc =~ s/`/'/g; + if ($cdesc ne '') { + push(@{$sortbytitle{$cdesc}},$cid); + } + } + } + foreach my $title (sort(keys(%sortbytitle))) { + if (ref($sortbytitle{$title}) eq 'ARRAY') { + foreach my $cid (sort(@{$sortbytitle{$title}})) { + my $cleantitle=&HTML::Entities::encode($title,'<>&"'); + $cleantitle=~s/'/\\'/g; + $cleantitle =~ s/^\s+//; + my ($namestr,@owners,%ownernames); + my $singleowner = $cloneableref->{$cid}{'internal.courseowner'}; + push(@owners,$singleowner); + if ($cloneableref->{$cid}{'co-owners'} ne '') { + foreach my $item (split(/,/,$cloneableref->{$cid}{'internal.co-owners'})) { + push(@owners,$item); + } + } + foreach my $owner (@owners) { + my ($ownername,$ownerdom); + if ($owner =~ /:/) { + ($ownername,$ownerdom) = split(/:/,$owner); + } else { + $ownername = $owner; + if ($owner ne '') { + $ownerdom = $dom; + } + } + if ($ownername ne '' && $ownerdom ne '') { + if (exists($allownernames{$ownername.':'.$ownerdom})) { + $ownernames{$ownername.':'.$ownerdom} = $allownernames{$ownername.':'.$ownerdom}; + } else { + my %namehash=&Apache::loncommon::getnames($ownername,$ownerdom); + $ownernames{$ownername.':'.$ownerdom} = \%namehash; + $allownernames{$ownername.':'.$ownerdom} = $ownernames{$ownername.':'.$ownerdom}; + } + } + } + my @lastnames; + foreach my $owner (keys(%ownernames)) { + if (ref($ownernames{$owner}) eq 'HASH') { + push(@lastnames,$ownernames{$owner}{'lastname'}); + } + } + if (@lastnames) { + $namestr = join(', ',sort(@lastnames)); + } + $output .= &Apache::loncommon::start_data_table_row(). + '<td><label><input type="radio" name="'.$name.'" value="'.$cid.'" />'. + ' '.$cleantitle.'</label></td>'. + '<td>'.$namestr.'</td>'. + &Apache::loncommon::end_data_table_row(); + } + } + } + if ($output) { + return &Apache::loncommon::start_data_table(). + &Apache::loncommon::start_data_table_header_row(). + '<th>'.&mt('Title').'</th>'. + '<th>'.&mt('Owner/co-owner(s)').'</th>'. + &Apache::loncommon::end_data_table_header_row(). + $output. + &Apache::loncommon::end_data_table(); + } + return; +} + sub process_textbook_request { my ($r,$dom,$action,$domdefs,$domconfig,$can_request) = @_; my ($uniquecode,$req_notifylist); @@ -4787,6 +4926,8 @@ sub process_textbook_request { $clonefrom = $env{'form.template'}; } elsif ($reqtype eq 'existing') { $clonefrom = $env{'form.owned'}; + } elsif ($reqtype eq 'colleague') { + $clonefrom = $env{'form.colleague'}; } my ($accessstart,$accessend) = &dates_from_form('accessstart','accessend'); if ($clonefrom) { @@ -4794,7 +4935,7 @@ sub process_textbook_request { if (&Apache::lonnet::homeserver($clonecrs,$clonedom) ne 'no_host') { my $canclone = &Apache::loncoursequeueadmin::can_clone_course($env{'user.name'}, - $env{'user.domain'},$clonecrs,$clonedom,$crstype); + $env{'user.domain'},$clonecrs,$clonedom,$crstype,$dom); unless ($canclone) { undef($clonecrs); undef($clonedom); @@ -4848,36 +4989,42 @@ sub process_textbook_request { } my $lonhost = $r->dir_config('lonHostID'); $r->rflush(); - my ($result,$output) = &process_request($r,$lonhost,$dom,$cnum,$crstype,$now,$details,'', - $req_notifylist,[],$domconfig); + my ($result,$output,$customized) = &process_request($r,$lonhost,$dom,$cnum,$crstype,$now,$details, + '',$req_notifylist,[],$domconfig); $r->print($output); if (&Apache::loncoursequeueadmin::author_prompt()) { - &print_author_prompt($r,$action,$cnum,$dom,$crstype,$result); + unless ($customized) { + &print_author_prompt($r,$action,$cnum,$dom,$crstype,$result); + } } elsif ($result eq 'created') { - $r->print('<p><a href="/adm/requestcourse">'.&mt('Create another course').'</a></p>'); + unless ($customized) { + $r->print('<p><a href="/adm/requestcourse">'.&mt('Create another course').'</a></p>'); + } } &endContentScreen($r); $r->print(&Apache::loncommon::end_page()); } sub textbook_request_javascript { - my ($numprefab,$numcurrent) = @_; + my ($numprefab,$numcurrent,$numcolleague,$customvalidationjs) = @_; return unless (ref($numprefab) eq 'HASH'); - return if (!$numprefab->{'textbooks'} && !$numprefab->{'templates'} && !$numcurrent); - my %lt = &Apache::lonlocal::texthash( - choose => 'Please select a content option.', - textbook => 'Please select a textbook, or choose a different option.', - template => 'Please select a template, or choose a different option.', - existing => 'Please select one of your existing courses to copy, or choose a different option.', - title => 'Please enter a course title.', + return if (!$numprefab->{'textbooks'} && !$numprefab->{'templates'} && !$numcurrent && !$numcolleague); + my %js_lt = &Apache::lonlocal::texthash( + choose => 'Please select a content option.', + textbook => 'Please select a textbook, or choose a different option.', + template => 'Please select a template, or choose a different option.', + existing => 'Please select one of your existing courses to copy, or choose a different option.', + colleague => "Please select a colleague's course to copy, or choose a different option.", + title => 'Please enter a course title.', ); + &js_escape(\%js_lt); return <<"ENDSCRIPT"; function cloneChoice() { if (document.requestcourse.cloning) { var radioLength = document.requestcourse.cloning.length; if (radioLength == undefined) { var val = document.requestcourse.cloning.value; - if ((val == 'textbook') || (val == 'template') || (val == 'existing')) { + if ((val == 'textbook') || (val == 'template') || (val == 'existing') || (val == 'colleague')) { var elem = document.getElementById('show'+val); if (document.requestcourse.cloning.checked) { elem.style.display = 'block'; @@ -4889,7 +5036,7 @@ function cloneChoice() { } else { for (var i=0; i<radioLength; i++) { var val = document.requestcourse.cloning[i].value; - if ((val == 'textbook') || (val == 'template') || (val == 'existing')) { + if ((val == 'textbook') || (val == 'template') || (val == 'existing') || (val == 'colleague')) { var elem = document.getElementById('show'+val); if (document.requestcourse.cloning[i].checked) { elem.style.display = 'block'; @@ -4903,6 +5050,9 @@ function cloneChoice() { if (val == 'existing') { uncheckRadio('owned'); } + if (val == 'colleague') { + uncheckRadio('colleague'); + } elem.style.display = 'none'; } } @@ -4930,15 +5080,19 @@ function uncheckAllRadio() { var numbook = $numprefab->{'textbooks'}; var numtemplate = $numprefab->{'templates'}; var numcurrent = $numcurrent; + var numcolleague = $numcolleague; if (numbook > 0) { uncheckRadio('textbook'); } - if (nutemplate > 0) { + if (numtemplate > 0) { uncheckRadio('template'); - }m + } if (numcurrent > 0) { uncheckRadio('existing'); } + if (numcolleague > 0) { + uncheckRadio('colleague'); + } return; } @@ -4948,7 +5102,7 @@ function validTextbookReq() { var radioLength = document.requestcourse.cloning.length; if (radioLength == undefined) { if (document.requestcourse.cloning.checked == false) { - alert("$lt{'choose'}"); + alert("$js_lt{'choose'}"); return false; } else { cloneChoice = document.requestcourse.cloning.value; @@ -4961,12 +5115,12 @@ function validTextbookReq() { } } if (cloneChoice == 0) { - alert("$lt{'choose'}"); + alert("$js_lt{'choose'}"); return false; } } var group; - if ((cloneChoice == 'textbook') || (cloneChoice == 'template') || (cloneChoice == 'existing')) { + if ((cloneChoice == 'textbook') || (cloneChoice == 'template') || (cloneChoice == 'existing') || (cloneChoice == 'colleague')) { var group; if (cloneChoice == 'textbook') { group = document.getElementsByName('book'); @@ -4974,7 +5128,11 @@ function validTextbookReq() { if (cloneChoice == 'template') { group = document.getElementsByName('template'); } else { - group = document.getElementsByName('owned'); + if (cloneChoice == 'existing') { + group = document.getElementsByName('owned'); + } else { + group = document.getElementsByName('colleague'); + } } } var groupLength = group.length; @@ -4993,12 +5151,16 @@ function validTextbookReq() { } if (chosen == 0) { if (cloneChoice == 'textbook') { - alert("$lt{'textbook'}"); + alert("$js_lt{'textbook'}"); } else { if (cloneChoice == 'template') { - alert("$lt{'template'}"); + alert("$js_lt{'template'}"); } else { - alert("$lt{'existing'}"); + if (cloneChoice == 'existing') { + alert("$js_lt{'existing'}"); + } else { + alert("js_$lt{'colleague'}"); + } } } return false; @@ -5006,9 +5168,10 @@ function validTextbookReq() { } } if (document.requestcourse.cdescr.value == '') { - alert("$lt{'title'}"); + alert("$js_lt{'title'}"); return false; } + $customvalidationjs return true; }