[LON-CAPA-cvs] cvs: modules /raeburn lonpopulate.pm

raeburn lon-capa-cvs@mail.lon-capa.org
Thu, 13 Nov 2003 16:09:45 -0000


This is a MIME encoded message

--raeburn1068739785
Content-Type: text/plain

raeburn		Thu Nov 13 11:09:45 2003 EDT

  Added files:                 
    /modules/raeburn	lonpopulate.pm 
  Log:
  Stuart's lonpopulate handler for autoenrollment management
  
  
--raeburn1068739785
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20031113110945.txt"


Index: modules/raeburn/lonpopulate.pm
+++ modules/raeburn/lonpopulate.pm
package Apache::lonpopulate;

use strict;
use Apache::lonnet();
use Apache::loncommon();
use Apache::lonhtmlcommon();
use Apache::Constants qw(:common :http REDIRECT);

###############################################################
sub header {
    my $bodytag=&Apache::loncommon::bodytag('Classlist Manager');
    return(<<ENDHEAD);
<html>
<head>
<title>LON-CAPA Classlist Manager</title>
</head>
$bodytag
ENDHEAD
}

###############################################################

sub print_mainbox {
  my $r = shift;
  my $action = "information";
  if ( exists($ENV{'form.action'}) )
  {
    $action = $ENV{'form.action'};
  }
  my @tasks = ("information","chgsettings","setdates","notify","crosslist","sections","updatenow");
  my %tasklong = (
               information => "Task information",
               chgsettings => "Automated adds/drops",
               setdates => "Change access dates",
               notify => "E-mail notification",
               crosslist => "Change crosslisting",
               sections => "Section settings",
               updatenow => "Update roster now",
               newcross => "Add crosslistings",
              );
  $r->print(<<ENDTHIS);
<table width="80%" border="0" cellpadding="0" cellspacing="0">
 <tr>
  <td width="100%" bgcolor="#000000">
   <table width="100%" border="0" cellpadding="1" cellspacing="0">
    <tr>
     <td width="100%" bgcolor="#000000">
      <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#ffffff">
       <tr>
        <td colspan="2" width="100%" bgcolor="#339999">
         <table width="100%" border="0" cellpadding="5" cellspacing="0">
          <tr>
           <td width="100%">
            <table width="100%" border="0" cellpadding="0" cellspacing="0">
             <tr>
              <td>
               <font face="arial,verdana" color="#000000" size="4"><b>Class Enrollment Manager</b></font></td>
              </td>
              <td align="right">
               <font face='arial,verdana' size="3" color="#ffffff"><b>$tasklong{$action}</b></font>
              </td>
             </tr>
            </table>
           </td>
          </tr>
         </table>
        </td>
       </tr>
ENDTHIS

}

