[LON-CAPA-cvs] cvs: loncom /html/adm/helper course.initialization.helper

raeburn lon-capa-cvs-allow@mail.lon-capa.org
Mon, 03 Sep 2007 20:23:58 -0000


raeburn		Mon Sep  3 16:23:58 2007 EDT

  Modified files:              
    /loncom/html/adm/helper	course.initialization.helper 
  Log:
  bug 5378
  Include "users can clone".
  
  
Index: loncom/html/adm/helper/course.initialization.helper
diff -u loncom/html/adm/helper/course.initialization.helper:1.17 loncom/html/adm/helper/course.initialization.helper:1.18
--- loncom/html/adm/helper/course.initialization.helper:1.17	Tue Oct 17 11:04:59 2006
+++ loncom/html/adm/helper/course.initialization.helper	Mon Sep  3 16:23:57 2007
@@ -192,7 +192,7 @@
     </state>
 
   <state name="FEEDBACK_ADDRESSES" title="Feedback Addresses for Course Content">
-    <message nextstate="FINAL">
+    <message nextstate="USERS_ALLOWED_TO_CLONE">
       Course members can provide feedback about the course. You can choose
       who will receive the feedback, such as a different instructor or a
       TA. Please enter their LON-CAPA address below, in the
@@ -233,6 +233,84 @@
       </message>
     </state>
 
+  <state name="USERS_ALLOWED_TO_CLONE" title="Granting permission to clone course">
+   <message nextstate="FINAL"> 
+      Existing courses can be cloned when creating new courses.<br />Cloning will copy the course structure, contents, and most parameters (automatically advancing any date parameters by six months).<br /><br />
+      Names of owners of other courses permitted to clone this course:<br />
+   </message>
+   <string variable='can_clone' size='60' >
+    <defaultvalue>
+     return &{$helper->{DATA}->{GETVAL}}('cloners');
+    </defaultvalue>
+    <validator>
+      my ($output,@cloners,%disallowed);
+      my $match_dom = $LONCAPA::match_domain;
+      my $match_uname = $LONCAPA::match_username; 
+      if ($val =~ /,/) {
+          @cloners = split(/,/,$val);
+      } else {
+          $cloners[0] = $val;
+      }
+      my @alldoms = &Apache::lonnet::all_domains();
+      foreach my $item (@cloners) {
+          if ($item ne '*') {
+              my ($clname,$cldom) = split(/:/,$item);
+              if ($clname eq '*') {
+                  if ($cldom =~ /^$match_dom$/) {
+                      if (!grep(/^\Q$cldom\E$/,@alldoms)) {
+                          $disallowed{'domain'} .= $item.',';
+                      }
+                  } else {
+                      $disallowed{'format'} .= $item.',';
+                  }
+              } elsif ($item !~/^($match_uname)\:($match_dom)$/) {
+                  $disallowed{'format'} .= $item.',';
+              } else {
+                  if (!grep(/^\Q$cldom\E$/,@alldoms)) {
+                      $disallowed{'domain'} .= $item.','; 
+                  } elsif (&Apache::lonnet::homeserver($clname,$cldom) eq 'no_host') {
+                      $disallowed{'newuser'} .= $item.',';
+                  }
+              }
+          }
+      }
+      foreach my $key (keys(%disallowed)) {
+          $disallowed{$key} =~ s/,$//;
+      }
+      if (keys(%disallowed) > 0) {
+          $output.= 'Your input contained the following errors:<ul>';
+          if (defined($disallowed{'format'})) {
+              $output  .= '<li>Invalid format: '.
+                          '<b>'.$disallowed{'format'}.'</b></li>';
+          }
+          if (defined($disallowed{'domain'})) {
+              $output .= '<li>Domain(s) do(es) not exist: '.
+                          '<b>'.$disallowed{'domain'}.'</b></li>';
+          }
+          if (defined($disallowed{'newuser'})) {
+              $output .= '<li>LON-CAPA user(s) do(es) not exist: '.
+                         '<b>'.$disallowed{'newuser'}.'</b></li>';
+          }
+          $output .= '.</ul>';
+      }
+      return $output;
+    </validator>
+    <finalcode>
+     if (&{$helper->{DATA}->{SETVAL}}('cloners', $element->getValue())) {
+
+
+       return 'Users allowed to clone course updated to <b>' . $element->getValue() .
+                 '</b>.';
+     }
+    </finalcode>
+   </string>
+   <message>
+    <br />(Course Coordinators automatically have the right to clone their own courses.)
+    <ul>
+     <li>Format: <b>user:domain</b>, where &quot;user&quot; and &quot;domain&quot;
+      are the LON-CAPA username and domain of the user.</li><li>Separate different users with a comma.</li><li>Use *:domain to allow course to be cloned by any course owner in the specified domain.</li><li>Use * to allow unrestricted cloning by all course owners in all domains.</li></ul>
+   </message>
+  </state>
   <state name="FINAL" title="Completed">
     <message>Your course is now set up. Please select the <b>Finish Course 
       Initialization</b> button to re-intialize the course with your chosen