[LON-CAPA-cvs] cvs: loncom /interface lonparmset.pm

raeburn lon-capa-cvs-allow@mail.lon-capa.org
Tue, 01 Jul 2008 01:35:29 -0000


This is a MIME encoded message

--raeburn1214876129
Content-Type: text/plain

raeburn		Mon Jun 30 21:35:29 2008 EDT

  Modified files:              
    /loncom/interface	lonparmset.pm 
  Log:
  - Course categories can be set by Course Coordinator via "Set Course Environment"
    if Domain Configuration permits this for courses in the domain.
  
  
--raeburn1214876129
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20080630213529.txt"

Index: loncom/interface/lonparmset.pm
diff -u loncom/interface/lonparmset.pm:1.402 loncom/interface/lonparmset.pm:1.403
--- loncom/interface/lonparmset.pm:1.402	Thu Jun 26 20:02:55 2008
+++ loncom/interface/lonparmset.pm	Mon Jun 30 21:35:28 2008
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set parameters for assessments
 #
-# $Id: lonparmset.pm,v 1.402 2008/06/27 00:02:55 raeburn Exp $
+# $Id: lonparmset.pm,v 1.403 2008/07/01 01:35:28 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2135,11 +2135,11 @@
                 }
                 # Update environment and nohist_courseids.db
                 if (($name eq 'description') || ($name eq 'cloners') || 
-                    ($name eq 'hidefromcat')) {
+                    ($name eq 'hidefromcat') || ($name eq 'categories')) {
                     if ($chome eq '') {
                         %crsinfo =
                             &Apache::lonnet::courseiddump($dom,'.',1,'.','.',
-                                                 $crs,undef,undef,'Course');
+                                                 $crs,undef,undef,'.');
                         $chome = &Apache::lonnet::homeserver($crs,$dom);
                     }
                 }
@@ -2152,17 +2152,10 @@
                                                          $chome,'notime');
                     }
                 }