sub print_navmenu {
  my $r = shift;
  my $action = "information";
  if (exists($ENV{'form.action'}) )
  {
    $action = $ENV{'form.action'};
  }
  my @tasks = ("information","chgsettings","setdates","notify","crosslist","sections","updatenow");
  my %tasklong = (
               information => "Task information",
               chgsettings => "Automated adds/drops",
               setdates => "Change access dates",
               notify => "E-mail notification",
               crosslist => "Change crosslisting",
               sections => "Section settings",
               updatenow => "Update roster now",
               newcross => "Add crosslistings",
              );
  $r->print(<<ENDONE);
       <tr>
        <td width="20%" valign="top" bgcolor="#dddddd" height="100%">
         <table width="100%" border="0" cellpadding="0" cellspacing="0" height="100%">
          <tr>
           <td valign="top" height="100%">
            <table width="100%" border="0" cellpadding="3" cellspacing="3">
ENDONE
  foreach my $task (@tasks) {
    if ($task eq $action) {
      $r->print(" 
             <tr>
              <td bgcolor='#ffffff'>
               <small>$tasklong{$task}</small><br> 
              </td>
             </tr>"); 
    }
    else {
      $r->print("
             <tr>
              <td>  
               <small><a href=\"/adm/populate?action=$task\">$tasklong{$task}</a></small><br> 
              </td>
             </tr>");
    }
  }
  $r->print("
              </table> 
           </td>
          </tr>
         </table>
        </td>");
}

###############################################################

sub print_main_frame {
  my $r = shift;
  $r->print("<td bgcolor='#ffffff' width='80%'>");
  my $action = "information";
  if (exists($ENV{'form.action'}) )
  {
    $action = $ENV{'form.action'};
  }

  my $dom = $ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
  my $crs = $ENV{'course.'.$ENV{'request.course.id'}.'.num'};

# get uname and udomain

#  my $coursecode = "us00ubw101";
#  my $sections = "001,002,003,004";
#  &Apache::lonnet::put('environment',{'coursecode'=>$coursecode,'sectionnums'=>$sections},$dom,$crs);
  
# Get course environment parameters
#  my %values = &Apache::lonnet::get('environment',['coursecode','sectionnums'],$dom,$crs);
#  my %values = &Apache::lonnet::dump('environment',$dom,$crs);
#  my %values = &Apache::lonnet::courseiddump($dom,'.',1);
#  foreach (keys %values) 
#  {
#    $r->print("<br>$_ $values{$_}<br>");
#  } 

  if ($action eq "information")
  {
    $r->print(<<ENDONE);
          <table border='0' width='100%'>
            <tr>
              <td>&nbsp;</td>
              <td><font face="arial,verdana" size="3"><b>Use the menu on the left to choose an enrollment management task.</b></font><br><br>
            <tr>
              <td>&nbsp;</td>
              <td><small>Use <i>"Automated adds/drops"</i> to enable or disable automatic nightly adds or drops in your LON-CAPA course based on instututional enrollment information.</small></td>
            </tr>
            <tr>
              <td>&nbsp;</td>
              <td><small>Use <i>"Change access dates"</i> to change the first enrollment date and/or the last access date for registered students.</td>
            </tr>
            <tr>
              <td>&nbsp;</td>
              <td><small>Use <i>"E-mail notification"</i> to enable or disable e-mail notification of enrollment changes and to add or remove course coordinators or instructors from the recipient list.</small></td>
            </tr>
            <tr>
              <td>&nbsp;</td>
              <td><small>Use <i>"Change crosslisting"</i> to include or exclude enrollment from crosslisted classes.</small></td>
            </tr>
            <tr>
              <td>&nbsp;</td>
              <td><small>Use <i>"Section relationships"</i> to make changes to the choice of sections included for enrollment in your LON-CAPA course.</small></td>
            </tr>
            <tr>
              <td>&nbsp;</td>
              <td><small>Use <i>"Update roster now"</i> to add and/or drop students from your course based on the latest institutional classlist information.</small></td>
            </tr>
            <tr>
             <td colspan='2'>&nbsp;</td>
            </tr>
            <tr>
             <td>&nbsp;</td>
             <td><font size='3'><b>Note: if automated adds and/or drops are enabled, the nightly enrollment update will ONLY occur once the first enrollment date has been reached.</b></font></td>
            </tr>
          </table>
         </td>
        </tr>
ENDONE
  }
  if ($action eq "chgsettings")
  {
    my $addset = 0;
    my $dropset = 0;
    $r->print(<<ENDTWO);
		  <table width="100%" border="0" cellpadding="2" cellspacing="2">
		   <tr>
		    <td align="left"><font face="arial,verdana" size="2"><b>Nightly automated enrollments</b></font><br><br>
		       <font face="arial,verdana" size="2">Currently: Nightly adds: <i>$addset</i>, Nightly drops: <i>$dropset</i></font>
		    </td>
                   </tr>
		  </table>
		  <table width="100%" border="0" cellpadding="3" cellspacing="3">
		    <tr>
		     <td><font face="arial,verdana" size="2">
		         Additions based on classlist changes:&nbsp;&nbsp;
ENDTWO
     if ($addset eq "ON") {
       $r->print("
			    <input type=\"radio\" name=\"enroll\" value=\"1\" checked>&nbsp;Enable&nbsp;&nbsp;&nbsp;
			    <input type=\"radio\" name=\"enroll\" value=\"0\">&nbsp;Disable
                 ");
     }
     else
     {
       $r->print("
                            <input type=\"radio\" name=\"enroll\" value=\"1\">&nbsp;Enable&nbsp;&nbsp;&nbsp;
                            <input type=\"radio\" name=\"enroll\" value=\"0\" checked>&nbsp;Disable
                 ");
     }
     $r->print("
               </font>
              </td>
             </tr>
             <tr>
              <td><font face=\"arial,verdana\" size=\"2\">
 			    Removals based on classlist changes:&nbsp;&nbsp;");
     if ($dropset eq "ON") {
       $r->print("
                <input type=\"radio\" name=\"unenroll\" value=\"1\" checked>&nbsp;Enable&nbsp;&nbsp;&nbsp;
                <input type=\"radio\" name=\"unenroll\" value=\"0\">&nbsp;Disable");
     }
     else {
       $r->print("
                <input type=\"radio\" name=\"unenroll\" value=\"1\">&nbsp;Enable&nbsp;&nbsp;&nbsp;
                <input type=\"radio\" name=\"unenroll\" value=\"0\" checked>&nbsp;Disable");
     }
     $r->print("
               </font>
              </td>
             </tr>
             <tr>
              <td>
               <font face=\"arial,verdana\"><font color=\"#888888\" size=\"2\">
Note: Any students added manually by course coordinators using Enrollment Manager will be unaffected by the nightly removal process if you choose to enable it.
               </font>
              </td>
             </tr>
             <tr>
              <td align=\"right\"><font face=\"arial,verdana\" size=\"2\">
               <input type=\"button\" name=\"chgsettings\" value=\"G\" onClick=\"process('chgsettings')\">
               </font>
	      </td>
             </tr>
	    </table>");
  }
}

###############################################################
sub print_doc_base {
  my $r = shift;
  $r->print(<<ENDBASE);
      </table>
     </td>
    </tr>
   </table>
  </td>
 </tr>
</table>
<br>
</body>
</html> 
ENDBASE
}
 
###################################################################
sub print_chgsettings_response ()
{
#  my $date_table = &date_setting_table();
}

sub print_chgdates_response ()
{

}

sub print_crosslistings_response ()
{

}

sub print_sections_menu ()
{

}

sub print_update_result ()
{

}

sub setup_date_selectors {
    my ($starttime,$endtime) = @_;
    if (! defined($starttime)) {
        $starttime = time;
        if (exists($ENV{'course.'.$ENV{'request.course.id'}.
                            '.default_enrollment_start_date'})) {
            $starttime = $ENV{'course.'.$ENV{'request.course.id'}.
                                  '.default_enrollment_start_date'};
        }
    }
    if (! defined($endtime)) {
        $endtime = time+(6*30*24*60*60); # 6 months from now, approx
        if (exists($ENV{'course.'.$ENV{'request.course.id'}.
                            '.default_enrollment_end_date'})) {
            $endtime = $ENV{'course.'.$ENV{'request.course.id'}.
                                '.default_enrollment_end_date'};
        }
    }
    my $startdateform = &Apache::lonhtmlcommon::date_setter('studentform',
                                                            'startdate',
                                                            $starttime);
    my $enddateform = &Apache::lonhtmlcommon::date_setter('studentform',
                                                          'enddate',
                                                          $endtime);
    return ($startdateform,$enddateform);
}

sub get_dates_from_form {
    my $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate');
    my $enddate   = &Apache::lonhtmlcommon::get_date_from_form('enddate');
    if ($ENV{'form.no_end_date'}) {
        $enddate = 0;
    }
    return ($startdate,$enddate);
}

sub date_setting_table {
    my ($starttime,$endtime) = @_;
    my ($startform,$endform)=&setup_date_selectors($starttime,$endtime);
    my $perpetual = '<nobr><input type="checkbox" name="no_end_date"';
    if (defined($endtime) && $endtime == 0) {
        $perpetual .= ' checked';
    }
    $perpetual.= ' />'.' no ending date</nobr>';
    my $result = '';
    $result .= "<table>\n";
    $result .= '<tr><td align="right">Starting Date</td>'.
        '<td>'.$startform.'</td>'.
        '<td>&nbsp;</td>'."</tr>\n";
    $result .= '<tr><td align="right">Ending Date</td>'.
        '<td>'.$endform.'</td>'.
        '<td>'.$perpetual.'</td>'."</tr>\n";
    $result .= "</table>\n";
    return $result;
}


###################################################################
sub handler {
    my $r = shift;
    if ($r->header_only) {
        $r->content_type('text/html');
        $r->send_http_header;
        return OK;
    }
    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['action','state']);
    #  Needs to be in a course
    if (! (($ENV{'request.course.fn'}) &&  (&Apache::lonnet::allowed('cst',$ENV{'request.course.id'})))) {
        # Not in a course, or not allowed to modify parms
        $ENV{'user.error.msg'}="/adm/populate:cst:0:0:Cannot drop or add students";
        return HTTP_NOT_ACCEPTABLE; 
    }
    # Start page
    $r->content_type('text/html');
    $r->send_http_header;
    $r->print(&header());
    
    #
    # Main switch on form.action and form.state, as appropriate
    #

     my $action = "information";
     if ( exists($ENV{'form.action'}) )
     {
       $action = $ENV{'form.action'};
     }
    
    &print_mainbox($r);
    &print_navmenu($r);
    if ($action eq "information")
    {
      &print_main_frame($r);
    }
    elsif ($action eq "chgsettings")
    {

    }
    &print_doc_base($r);  
    return OK;
}
###################################################################
1;

--raeburn1068739785--