[LON-CAPA-cvs] cvs: loncom(version_2_11_X) /interface domainprefs.pm

raeburn raeburn at source.lon-capa.org
Fri Dec 27 11:40:08 EST 2013


raeburn		Fri Dec 27 16:40:08 2013 EDT

  Modified files:              (Branch: version_2_11_X)
    /loncom/interface	domainprefs.pm 
  Log:
  - For 2.11
    - Backport 1.216, 1.217, 1.218
  
  
-------------- next part --------------
Index: loncom/interface/domainprefs.pm
diff -u loncom/interface/domainprefs.pm:1.160.6.29 loncom/interface/domainprefs.pm:1.160.6.30
--- loncom/interface/domainprefs.pm:1.160.6.29	Mon Dec 23 14:34:35 2013
+++ loncom/interface/domainprefs.pm	Fri Dec 27 16:40:08 2013
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set domain-wide configuration settings
 #
-# $Id: domainprefs.pm,v 1.160.6.29 2013/12/23 14:34:35 raeburn Exp $
+# $Id: domainprefs.pm,v 1.160.6.30 2013/12/27 16:40:08 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -103,8 +103,8 @@
 
 In the case of course requests, radio buttons are displayed for each institutional
 affiliate type (and also default, and _LC_adv) for each of the course types 
-(official, unofficial and community).  In each case the radio buttons allow the 
-selection of one of four values:
+(official, unofficial, community, and textbook).  In each case the radio buttons 
+allow the selection of one of four values:
 
 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
 which have the following effects:
@@ -327,7 +327,9 @@
                   header => [{col1 => 'User affiliation',
                               col2 => 'Availability/Processing of requests',},
                              {col1 => 'Setting',
-                              col2 => 'Value'}],
+                              col2 => 'Value'},
+                             {col1 => 'Available textbooks',
+                              col2 => ''}],
                  },
         'requestauthor' =>
                  {text => 'Request authoring space',
@@ -418,6 +420,16 @@
                    &common_domprefs_js().
                    &Apache::loncommon::javascript_array_indexof();
         }