-                if ($name eq 'cloners') {
-                    if (ref($crsinfo{$env{'request.course.id'}}) eq 'HASH') {
-                        $crsinfo{$env{'request.course.id'}}{'cloners'} = $value;
-                        my $putresult =
-                            &Apache::lonnet::courseidput($dom,\%crsinfo,
-                                                         $chome,'notime');
-                    }
-                }
-                if ($name eq 'hidefromcat') {
+                if (($name eq 'cloners') || ($name eq 'hidefromcat') || ($name eq 'categories')) {
                     if (ref($crsinfo{$env{'request.course.id'}}) eq 'HASH') {
-                        $crsinfo{$env{'request.course.id'}}{'hidefromcat'} = $value;
+                        &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.'.$name => $value});
+                        $crsinfo{$env{'request.course.id'}}{$name} = $value;
                         my $putresult =
                             &Apache::lonnet::courseidput($dom,\%crsinfo,
                                                          $chome,'notime');
@@ -2218,6 +2211,7 @@
     my $SelectStyleFile=&mt('Select Style File');
     my $SelectSpreadsheetFile=&mt('Select Spreadsheet File');
     my $output='';
+    my $can_categorize;
     if (! exists($values{'con_lost'})) {
         my %descriptions=
 	    ('url'            => '<b>'.&mt('Top Level Map').'</b><br />'.
@@ -2355,14 +2349,21 @@
              'suppress_embed_prompt'
                  => '<b>'.&mt('Suppress prompt to upload items referenced in a web page being uploaded to portfolio, when current role is student.').'</b><br />'.
                     ' ('.&mt('[_1] to suppress, anything else to not suppress','"<tt>yes</tt>"').')',
-              'hidefromcat'
+             'hidefromcat'
                  => '<b>'.&mt('Exclude from course catalog').'</b><br />'.
                     ' ('.&mt('[_1] to exclude, anything else to include - included if assigned an institutional code, or manually catagorized','"<tt>yes</tt>"').')',
+             'categories'
+                 => '<b>'.&mt('Categorize course').'</b> <a href="javascript:catsbrowser()">'.
+                    &mt('Display Categories').'</a>',
              );
         my @Display_Order = ('url','description','courseid','cloners');
-        if (&can_toggle_cat($dom)) {
+        (my $can_toggle_cat,$can_categorize) = &can_modify_catsettings($dom);
+        if ($can_toggle_cat) {
             push(@Display_Order,'hidefromcat');
         }
+        if ($can_categorize) {
+            push(@Display_Order,'categories');
+        }
         push (@Display_Order,('grading',
                              'externalsyllabus',
                              'default_xml_style','pageseparators',
@@ -2461,14 +2462,26 @@
     my $Parameter=&mt('Parameter');
     my $Value=&mt('Value');
     my $Set=&mt('Set');
-    my $browse_js=
-	'<script type="text/javascript" language="Javascript">'.
-	&Apache::loncommon::browser_and_searcher_javascript('parmset').
-	'</script>';
-    
+    my ($jscript,$categorize_js);
+    my $browse_js = &Apache::loncommon::browser_and_searcher_javascript('parmset');
+    if ($can_categorize) {
+        $categorize_js = <<ENDSCRIPT;
+function catsbrowser() {
+    var catswin = null;
+    var url = '/adm/parmset?action=categorizecourse';
+    if (!catswin || catswin.closed) {
+        catswin=window.open(url,'categorieswin','height=480,width=600,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
+    } else {
+        catswin.focus();
+    }
+} 
+ENDSCRIPT
+    }
+    $jscript = '<script type="text/javascript" language="Javascript">'."\n".
+               $browse_js."\n".$categorize_js."\n".'</script>';
     my $start_page = 
 	&Apache::loncommon::start_page('Set Course Environment',
-				       $browse_js);
+				       $jscript);
     my $end_page = 
 	&Apache::loncommon::end_page();
     my $end_table=&Apache::loncommon::end_data_table();
@@ -2490,16 +2503,88 @@
 ENDENV
 }
 
-sub can_toggle_cat {
+sub can_modify_catsettings {
     my ($dom) = @_;
     my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$dom);
-    my $can_toggle_cat = '';
+    my ($can_toggle_cat,$can_categorize);
     if (ref($domconf{'coursecategories'}) eq 'HASH') {
         if ($domconf{'coursecategories'}{'togglecats'} eq 'crs') {
             $can_toggle_cat = 1;
         }
+        if ($domconf{'coursecategories'}{'categorize'} eq 'crs') {
+            $can_categorize = 1;
+        }
+    }
+    return ($can_toggle_cat,$can_categorize);
+}
+
+sub assign_course_categories {
+    my ($r) = @_;
+    my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+    my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+    my $hascats = 0;
+    my $cathash;
+    my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
+    if (ref($domconf{'coursecategories'}) eq 'HASH') {
+        $cathash = $domconf{'coursecategories'}{'cats'};
+        if (ref($cathash) eq 'HASH') {
+            $hascats = 1;   
+        }
     }
-    return $can_toggle_cat;
+    my $catwin_js;
+    if ($hascats) {
+        my $alert = &mt('Use \"Save\" in the main window to save course categories');
+        $catwin_js = <<ENDSCRIPT;
+<script type="text/javascript">
+
+function updateCategories() {
+    var newcategories = '';
+    if (document.chgcats.usecategory.length) {
+        for (var i=0; i<document.chgcats.usecategory.length; i++) {
+            if (document.chgcats.usecategory[i].checked == true) {
+                newcategories = newcategories + document.chgcats.usecategory[i].value + '&';
+            }
+        }
+        if (newcategories.length > 0) {
+            newcategories = newcategories.slice(0,-1);
+        }
+    } else {
+         if (document.chgcats.usecategory.checked == true) {
+             newcategories = document.chgcats.usecategory.value;
+         }
+    }
+    opener.document.envform.categories_value.value = newcategories;
+    opener.document.envform.categories_setparmval.checked = true;
+    alert("$alert");
+    self.close();
+    return;
+}
+
+</script>
+ENDSCRIPT
+    } else {
+        my $onload; 
+    }
+    my $start_page =
+        &Apache::loncommon::start_page('Course Categories',$catwin_js,
+                                       {'only_body'      => 1,});
+    my $end_page = &Apache::loncommon::end_page();
+    my $categoriesform = '<h3>'.&mt('Categorize Course').'</h3>';
+    if ($hascats) {
+        my %currsettings =
+            &Apache::lonnet::get('environment',['hidefromcat','categories'],$cdom,$cnum);
+        $categoriesform .= &mt('Assign one or more categories to this course.').'<br /><br />'.
+                               '<form name="chgcats" action="/adm/parmset" method="post">'."\n"
+                               .&Apache::loncommon::assign_categories_table($cathash,
+                                                       $currsettings{'categories'})."\n"
+                               .'<br /><input type="button" name="changes" value="'
+                               .&mt('Copy to main window').'" '
+                               .'onclick="javascript:updateCategories()" /></form><br />';
+    } else {
+        $categoriesform .= &mt('No categories defined for this domain');
+    }
+    $r->print($start_page.$categoriesform.$end_page);
+    return;
 }
 
 ##################################################
@@ -4363,7 +4448,9 @@
             &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=dateshift1&timebase='.$env{'form.timebase'},
                                                     text=>"Shifting Dates"});
             &date_shift_two($r);
-	}       
+	} elsif ($env{'form.action'} eq 'categorizecourse' && $parm_permission) {
+            &assign_course_categories($r);
+        } 
     } else {
 # ----------------------------- Not in a course, or not allowed to modify parms
 	if ($exists) {

--raeburn1214876129--