File:  [LON-CAPA] / loncom / html / adm / helper / newslot.helper
Revision 1.12: download - view: text, annotated - select for diffs
Fri Feb 3 22:40:46 2006 UTC (18 years, 6 months ago) by albertel
Branches: MAIN
CVS tags: version_2_1_X, version_2_1_3, HEAD
- weren't able to actually change the start reserve time

    1: <helper title="Slot Creation" requiredpriv="mgq">
    2:   <state name="START" title="Specify Required Attributes">
    3:     <exec>
    4:       if (!exists($helper->{'VARS'}{'name'}) ||
    5: 	  $helper->{'VARS'}{'name'} !~ /\S/) {
    6: 	  &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
    7: 	  if (exists($env{'form.name'}) ||
    8: 	      $env{'form.name'} =~ /\S/) {
    9: 	      $helper->{'VARS'}{'name'}=$env{'form.name'};
   10: 	      $helper->{VARS}{'origname'}=$env{'form.name'};
   11: 	      $helper->{DATA}{copy} = 1;
   12: 	  }
   13:       }
   14:       $helper->{DATA}{origslot} = sub {
   15: 	  my ($which,$default)=@_;
   16: 	  if (!exists($helper->{'VARS'}{'name'}) ||
   17: 	      $helper->{'VARS'}{'name'} !~ /\S/) {
   18: 	      return $default;
   19: 	  }
   20: 	  my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
   21: 	  my $cdom  = $env{'course.'.$env{'request.course.id'}.'.domain'};
   22: 	  my $name=$helper->{VARS}{'origname'};
   23: 	  my %slot=&Apache::lonnet::get('slots', [$name], $cdom, $cnum);
   24: 	  if (!ref($slot{$name})) { return $default; }
   25: 	  if (!exists($slot{$name}{$which})) { return $default; }
   26: 	  return $slot{$name}{$which};
   27:       }
   28:     </exec>
   29:     <message nextstate="OPTIONAL">
   30:         Name: <br />&nbsp;&nbsp;&nbsp;
   31:     </message>
   32:     <string variable="name" size="30">
   33:       <validator>
   34:           if ($val=~/^\s*$/) { return 'Must specify a name'; }
   35:           if ($val=~/\s/) { return 'Must not contain spaces'; }
   36:           if ($val=~/\W/) { return 'Must contain only letters, numbers and _'; }
   37:           return undef;
   38:       </validator>
   39:       <defaultvalue>
   40:         return $helper->{'VARS'}{'name'};
   41:       </defaultvalue>
   42:     </string>
   43:     <condition>
   44:       <clause>$helper->{DATA}{copy}</clause>
   45:       <message nextstate="OPTIONAL">
   46: 	<p>Changing the Name will create a new slot with the new name, and not rename the existing slot.</p>
   47:       </message>
   48:     </condition>
   49:     <message>
   50:       <br />Start time:<br />&nbsp;&nbsp;&nbsp;
   51:     </message>
   52:     <date variable="starttime" hoursminutes="1">
   53:       <defaultvalue>
   54:         return &{$helper->{DATA}{origslot}}('starttime');
   55:       </defaultvalue>
   56:     </date>
   57:     <message>
   58:       <br />End time:<br />&nbsp;&nbsp;&nbsp;
   59:     </message>
   60:     <date variable="endtime" hoursminutes="1">
   61:       <defaultvalue>
   62:         return &{$helper->{DATA}{origslot}}('endtime');
   63:       </defaultvalue>
   64:     </date>
   65:     <message>
   66:       <br />Type:
   67:     </message>
   68:     <choices variable="type">
   69:       <choice computer='preassigned'>Instructor asssignable.</choice>
   70:       <choice computer='schedulable_student'>Student selectable.</choice>
   71:       <defaultvalue>
   72:         return &{$helper->{DATA}{origslot}}('type','preassigned');
   73:       </defaultvalue>
   74:     </choices>
   75:   </state>
   76: 
   77:   <state name="OPTIONAL" title="Specify Optional Attributes">
   78:     <message>
   79:         <p>Description:<br />&nbsp;&nbsp;&nbsp;
   80:     </message>
   81:     <string variable="description" size="60">
   82:       <defaultvalue>
   83:         return &{$helper->{DATA}{origslot}}('description');
   84:       </defaultvalue>
   85:     </string>
   86:     <condition>
   87:       <clause>$helper->{'VARS'}{'type'} eq 'schedulable_student'</clause>
   88:       <message>
   89:         </p><p>Time students can start reserving:<br />&nbsp;&nbsp;&nbsp;
   90:       </message>
   91:       <date variable="startreserve" hoursminutes="1" anytime="1">
   92:         <defaultvalue>
   93:           return &{$helper->{DATA}{origslot}}('startreserve','anytime');
   94:         </defaultvalue>
   95:       </date>
   96:       <message>
   97:          </p><p>Maxium number of students allowed in this slot:<br />&nbsp;&nbsp;&nbsp;
   98:       </message>
   99:       <string variable="maxspace" size="4">
  100:         <validator>
  101:             if ($val ne '' && $val=~/\D/) { return 'Must be numeric.'; }
  102:             return undef;
  103:         </validator>
  104:         <defaultvalue>
  105:           return &{$helper->{DATA}{origslot}}('maxspace');
  106:         </defaultvalue>
  107:       </string>
  108:       <message>
  109:          </p><p>Period of time in which this slot is can only be uniquely chosen:<br />&nbsp;&nbsp;&nbsp;Start:
  110:       </message>
  111:       <date variable="startunique" hoursminutes="1" anytime="1">
  112:         <defaultvalue>
  113:           my $default=&{$helper->{DATA}{origslot}}('uniqueperiod','anytime');
  114:           if ($default eq 'anytime') { return 'anytime' };
  115:           if (ref($default)) { return $default->[0]; }
  116:           return 'anytime';
  117:         </defaultvalue>
  118:       </date>
  119:       <message><br />&nbsp;&nbsp;&nbsp;End: </message>
  120:       <date variable="endunique" hoursminutes="1" anytime="1">
  121:         <defaultvalue>
  122:           my $default=&{$helper->{DATA}{origslot}}('uniqueperiod','anytime');
  123:           if ($default eq 'anytime') { return 'anytime' };
  124:           if (ref($default)) { return $default->[1]; }
  125:           return 'anytime';
  126:         </defaultvalue>
  127:       </date>
  128:     </condition>
  129:     <condition>
  130:       <clause>$helper->{'VARS'}{'type'} eq 'preassigned'</clause>
  131:       <exec>
  132:         delete($helper->{'VARS'}{'startreserve'});
  133:         delete($helper->{'VARS'}{'maxspace'});
  134:         delete($helper->{'VARS'}{'startunique'});
  135:         delete($helper->{'VARS'}{'endunique'});
  136:       </exec>
  137:     </condition>
  138:     <message>
  139:       </p><p>Secret word proctors use to checkin users:<br />&nbsp;&nbsp;&nbsp;
  140:     </message>
  141:     <string variable="secret" size="12">
  142:       <validator>
  143:           return undef;
  144:       </validator>
  145:       <defaultvalue>
  146:         return &{$helper->{DATA}{origslot}}('secret');
  147:       </defaultvalue>
  148:     </string>
  149:     <message>
  150:       </p><p>Slot is:
  151:     </message>
  152:     <choices variable="restricttosymb">
  153:       <choice nextstate="PROCTOR" computer='any'>usable for any resource.</choice>
  154:       <choice nextstate="RESOURCESELECT" computer='resource'>restricted to a specific resource.</choice>
  155:       <defaultvalue>
  156:         my $default=&{$helper->{DATA}{origslot}}('symb');
  157:         if ($default) { return 'resource'; }
  158:         return 'any';
  159:       </defaultvalue>
  160:     </choices>
  161:     <message>
  162:        
  163: 	</p><p>IP restrictions:<br />&nbsp;&nbsp;&nbsp;
  164:       
  165:     </message>
  166:     <string variable="ip" size="30">
  167:       <validator>
  168:           return undef;
  169:       </validator>
  170:       <defaultvalue>
  171:         return &{$helper->{DATA}{origslot}}('ip');
  172:       </defaultvalue>
  173:     </string>
  174:     <message>  </p>  </message>
  175:   </state>
  176:   <state name="RESOURCESELECT" title="Specify Optional Attributes">
  177:     <resource variable="symb">
  178:       <filterfunc>return $res->is_problem()</filterfunc>
  179:       <valuefunc>return $res->symb()</valuefunc>
  180:       <nextstate>PROCTOR</nextstate>
  181:       <defaultvalue>
  182:         return &{$helper->{DATA}{origslot}}('symb');
  183:       </defaultvalue>
  184:     </resource>    
  185:   </state>
  186:   <state name="PROCTOR" title="Specify Proctors">
  187:     <student variable="proctor" multichoice="1" coursepersonnel="1"
  188:              nextstate="FINISH" activeonly="1" emptyallowed="1">
  189:       <defaultvalue>
  190:         my @defaults;
  191:         my $default=&{$helper->{DATA}{origslot}}('proctor');
  192:         if ($default) {
  193: 	    $default=~ tr/@/:/;
  194: 	    @defaults=(split(',',$default)); 
  195: 	}
  196:         return @defaults;
  197:       </defaultvalue>
  198:     </student>
  199:   </state>
  200:   <state name="FINISH" title="Creating/Modfying Slot">
  201: 	    <message> Created Slot  </message>	
  202:     <final>
  203:       <finalcode>
  204:         my $result;
  205: 	if ($helper->{'STATE'} ne 'FINISH') { return; }
  206: 	my %slot;
  207: 	foreach my $which ('type','starttime','endtime') {
  208: 	    $slot{$which} = $helper->{'VARS'}{$which};
  209: 	}
  210: 	foreach my $which ('ip','description','maxspace',
  211: 			   'secret','symb') {
  212: 	    if ( $helper->{'VARS'}{$which} =~/\S/ ) {
  213: 		$slot{$which} = $helper->{'VARS'}{$which};
  214: 	    }
  215: 	}
  216: 	if ( $helper->{'VARS'}{'startreserve'} > 0) {
  217: 		$slot{'startreserve'} = $helper->{'VARS'}{'startreserve'};
  218: 	}
  219: 	if ( $helper->{'VARS'}{'startunique'} > 0 &&
  220: 	     $helper->{'VARS'}{'endunique'} > 0 ) {
  221: 	    $slot{'uniqueperiod'} = [$helper->{'VARS'}{'startunique'},
  222: 				     $helper->{'VARS'}{'endunique'}];
  223: 	}
  224:         if ( $helper->{'VARS'}{'proctor'} =~/\S/ ) {
  225: 	    my @names;
  226: 	    foreach my $user (split(/\|\|\|/, $helper->{'VARS'}{'proctor'})) {
  227: 		my ($uname,$udomain)=split(/:/,$user);
  228: 		push(@names,"$uname\@$udomain");
  229: 	    }
  230: 	    # make sure the usenrmaes are unique
  231: 	    my %proctors = map { ($_,1) } @names;
  232: 	    $slot{'proctor'}=join(',',sort(keys(%proctors)));
  233: 	}
  234:         my $cname = $env{'course.'.$env{'request.course.id'}.'.num'};
  235:         my $cdom  = $env{'course.'.$env{'request.course.id'}.'.domain'};
  236: 
  237:         my $ret = &Apache::lonnet::cput('slots',
  238: 					{$helper->{'VARS'}{'name'} => \%slot},
  239: 					$cdom,$cname);
  240:         $result.="\n ".'Name: '.&HTML::Entities::encode($helper->{'VARS'}{'name'}).'</li>'.
  241:     "\n".'<li> Starts: '.&Apache::lonlocal::locallocaltime($slot{'starttime'}).'</li>'.
  242:                  "\n".'<li> Ends: '.&Apache::lonlocal::locallocaltime($slot{'endtime'}).'</li>'.
  243:                  "\n".'<li> Type: '.$slot{'type'}.'</li>';
  244:         my %labels =
  245:              map {($_->[0],$_->[1])} &Apache::slotrequest::csvupload_fields();
  246:         foreach my $which ('ip','description','maxspace','secret','symb') {
  247: 	    if (exists($slot{$which})) {
  248: 		$result.="\n".'<li> '.$labels{$which}.': '.
  249: 		    &HTML::Entities::encode($slot{$which}).'</li>';
  250: 	    }
  251: 	}
  252: 	if (exists($slot{'startreserve'})) {
  253: 	    $result.="\n".'<li> '.$labels{'startreserve'}.': '.
  254: 		    &Apache::lonlocal::locallocaltime($slot{'startreserve'}).'</li>';
  255: 	}
  256:         if (exists($slot{'proctor'})) {
  257: 	    my $proctors = $slot{'proctor'};
  258: 	    $proctors =~ s/,/, /g;
  259: 	    $result.="\n".'<li> '.$labels{'proctor'}.': '.
  260: 		&HTML::Entities::encode($proctors).'</li>';
  261: 	}
  262:         if (exists($slot{'uniqueperiod'})) {
  263: 	    $result.=
  264:                  "\n".'<li> '.$labels{'uniqueperiod'}.': '.
  265: 		 &Apache::lonlocal::locallocaltime($slot{'uniqueperiod'}[0]).
  266: 		 ', '.
  267: 		 &Apache::lonlocal::locallocaltime($slot{'uniqueperiod'}[1]).
  268: 		 '</li>';
  269: 	}
  270:         return $result;
  271:       </finalcode>
  272:       <exitpage>/adm/slotrequest?command=showslots</exitpage>
  273:     </final>
  274:   </state>
  275: </helper>

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>