+        if (grep(/^requestcourses$/, at actions)) {
+            my $javascript_validations;
+            my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'}); 
+            $js .= <<END;
+<script type="text/javascript">
+$javascript_validations
+</script>
+$coursebrowserjs
+END
+        }
         &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
     } else {
 # check if domconfig user exists for the domain.
@@ -499,7 +511,7 @@
         $output = &modify_rolecolors($r,$dom,$confname,$roles,
                                      $lastactref,%domconfig);
     } elsif ($action eq 'quotas') {
-        $output = &modify_quotas($dom,$action,$lastactref,%domconfig);
+        $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
     } elsif ($action eq 'autoenroll') {
         $output = &modify_autoenroll($dom,$lastactref,%domconfig);
     } elsif ($action eq 'autoupdate') {
@@ -523,9 +535,9 @@
     } elsif ($action eq 'serverstatuses') {
         $output = &modify_serverstatuses($dom,%domconfig);
     } elsif ($action eq 'requestcourses') {
-        $output = &modify_quotas($dom,$action,$lastactref,%domconfig);
+        $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
     } elsif ($action eq 'requestauthor') {
-        $output = &modify_quotas($dom,$action,$lastactref,%domconfig);
+        $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
     } elsif ($action eq 'coursedefaults') {
         $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
     } elsif ($action eq 'usersessions') {
@@ -647,7 +659,7 @@
             <table class="LC_nested">
              <tr class="LC_info_row">
               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
-              <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>      </tr>'.
+              <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
                        &print_usermodification('bottom',$dom,$settings,\$rowtotal);
             $rowtotal ++;
         } elsif ($action eq 'coursecategories') {
@@ -663,14 +675,25 @@
             <table class="LC_nested">
              <tr class="LC_info_row">
               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
-              <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>      </tr>'.
+              <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
                        &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
                 $rowtotal ++;
             } else {
                 $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
             }
         } elsif ($action eq 'requestcourses') {
-            $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
+            $output .= &print_requestmail($dom,$action,$settings,\$rowtotal).
+                       &print_studentcode($settings,\$rowtotal).'
+           </table>
+          </td>
+         </tr>
+         <tr>
+           <td>
+            <table class="LC_nested">
+             <tr class="LC_info_row">
+              <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
+              <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
+                       &print_textbookcourses($dom,$settings,\$rowtotal);
         } elsif ($action eq 'requestauthor') {
             $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
         } elsif ($action eq 'usersessions') {
@@ -1530,7 +1553,7 @@
     my $typecount = 0;
     my ($css_class,%titles);
     if ($context eq 'requestcourses') {
-        @usertools = ('official','unofficial','community');
+        @usertools = ('official','unofficial','community','textbook');
         @options =('norequest','approval','validate','autolimit');
         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
         %titles = &courserequest_titles();
@@ -1976,6 +1999,216 @@
     return $datatable;
 }
 
+sub print_studentcode {
+    my ($settings,$rowtotal) = @_;
+    my $rownum = 0; 
+    my ($output,%current);
+    my @crstypes = ('official','unofficial','community','textbook');
+    if (ref($settings->{'uniquecode'}) eq 'HASH') {
+        foreach my $type (@crstypes) {
+            $current{$type} = $settings->{'uniquecode'}{$type};
+        }
+    }
+    $output .= '<tr>'.
+               '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
+               '<td class="LC_left_item">';
+    foreach my $type (@crstypes) {
+        my $check = ' ';
+        if ($current{$type}) {
+            $check = ' checked="checked" ';
+        }
+        $output .= '<span class="LC_nobreak"><label>'.
+                   '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
+                   &mt($type).'</label></span>'.(' 'x2).' ';
+    }
+    $output .= '</td></tr>';
+    $$rowtotal ++;
+    return $output;
+}
+
+sub print_textbookcourses {
+    my ($dom,$settings,$rowtotal) = @_;
+    my $rownum = 0;
+    my $css_class;
+    my $itemcount = 1;
+    my $maxnum = 0;
+    my $bookshash;
+    if (ref($settings) eq 'HASH') {
+        $bookshash = $settings->{'textbooks'};
+    }
+    my %ordered;
+    if (ref($bookshash) eq 'HASH') {
+        foreach my $item (keys(%{$bookshash})) {
+            if (ref($bookshash->{$item}) eq 'HASH') {
+                my $num = $bookshash->{$item}{'order'};
+                $ordered{$num} = $item;
+            }
+        }
+    }
+    my $confname = $dom.'-domainconfig';
+    my $switchserver = &check_switchserver($dom,$confname);
+    my $maxnum = scalar(keys(%ordered));
+    my $datatable = &textbookcourses_javascript(\%ordered);
+    if (keys(%ordered)) {
+        my @items = sort { $a <=> $b } keys(%ordered);
+        for (my $i=0; $i<@items; $i++) {
+            $css_class = $itemcount%2?' class="LC_odd_row"':'';
+            my $key = $ordered{$items[$i]};
+            my %coursehash=&Apache::lonnet::coursedescription($key);
+            my $coursetitle = $coursehash{'description'};
+            my ($subject,$title,$author,$image,$imgsrc,$cdom,$cnum);
+            if (ref($bookshash->{$key}) eq 'HASH') {
+                $subject = $bookshash->{$key}->{'subject'};
+                $title = $bookshash->{$key}->{'title'};
+                $author = $bookshash->{$key}->{'author'};
+                $image = $bookshash->{$key}->{'image'};
+                if ($image ne '') {
+                    my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
+                    my $imagethumb = "$path/tn-".$imagefile;
+                    $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
+                }
+            }
+            my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$key'".');"';
+            $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
+                         .'<select name="'.$key.'"'.$chgstr.'>';
+            for (my $k=0; $k<=$maxnum; $k++) {
+                my $vpos = $k+1;
+                my $selstr;
+                if ($k == $i) {
+                    $selstr = ' selected="selected" ';
+                }
+                $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
+            }
+            $datatable .= '</select>'.(' 'x2).
+                '<label><input type="checkbox" name="book_del" value="'.$key.'" />'.
+                &mt('Delete?').'</label></span></td>'.
+                '<td colspan="2">'.
+                '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="book_subject_'.$i.'" value="'.$subject.'" /></span> '.
+                (' 'x2).
+                '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="book_title_'.$i.'" value="'.$title.'" /></span> '.
+                (' 'x2).
+                '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="book_author_'.$i.'" value="'.$author.'" /></span> '.
+                (' 'x2).
+                '<span class="LC_nobreak">'.&mt('Thumbnail:');
+            if ($image) {
+                $datatable .= '<span class="LC_nobreak">'.
+                              $imgsrc.
+                              '<label><input type="checkbox" name="book_image_del"'.
+                              ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
+                              '<span class="LC_nobreak"> '.&mt('Replace:').' ';
+            }
+            if ($switchserver) {
+                $datatable .= &mt('Upload to library server: [_1]',$switchserver);
+            } else {
+                $datatable .= '<input type="file" name="book_image_'.$i.'" value="" />';
+            }
+            $datatable .= '<input type="hidden" name="book_id_'.$i.'" value="'.$key.'" /></span> '.
+                          '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
+                          $coursetitle.'</span></td></tr>'."\n";
+            $itemcount ++;
+        }
+    }
+    $css_class = $itemcount%2?' class="LC_odd_row"':'';
+    my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'addbook_pos'".');"';
+    $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
+                  '<input type="hidden" name="book_maxnum" value="'.$maxnum.'" />'."\n".
+                  '<select name="addbook_pos"'.$chgstr.'>';
+    for (my $k=0; $k<$maxnum+1; $k++) {
+        my $vpos = $k+1;
+        my $selstr;
+        if ($k == $maxnum) {
+            $selstr = ' selected="selected" ';
+        }
+        $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
+    }
+    $datatable .= '</select> '."\n".
+                  '<input type="checkbox" name="addbook" value="1" />'.&mt('Add').'</td>'."\n".
+                  '<td colspan="2">'.
+                  '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="addbook_subject" value="" /></span> '."\n".
+                  (' 'x2).
+                  '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="addbook_title" value="" /></span> '."\n".
+                  (' 'x2).
+                  '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="addbook_author" value="" /></span> '."\n".
+                  (' 'x2).
+                  '<span class="LC_nobreak">'.&mt('Image:').' ';
+    if ($switchserver) {
+        $datatable .= &mt('Upload to library server: [_1]',$switchserver);
+    } else {
+        $datatable .= '<input type="file" name="addbook_image" value="" />';
+    }
+    $datatable .= '</span>'."\n".
+                  '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
+                  &Apache::loncommon::select_dom_form($env{'request.role.domain'},'addbook_cdom').
+                  '<input type="text" size="25" name="addbook_cnum" value="" />'.
+                  &Apache::loncommon::selectcourse_link
+                      ('display','addbook_cnum','addbook_cdom',undef,undef,undef,'Course');
+                  '</span></td>'."\n".
+                  '</tr>'."\n";
+    $itemcount ++;
+    return $datatable;
+}
+
+sub textbookcourses_javascript {
+    my ($textbooks) = @_;
+    return unless(ref($textbooks) eq 'HASH');
+    my $num = scalar(keys(%{$textbooks}));
+    my @jsarray;
+    foreach my $item (sort {$a <=> $b } (keys(%{$textbooks}))) {
+        push(@jsarray,$textbooks->{$item});
+    }
+    my $jstext = '    var textbooks = Array('."'".join("','", at jsarray)."'".');'."\n";
+    return <<"ENDSCRIPT";
+<script type="text/javascript">
+// <![CDATA[
+function reorderBooks(form,item) {
+    var changedVal;
+$jstext 
+    var newpos = 'addbook_pos';
+    var current = new Array;
+    var maxh = 1 + $num;
+    var current = new Array;
+    var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
+    if (item == newpos) {
+        changedVal = newitemVal;
+    } else {
+        changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
+        current[newitemVal] = newpos;
+    }
+    for (var i=0; i<textbooks.length; i++) {
+        var elementName = textbooks[i];
+        if (elementName != item) {
+            if (form.elements[elementName]) {
+                var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
+                current[currVal] = elementName;
+            }
+        }
+    }
+    var oldVal;
+    for (var j=0; j<maxh; j++) {
+        if (current[j] == undefined) {
+            oldVal = j;
+        }
+    }
+    if (oldVal < changedVal) {
+        for (var k=oldVal+1; k<=changedVal ; k++) {
+           var elementName = current[k];
+           form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
+        }
+    } else {
+        for (var k=changedVal; k<oldVal; k++) {
+            var elementName = current[k];
+            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
+        }
+    }
+    return;
+}
+
+// ]]>
+</script>
+
+ENDSCRIPT
+}
+
 sub print_autoenroll {
     my ($dom,$settings,$rowtotal) = @_;
     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
@@ -2474,9 +2707,10 @@
                                                  \%choices,$itemcount);
     } else {
         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
-        my ($currdefresponder,$def_official_credits,$def_unofficial_credits,%curruploadquota);
+        my ($currdefresponder,$def_official_credits,$def_unofficial_credits,$def_textbook_credits,
+            %curruploadquota);
         my $currusecredits = 0;
-        my @types = ('official','unofficial','community');
+        my @types = ('official','unofficial','community','textbook');
         if (ref($settings) eq 'HASH') {
             $currdefresponder = $settings->{'anonsurvey_threshold'};
             if (ref($settings->{'uploadquota'}) eq 'HASH') {
@@ -2487,7 +2721,9 @@
             if (ref($settings->{'coursecredits'}) eq 'HASH') {
                 $def_official_credits = $settings->{'coursecredits'}->{'official'};
                 $def_unofficial_credits = $settings->{'coursecredits'}->{'unofficial'};
-                if (($def_official_credits ne '') || ($def_unofficial_credits ne '')) {
+                $def_textbook_credits = $settings->{'coursecredits'}->{'textbook'};
+                if (($def_official_credits ne '') || ($def_unofficial_credits ne '') ||
+                    ($def_textbook_credits ne '')) {
                     $currusecredits = 1;
                 }
             }
@@ -2537,6 +2773,11 @@
                          &mt('Default credits for unofficial courses [_1]',
                          '<input type="text" name="unofficial_credits" value="'.
                          $def_unofficial_credits.'" size="3" />').
+                         '</span><br />'.
+                         '<span class="LC_nobreak">'.
+                         &mt('Default credits for textbook courses [_1]',
+                         '<input type="text" name="textbook_credits" value="'.
+                         $def_textbook_credits.'" size="3" />').
                          '</span></div>'."\n";
         %defaultchecked = ('coursecredits' => 'off');
         @toggles = ('coursecredits');
@@ -3327,6 +3568,7 @@
                      official   => 'Official courses (with institutional codes)',
                      unofficial => 'Unofficial courses',
                      community  => 'Communities',
+                     textbook   => 'Textbook courses',
                  );
     return %titles;
 }
@@ -3336,6 +3578,7 @@
                                    official   => 'Official',
                                    unofficial => 'Unofficial',
                                    community  => 'Communities',
+                                   textbook   => 'Textbook',
                                    norequest  => 'Not allowed',
                                    approval   => 'Approval by Dom. Coord.',
                                    validate   => 'With validation',
@@ -5803,21 +6046,25 @@
 }
 
 sub modify_quotas {
-    my ($dom,$action,$lastactref,%domconfig) = @_;
+    my ($r,$dom,$action,$lastactref,%domconfig) = @_;
     my ($context, at usertools, at options,%validations,%titles,%confhash,%toolshash,
-        %limithash,$toolregexp,%conditions,$resulttext,%changes);
+        %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
+        $author_ok,$switchserver,$errors);
     if ($action eq 'quotas') {
         $context = 'tools'; 
     } else {
         $context = $action;
     }
     if ($context eq 'requestcourses') {
-        @usertools = ('official','unofficial','community');
+        @usertools = ('official','unofficial','community','textbook');
         @options =('norequest','approval','validate','autolimit');
         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
         %titles = &courserequest_titles();
         $toolregexp = join('|', at usertools);
         %conditions = &courserequest_conditions();
+        $confname = $dom.'-domainconfig';
+        my $servadm = $r->dir_config('lonAdmEMail');
+        ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
     } elsif ($context eq 'requestauthor') {
         @usertools = ('author');
         %titles = &authorrequest_titles();
@@ -5856,6 +6103,36 @@
         my @approvalnotify = &Apache::loncommon::get_env_multiple('form.reqapprovalnotify');
         @approvalnotify = sort(@approvalnotify);
         $confhash{'notify'}{'approval'} = join(',', at approvalnotify);
+        my @crstypes = ('official','unofficial','community','textbook');
+        my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
+        foreach my $type (@hasuniquecode) {
+            if (grep(/^\Q$type\E$/, at crstypes)) {
+                $confhash{'uniquecode'}{$type} = 1;
+            }
+        }
+        my ($newbook, at allpos);
+        if ($context eq 'requestcourses') {
+            if ($env{'form.addbook'}) {
+                if (($env{'form.addbook_cnum'} =~ /^$match_courseid$/) &&
+                    ($env{'form.addbook_cdom'} =~ /^$match_domain$/)) {
+                    if (&Apache::lonnet::homeserver($env{'form.addbook_cnum'},
+                                                    $env{'form.addbook_cdom'}) eq 'no_host') {
+                        $errors .= '<li><span class="LC_error">'.&mt('Invalid LON-CAPA course for textbook').
+                                   '</span></li>';
+                    } else {
+                        $newbook = $env{'form.addbook_cdom'}.'_'.$env{'form.addbook_cnum'};
+                        my $position = $env{'form.addbook_pos'};
+                        $position =~ s/\D+//g;
+                        if ($position ne '') {
+                            $allpos[$position] = $newbook;
+                        }
+                    }
+                } else {
+                    $errors .= '<li><span class="LC_error">'.&mt('Invalid LON-CAPA course for textbook').
+                               '</span></li>';
+                }
+            }
+        }
         if (ref($domconfig{$action}) eq 'HASH') {
             if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
                 if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
@@ -5866,10 +6143,131 @@
                     $changes{'notify'}{'approval'} = 1;
                 }
             }
+            if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
+                if (ref($confhash{'uniquecode'}) eq 'HASH') {
+                    foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
+                        unless ($confhash{'uniquecode'}{$crstype}) {
+                            $changes{'uniquecode'} = 1;
+                        }
+                    }
+                    unless ($changes{'uniquecode'}) {
+                        foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
+                            unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
+                                $changes{'uniquecode'} = 1;
+                            }
+                        }
+                    }
+               } else {
+                   $changes{'uniquecode'} = 1;
+               }
+            } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
+                $changes{'uniquecode'} = 1;
+            }
+            if ($context eq 'requestcourses') {
+                if (ref($domconfig{$action}{'textbooks'}) eq 'HASH') {
+                    my %deletions;
+                    my @todelete = &Apache::loncommon::get_env_multiple('form.book_del');
+                    if (@todelete) {
+                        map { $deletions{$_} = 1; } @todelete;
+                    }
+                    my %imgdeletions;
+                    my @todeleteimages = &Apache::loncommon::get_env_multiple('form.book_image_del');
+                    if (@todeleteimages) {
+                        map { $imgdeletions{$_} = 1; } @todeleteimages;
+                    }
+                    my $maxnum = $env{'form.book_maxnum'};
+                    for (my $i=0; $i<=$maxnum; $i++) {
+                        my $key = $env{'form.book_id_'.$i};
+                        if (ref($domconfig{$action}{'textbooks'}{$key}) eq 'HASH') {
+                            if ($deletions{$key}) {
+                                if ($domconfig{$action}{'textbooks'}{$key}{'image'}) {
+                                    #FIXME need to obsolete item in RES space
+                                }
+                                next;
+                            } else {
+                                my $newpos = $env{'form.'.$key};
+                                $newpos =~ s/\D+//g;
+                                foreach my $item ('subject','title','author') {
+                                    $confhash{'textbooks'}{$key}{$item} = $env{'form.book_'.$item.'_'.$i};
+                                    if ($domconfig{$action}{'textbooks'}{$key}{$item} ne $confhash{'textbooks'}{$key}{$item}) {
+                                        $changes{'textbooks'}{$key} = 1;
+                                    }
+                                }
+                                $allpos[$newpos] = $key;
+                            }
+                            if ($imgdeletions{$key}) {
+                                $changes{'textbooks'}{$key} = 1;
+                                #FIXME need to obsolete item in RES space
+                            } elsif ($env{'form.book_image_'.$i.'.filename'}) {
+                                my ($cdom,$cnum) = split(/_/,$key);
+                                my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,'book_image_'.$i,
+                                                                              $cdom,$cnum,$configuserok,
+                                                                              $switchserver,$author_ok);
+                                if ($imgurl) {
+                                    $confhash{'textbooks'}{$key}{'image'} = $imgurl;
+                                    $changes{'textbooks'}{$key} = 1; 
+                                }
+                                if ($error) {
+                                    &Apache::lonnet::logthis($error);
+                                    $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
+                                } 
+                            } elsif ($domconfig{$action}{'textbooks'}{$key}{'image'}) {
+                                $confhash{'textbooks'}{$key}{'image'} = 
+                                    $domconfig{$action}{'textbooks'}{$key}{'image'};
+                            }
+                        }
+                    }
+                }
+            }
         } else {
             if ($confhash{'notify'}{'approval'}) {
                 $changes{'notify'}{'approval'} = 1;
             }
+            if (ref($confhash{'uniquecode'} eq 'HASH')) {
+                $changes{'uniquecode'} = 1;
+            }
+        }
+        if ($context eq 'requestcourses') {
+            if ($newbook) {
+                $changes{'textbooks'}{$newbook} = 1;
+                foreach my $item ('subject','title','author') {
+                    $env{'form.addbook_'.$item} =~ s/(`)/'/g;
+                    if ($env{'form.addbook_'.$item}) {
+                        $confhash{'textbooks'}{$newbook}{$item} = $env{'form.addbook_'.$item};
+                    }
+                }
+                if ($env{'form.addbook_image.filename'} ne '') {
+                    my ($cdom,$cnum) = split(/_/,$newbook);
+                    my ($imageurl,$error) = 
+                        &process_textbook_image($r,$dom,$confname,'addbook_image',$cdom,$cnum,$configuserok,
+                                                $switchserver,$author_ok);
+                    if ($imageurl) {
+                        $confhash{'textbooks'}{$newbook}{'image'} = $imageurl;
+                    }
+                    if ($error) {
+                        &Apache::lonnet::logthis($error);
+                        $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
+                    }
+                }
+            }
+            if (@allpos > 0) {
+                my $idx = 0;
+                foreach my $item (@allpos) {
+                    if ($item ne '') {
+                        $confhash{'textbooks'}{$item}{'order'} = $idx;
+                        if (ref($domconfig{$action}) eq 'HASH') {
+                            if (ref($domconfig{$action}{'textbooks'}) eq 'HASH') {
+                                if (ref($domconfig{$action}{'textbooks'}{$item}) eq 'HASH') {
+                                    if ($domconfig{$action}{'textbooks'}{$item}{'order'} ne $idx) {
+                                        $changes{'textbooks'}{$item} = 1;
+                                    }
+                                }
+                            }
+                        }
+                        $idx ++;
+                    }
+                }
+            }
         }
     } else {
         $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
@@ -6011,7 +6409,9 @@
         $domdefaults{'requestauthor'} = \%confhash;
     } else {
         foreach my $key (keys(%confhash)) {
-            $domdefaults{$key} = $confhash{$key};
+            unless (($context eq 'requestcourses') && ($key eq 'textbooks')) {
+                $domdefaults{$key} = $confhash{$key};
+            }
         }
     }
 
@@ -6148,6 +6548,42 @@
                     }
                 }
             }
+            if ($action eq 'requestcourses') {
+                my @offon = ('off','on');
+                if ($changes{'uniquecode'}) {
+                    if (ref($confhash{'uniquecode'}) eq 'HASH') {
+                        my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
+                        $resulttext .= '<li>'.
+                                       &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
+                                       '</li>';
+                    } else {
+                        $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
+                                       '</li>';
+                    }
+                }
+                if (ref($changes{'textbooks'}) eq 'HASH') {
+                    $resulttext .= '<li>'.&mt('Available textbooks updated').'<ul>';
+                    foreach my $key (sort(keys(%{$changes{'textbooks'}}))) {
+                        my %coursehash = &Apache::lonnet::coursedescription($key);
+                        my $coursetitle = $coursehash{'description'};
+                        my $position = $confhash{'textbooks'}{$key}{'order'} + 1;
+                        $resulttext .= '<li>';
+                        foreach my $item ('subject','title','author') {
+                            my $name = $item.':';
+                            $name =~ s/^(\w)/\U$1/;
+                            $resulttext .= &mt($name).' '.$confhash{'textbooks'}{$key}{$item}.'<br />';
+                        }
+                        $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
+                        if ($confhash{'textbooks'}{$key}{'image'}) {
+                            $resulttext .= ' '.&mt('Image: [_1]',
+                                               '<img src="'.$confhash{'textbooks'}{$key}{'image'}.'"'.
+                                               ' alt="Textbook cover" />').'<br />';
+                        }
+                        $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
+                    }
+                    $resulttext .= '</ul></li>';
+                }
+            }
             $resulttext .= '</ul>';
             if (keys(%newenv)) {
                 &Apache::lonnet::appenv(\%newenv);
@@ -6165,9 +6601,40 @@
         $resulttext = '<span class="LC_error">'.
 	    &mt('An error occurred: [_1]',$putresult).'</span>';
     }
+    if ($errors) {
+        $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
+                       '<ul>'.$errors.'</ul></p>';
+    }
     return $resulttext;
 }
 
+sub process_textbook_image {
+    my ($r,$dom,$confname,$caller,$cdom,$cnum,$configuserok,$switchserver,$author_ok) = @_;
+    my $filename = $env{'form.'.$caller.'.filename'};
+    my ($error,$url);
+    my ($width,$height) = (50,50);
+    if ($configuserok eq 'ok') {
+        if ($switchserver) {
+            $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
+                         $switchserver);
+        } elsif ($author_ok eq 'ok') {
+            my ($result,$imageurl) =
+                &publishlogo($r,'upload',$caller,$dom,$confname,
+                             "textbooks/$dom/$cnum/cover",$width,$height);
+            if ($result eq 'ok') {
+                $url = $imageurl;
+            } else {
+                $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
+            }
+        } else {
+            $error = &mt("Upload of [_1] failed because an author role could not be assigned to a Domain Configuration user ([_2]) in domain: [_3].  Error was: [_4].",$filename,$confname,$dom,$author_ok);
+        }
+    } else {
+        $error = &mt("Upload of [_1] failed because a Domain Configuration user ([_2]) could not be created in domain: [_3].  Error was: [_4].",$filename,$confname,$dom,$configuserok);
+    }
+    return ($url,$error);
+}
+
 sub modify_autoenroll {
     my ($dom,$lastactref,%domconfig) = @_;
     my ($resulttext,%changes);
@@ -8052,8 +8519,8 @@
     my %defaultchecked = ('canuse_pdfforms' => 'off');
     my @toggles = ('canuse_pdfforms');
     my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
-                   'uploadquota_community');
-    my @types = ('official','unofficial','community');
+                   'uploadquota_community','uploadquota_textbook');
+    my @types = ('official','unofficial','community','textbook');
     my %staticdefaults = (
                            anonsurvey_threshold => 10,
                            uploadquota          => 500,
@@ -8118,21 +8585,25 @@
             }
         }
         my $officialcreds = $env{'form.official_credits'};
-        $officialcreds =~ s/^[^\d\.]//g;
+        $officialcreds =~ s/[^\d.]+//g;
         my $unofficialcreds = $env{'form.unofficial_credits'};
-        $unofficialcreds =~ s/^[^\d\.]//g;
+        $unofficialcreds =~ s/[^\d.]+//g;
+        my $textbookcreds = $env{'form.textbook_credits'};
+        $textbookcreds =~ s/[^\d.]+//g;
         if (ref($domconfig{'coursedefaults'}{'coursecredits'} ne 'HASH') &&
                 ($env{'form.coursecredits'} eq '1')) {
                 $changes{'coursecredits'} = 1;
         } else {
             if (($domconfig{'coursedefaults'}{'coursecredits'}{'official'} ne $officialcreds)  ||
-                ($domconfig{'coursedefaults'}{'coursecredits'}{'unofficial'} ne $unofficialcreds)) {
+                ($domconfig{'coursedefaults'}{'coursecredits'}{'unofficial'} ne $unofficialcreds) ||
+                ($domconfig{'coursedefaults'}{'coursecredits'}{'textbook'} ne $textbookcreds)) {
                 $changes{'coursecredits'} = 1;
             }
         }
         $defaultshash{'coursedefaults'}{'coursecredits'} = {
             official   => $officialcreds,
             unofficial => $unofficialcreds,
+            textbook   => $textbookcreds,
         }
     }
     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
@@ -8150,6 +8621,8 @@
                             $defaultshash{'coursedefaults'}{'coursecredits'}{'official'};
                         $domdefaults{'unofficialcredits'} =
                             $defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'};
+                        $domdefaults{'textbookcredits'} =
+                            $domdefaults{'coursedefaults'}{'coursecredits'}{'textbook'};
                     }
                 }
                 if ($changes{'uploadquota'}) {
@@ -8180,6 +8653,8 @@
                         $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
                                        '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
                                        '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
+                                       '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
+
                                        '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
                                        '</ul>'.
                                        '</li>';
@@ -8189,12 +8664,14 @@
                 } elsif ($item eq 'coursecredits') {
                     if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
                         if (($domdefaults{'officialcredits'} eq '') &&
-                            ($domdefaults{'unofficialcredits'} eq '')) {
+                            ($domdefaults{'unofficialcredits'} eq '') &&
+                            ($domdefaults{'textbookcredits'} eq '')) {
                             $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
                         } else {
                             $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
                                            '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
                                            '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
+                                           '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
                                            '</ul>'.
                                            '</li>';
                         }


More information about the LON-CAPA-cvs mailing list