This file is indexed.

/usr/share/perl5/AMC/Export.pm is in auto-multiple-choice-common 1.2.1-3build1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
#
# Copyright (C) 2009-2013 Alexis Bienvenue <paamc@passoire.fr>
#
# This file is part of Auto-Multiple-Choice
#
# Auto-Multiple-Choice is free software: you can redistribute it
# and/or modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation, either version 2 of
# the License, or (at your option) any later version.
#
# Auto-Multiple-Choice is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Auto-Multiple-Choice.  If not, see
# <http://www.gnu.org/licenses/>.

package AMC::Export;

use AMC::Basic;
use AMC::Data;
use AMC::NamesFile;
use AMC::Messages;

@ISA=("AMC::Messages");

use_gettext;

my %sorting=('l'=>['n:student.line'],
	     'm'=>['n:mark','s:student.name','n:student.line'],
	     'i'=>['n:student','n:copy','n:student.line'],
	     'n'=>['s:student.name','n:student.line'],
	    );

sub new {
    my $class = shift;
    my $self  = {
	'fich.datadir'=>'',
	'fich.noms'=>'',

	'noms'=>'',

	'noms.encodage'=>'',
	'noms.separateur'=>'',
	'noms.useall'=>1,
	'noms.postcorrect'=>'',
	'noms.abs'=>'ABS',
	'noms.identifiant'=>'',

	'out.rtl'=>'',

	'sort.keys'=>['s:student.name','n:student.line'],

	'marks'=>[],

	'messages'=>[],
    };
    bless ($self, $class);
    return $self;
}

sub set_options {
    my ($self,$domaine,%f)=@_;
    for(keys %f) {
	my $k=$domaine.'.'.$_;
	if(defined($self->{$k})) {
	    debug "Option $k = $f{$_}";
	    $self->{$k}=$f{$_};
	} else {
	    debug "Unusable option <$domaine.$_>\n";
	}
    }
}

sub opts_spec {
    my ($self,$domaine)=@_;
    my @o=();
    for my $k (grep { /^$domaine/ } (keys %{$self})) {
	my $kk=$k;
	$kk =~ s/^$domaine\.//;
	push @o,$kk,$self->{$k} if($self->{$k});
    }
    return(@o);
}

sub load {
    my ($self)=@_;
    die "Needs data directory" if(!-d $self->{'fich.datadir'});

    $self->{'_data'}=AMC::Data->new($self->{'fich.datadir'});
    $self->{'_scoring'}=$self->{'_data'}->module('scoring');
    $self->{'_assoc'}=$self->{'_data'}->module('association');

    if($self->{'fich.noms'} && ! $self->{'noms'}) {
	$self->{'noms'}=AMC::NamesFile::new($self->{'fich.noms'},
					    $self->opts_spec('noms'),
					   );
    }
}

sub question_group {
  my ($self,$question)=@_;
  if($question->{title} =~ /^([^:]+):/) {
    return($1);
  } else {
    return(undef);
  }
}

sub group_sum_q {
  my ($self,%g)=@_;
  return({question=>-1,%g,
	  title=>"<".$g{group_sum}.">"});
}

sub insert_groups_sum_headers {
  my ($self,@questions)=@_;
  if($self->{'out.groupsums'}) {
    my %group=();
    my @r=();
    for my $q (@questions) {
      my $g=$self->question_group($q);
      $q->{group}=$g if(defined($g));

      if(defined($g) && $g eq $group{group_sum}) {
	$group{indic0}=1 if($q->{indic0});
	$group{indic1}=1 if($q->{indic1});
	$group{n}++;
      } else {
	push @r,$self->group_sum_q(%group) if(defined($group{group_sum}));
	%group=(group_sum=>$g,n=>1,
		indic0=>$q->{indic0},indic1=>$q->{indic1});
      }
      push @r,$q;
    }
    push @r,$self->group_sum_q(%group) if(defined($group{group_sum}));
    return(@r);
  } else {
    return(@questions);
  }
}

