File:  [LON-CAPA] / loncom / html / adm / helper / resettimes.helper
Revision 1.11: download - view: text, annotated - select for diffs
Tue May 31 22:04:14 2016 UTC (8 years, 5 months ago) by raeburn
Branches: MAIN
CVS tags: version_2_12_X, version_2_11_2_uiuc, version_2_11_2_msu, HEAD
- Bug 6763. "Done" button.
  - When "Reset access times" helper deletes student-specific interval
    interval parameter (set by "Done" button push), devalidate cache of
    userres data for that student.

    1: <helper title="Reset Access Times" requiredpriv="mgr">
    2:   <state name="START" title="Select Scope">
    3:     <message>
    4:       <message_text>Select </message_text>
    5:     </message>
    6:     <choices variable="harry">
    7:       <choice computer='1' nextstate="Student">Reset times on one or more folders/maps, resources or the course for a single student.</choice>
    8:       <choice computer='0' nextstate="Class">Reset times on a single folder/map, resource or the course for a section or the whole class.</choice>
    9:       </choices>
   10:   </state>
   11:   <state name="Student" title="Select Student">
   12:     <message nextstate="SelectAccess">
   13: 	<message_text>Choose a student:<br /></message_text>
   14:     </message>
   15:     <student variable='stu1' coursepersonnel='true' activeonly='true' />
   16:   </state>
   17: 
   18:   <state name="SelectAccess">
   19:     <message nextstate="ConfirmStu">
   20:        <message_text>This is a list of first access times and what was accessed, please select those you want deleted.</message_text>
   21:     </message>
   22:     <choices variable='delete' multichoice='true'>
   23:       <exec>
   24:          my ($uname,$udom,$sec,$fullname)=split(':',$helper->{'VARS'}{'stu1'});
   25:          my %times=&Apache::lonnet::dump('firstaccesstimes',$udom,$uname,
   26: 					 "^$env{'request.course.id'}\0");
   27:          foreach my $res (sort(keys(%times))) {
   28: 	     my (undef,$symb)=split("\0",$res);
   29: 	     my $escsymb=&Apache::lonnet::escape($symb);
   30: 	     my $title = 
   31: 		 ($symb ne 'course') ? &Apache::lonnet::gettitle($symb)
   32: 	                             : $env{'course.'.$env{'request.course.id'}.'.description'};
   33: 	     my $time=&Apache::lonlocal::locallocaltime($times{$res});
   34: 	     my $description="<a href='/adm/navmaps?postsymb=".&Apache::lonnet::escape($symb)."'>$title</a> on $time";
   35: 	     push(@{$state->{CHOICES}},[$description,$escsymb]);
   36: 	 }
   37:       </exec>
   38:     </choices>
   39:   </state>
   40: 
   41:   <state name="ConfirmStu">
   42:     <message nextstate="FinishStu">
   43:        <message_text>Will remove access times from user <ul></message_text>
   44:     </message>
   45:     <eval>
   46:         my ($uname,$udom,undef,$fullname)=split(':',$helper->{'VARS'}{'stu1'});
   47:         if (!$fullname) { $fullname="$uname\@$udom"; }
   48:         return '<li>'.$fullname.'</li>';
   49:     </eval>
   50:     <message><message_text></ul> for <ul></message_text></message>
   51:     <eval>
   52: 	my $list;
   53: 	my @symbs=split(/\|\|\|/,$helper->{'VARS'}{'delete'});
   54: 	foreach my $escsymb (@symbs) {
   55: 	    my $symb=&Apache::lonnet::unescape($escsymb);
   56: 	    my $title = 
   57: 		($symb ne 'course') ? &Apache::lonnet::gettitle($symb)
   58: 	                            : $env{'course.'.$env{'request.course.id'}.'.description'};
   59: 	    $list.='<li>'.$title.'</li>';
   60: 	}
   61: 	return $list;
   62:     </eval>
   63:   </state>
   64: 
   65:   <state name="FinishStu" title="Processing">
   66:     <final>
   67:       <finalcode>
   68:         if ($helper->{'STATE'} ne 'FinishStu') { return; }
   69:         my $result;
   70:         my $courseid=$env{'request.course.id'};
   71:         my ($uname,$udom,$sec,$fullname)=split(':',$helper->{'VARS'}{'stu1'});
   72:         &Apache::lonnet::logthis($helper->{'VARS'}{'delete'});
   73:         my $needsdeval;
   74:         foreach my $escsymb (split(/\|\|\|/,$helper->{'VARS'}{'delete'})) {
   75: 	    my $symb=&Apache::lonnet::unescape($escsymb);
   76:             my $key = "$courseid\0$symb";
   77:             my $title =    
   78:                 ($symb ne 'course') ? &Apache::lonnet::gettitle($symb)
   79:                                     : $env{'course.'.$courseid.'.description'};
   80: 	    my $res=&Apache::lonnet::del('firstaccesstimes',
   81: 					 [$key],$udom,$uname);
   82:             $result.="Removing access time from ".
   83:                       $title.": ".$res.'</li><li>';
   84:             if ($res eq 'ok') {
   85:                 if ($symb ne 'course') {
   86:                     my $what = [];
   87:                     my ($storeunder,@recurseup,$recursed);
   88:                     my $mapp = &Apache::lonnet::deversion((
   89:                                    &Apache::lonnet::decode_symb($symb))[2]);
   90:                     if ($symb =~ /\.(page|sequence)$/) {
   91:                         $storeunder = $env{'request.course.id'}.'.'.$mapp.'___(all).0.interval';
   92:                         $what = [$storeunder,'map'];
   93:                     } else {
   94:                         $storeunder = $env{'request.course.id'}.'.'.$symb.'.0.interval';
   95:                         $what = [$storeunder,'resource'];
   96:                     }
   97:                     &Apache::lonnet::del('timerinterval',[$key],$udom,$uname);
   98:                     my $userreply=&Apache::lonnet::resdata($uname,$udom,'user',$mapp,
   99:                                                            \$recursed,\@recurseup,
  100:                                                            $env{'request.course.id'},
  101:                                                            '.','0.interval',($what));
  102:                     if (ref($userreply) eq 'ARRAY') {
  103:                         if ($userreply->[0] =~ /^\d+$/) {
  104:                             if (($userreply->[1] eq 'map') || ($userreply->[1] eq 'resource')) {
  105:                                 my %storecontent=($storeunder         => $userreply->[0],
  106:                                                   $storeunder.'.type' => 'date_interval');
  107:                                 if (&Apache::lonnet::del
  108:                                        ('resourcedata',[keys(%storecontent)],$udom,$uname) eq 'ok') {
  109:                                     &Apache::lonparmset::log_parmset(\%storecontent,1,$uname,$udom);
  110:                                     $needsdeval = 1;
  111:                                 }
  112:                             }
  113:                         }
  114:                     }
  115:                 }
  116:             }
  117: 	}
  118:         if ($needsdeval) {
  119:             &Apache::lonnet::devalidateuserresdata($uname,$udom);
  120:         }
  121:         $result=~s/<li>$//;
  122:         return $result;
  123:       </finalcode>
  124:       <exitpage>/adm/flip?postdata=return:</exitpage>
  125:     </final>
  126:   </state>
  127: 
  128:   <state name="Class">
  129:     <message nextstate="SelectMap">
  130:     </message>
  131:     <student variable='stu1' coursepersonnel='true' activeonly='true' multichoice='true' />
  132:   </state>
  133: 
  134:   <state name="SelectMap" title="Select a folder/map">
  135:     <resource variable="res2" includecourse="true">
  136:       <filterfunc>return (($res->is_map() && $res->map_contains_problem()) 
  137:                           ||$res->is_problem() );</filterfunc>
  138:       <valuefunc>return $res->symb()</valuefunc>
  139:       <nextstate>ShowPlan</nextstate>
  140:     </resource>    
  141:   </state>
  142: 
  143:   <state name="ShowPlan" title="Processing">
  144:     <message nextstate="FINISH"><message_text>Will remove access times for <ul></message_text></message>
  145: 
  146:     <eval>
  147: 	return '<li>'.&Apache::lonnet::gettitle($helper->{'VARS'}{'res2'}).'</li>';
  148:     </eval>
  149:     <message><message_text></ul> from users <ul></message_text></message>
  150:     <eval>
  151: 	my $list;
  152: 	my @names=split(/\|\|\|/,$helper->{'VARS'}{'stu1'});
  153: 	foreach my $name (@names) {
  154: 	    my ($uname,$udom,$sec,$fullname)=split(':',$name);
  155: 	    if (!$fullname) { $fullname="$uname\@$udom"; }
  156: 	    $list.='<li>'.$fullname.'</li>';
  157: 	}
  158: 	return $list;
  159:     </eval>
  160:   </state>
  161: 
  162:   <state name="FINISH" title="Processing">
  163:       <final>
  164:         <finalcode>
  165:         if ($helper->{'STATE'} ne 'FINISH') { return; }
  166:         my $result;
  167:         my $symb=$helper->{'VARS'}{'res2'};
  168:         my $key=$env{'request.course.id'}."\0".$symb;
  169: 	my @names=split(/\|\|\|/,$helper->{'VARS'}{'stu1'});
  170:         my $what = [];
  171:         my ($storeunder,@recurseup,$recursed);
  172:         my $mapp = &Apache::lonnet::deversion((
  173:                        &Apache::lonnet::decode_symb($symb))[2]);
  174:         if ($symb =~ /\.(page|sequence)$/) {
  175:             $storeunder = $env{'request.course.id'}.'.'.$mapp.'___(all).0.interval';
  176:             $what = [$storeunder,'map'];
  177:         } else {
  178:             $storeunder = $env{'request.course.id'}.'.'.$symb.'.0.interval';
  179:             $what = [$storeunder,'resource'];
  180:         }
  181:         my %donedeval;
  182: 	foreach my $name (@names) {
  183: 	    my ($uname,$udom,$sec,$fullname)=split(':',$name);
  184: 	    if (!$fullname) { $fullname="$uname\@$udom"; }
  185: 	    my %times=&Apache::lonnet::get('firstaccesstimes',
  186: 					   [$key],$udom,$uname);
  187: 	    if (!$times{$key}) {
  188: 		$result.="No Access times found for student ".$fullname;
  189: 	    } else {
  190: 		$result.="Removing access times ".
  191: 		    &Apache::lonlocal::locallocaltime($times{$key}).
  192: 		    " found for student ".$fullname.": ";
  193: 		my $delres=&Apache::lonnet::del('firstaccesstimes',
  194: 					      [$key],$udom,$uname);
  195:                 $result.=$delres;
  196:                 if ($delres eq 'ok') {
  197:                     &Apache::lonnet::del('timerinterval',
  198:                                          [$key],$udom,$uname);
  199:                     my $userreply=&Apache::lonnet::resdata($uname,$udom,'user',$mapp,
  200:                                                            \$recursed,\@recurseup,
  201:                                                            $env{'request.course.id'},
  202:                                                            '.','0.interval',($what));
  203:                     if (ref($userreply) eq 'ARRAY') {
  204:                         if ($userreply->[0] =~ /^\d+$/) {
  205:                             if (($userreply->[1] eq 'map') || ($userreply->[1] eq 'resource')) {
  206:                                 my %storecontent=($storeunder         => $userreply->[0],
  207:                                                   $storeunder.'.type' => 'date_interval');
  208:                                 if (&Apache::lonnet::del
  209:                                        ('resourcedata',[keys(%storecontent)],$udom,$uname) eq 'ok') {
  210:                                     &Apache::lonparmset::log_parmset(\%storecontent,1,$uname,$udom);
  211:                                     unless ($donedeval{$uname.':'.$udom}) {
  212:                                         &Apache::lonnet::devalidateuserresdata($uname,$udom);
  213:                                         $donedeval{$uname.':'.$udom} = 1;
  214:                                     }
  215:                                 }
  216:                             }
  217:                         }
  218:                     }
  219:                 }
  220: 	    }
  221: 	    $result.="</li>\n<li>";
  222: 	}
  223:         $result=~s/<li>$//;
  224:         return $result;
  225:         </finalcode>
  226:       <exitpage>/adm/flip?postdata=return:</exitpage></final>
  227:   </state>
  228: </helper>

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