sub test_indicative {
  my ($self,$question)=@_;
  for my $state (0,1) {
    $question->{'indic'.$state}=1
      if($self->{'_scoring'}->one_indicative($question->{question},$state));
  }
}

sub codes_questions {
  my ($self,$codes,$questions,$plain)=@_;
  @$codes=$self->{'_scoring'}->codes();
  if($plain) {
    my $codes_re="(".join("|",map { "\Q$_\E" } @$codes).")";
    @$questions=grep { $_->{'title'} !~ /^$codes_re\.[0-9]+$/ }
      $self->{'_scoring'}->questions;
  } else {
    @$questions=$self->{'_scoring'}->questions;
  }
  for(@$questions) { $self->test_indicative($_); }
  @$questions=$self->insert_groups_sum_headers(@$questions);
}

sub pre_process {
    my ($self)=@_;

    $self->{'sort.keys'}=$sorting{lc($1)}
      if($self->{'sort.keys'} =~ /^\s*([lmin])/i);
    $self->{'sort.keys'}=[] if(!$self->{'sort.keys'});

    $self->load();

    $self->{'_scoring'}->begin_read_transaction('EXPP');

    my $lk=$self->{'_assoc'}->variable('key_in_list');
    my %keys=();
    my @marks=();
    my @post_correct=$self->{'_scoring'}->postcorrect_sc;

    # Get all students from the marks table

    my $sth=$self->{'_scoring'}->statement('marks');
    $sth->execute;
  STUDENT: while(my $m=$sth->fetchrow_hashref) {
      next STUDENT if((!$self->{'noms.postcorrect'}) &&
		      $m->{student}==$post_correct[0] &&
		      $m->{'copy'}==$post_correct[1]);

      $m->{'abs'}=0;
      $m->{'student.copy'}=studentids_string($m->{'student'},$m->{'copy'});

      # Association key for this sheet
      $m->{'student.key'}=$self->{'_assoc'}->get_real($m->{'student'},$m->{'copy'});
      $keys{$m->{'student.key'}}=1;

      # find the corresponding name
      my ($n)=$self->{'noms'}->data($lk,$m->{'student.key'});
      if($n) {
	$m->{'student.name'}=$n->{'_ID_'};
	$m->{'student.line'}=$n->{'_LINE_'};
	$m->{'student.all'}={%$n};
      } else {
	for(qw/name line/) {
	  $m->{"student.$_"}='?';
	}
      }
      push @marks,$m;
    }

    # Now, add students with no mark (if requested)

    if($self->{'noms.useall'}) {
      for my $i ($self->{'noms'}->liste($lk)) {
	if(!$keys{$i}) {
	  my ($name)=$self->{'noms'}->data($lk,$i);
	  push @marks,
	    {'student'=>'',
	     'copy'=>'',
	     'student.copy'=>'',
	     'abs'=>1,
	     'student.key'=>$name->{$lk},
	     'mark'=>$self->{'noms.abs'},
	     'student.name'=>$name->{'_ID_'},
	     'student.line'=>$name->{'_LINE_'},
	     'student.all'=>{%$name},
	    };
	}
      }
    }

    # sorting as requested

    debug "Sorting with keys ".join(", ",@{$self->{'sort.keys'}});
    $self->{'marks'}=[sort { $self->compare($a,$b); } @marks];

    $self->{'_scoring'}->end_transaction('EXPP');

}

sub compare {
    my ($self,$xa,$xb)=@_;
    my $r=0;

    for my $k (@{$self->{'sort.keys'}}) {
	my $key=$k;
	my $mode='s';

	if($k =~ /^([ns]):(.*)/) {
	  $mode=$1;
	  $key=$2;
	  if($mode eq 'n') {
	    $r=$r || ( $xa->{$key} <=>
		       $xb->{$key} );
	  } else {
	    $r=$r || ( $xa->{$key} cmp
		       $xb->{$key} );
	  }
	}
    }
    return($r);
}

sub export {
    my ($self,$fichier)=@_;

    debug "WARNING: Base class export to $fichier\n";
}

1;