Subversion Repositories wimsdev

Rev

Rev 11479 | Rev 13646 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
11931 schaersvoo 1
#!/usr/bin/perl
7710 bpr 2
use strict "vars";
3
use strict "subs";
8974 bpr 4
use search ('hashdomain', 'treate_dict', 'sortuniq', 'out', 'canonify', 'reverse_dic', 'treate_language');
7710 bpr 5
 
7709 bpr 6
use locale;
7
use warnings;
8575 bpr 8
my $LANG='fr';
7709 bpr 9
## leave simple quotes
10
my $joker='$wims_name_erase';
8590 bpr 11
my $outputtaxo='../../modules/';
7713 bpr 12
my $ddir='taxonomy';
8575 bpr 13
my $indexdir="../classification";
8633 bpr 14
my $sheetdir="../sheet";
8685 bpr 15
my $moduledir="../site";
8635 bpr 16
my ($module,$option)=('','');
7709 bpr 17
while ($_ = shift (@ARGV))
18
{
19
  last if (!/^--/);
7710 bpr 20
  if (/^--lang=(.*)$/) { $LANG = $1; }
21
  elsif (/^--joker=(.*)$/) { $joker = $1; }
8578 bpr 22
  elsif (/^--module=(.*)$/) { $module = $1; }
8618 bpr 23
  elsif (/^--option=(.*)$/) { $option = $1; }
8590 bpr 24
  elsif (/^--output=(.*)$/) { $outputtaxo = "$outputtaxo/$1"; }
7709 bpr 25
}
7700 bpr 26
 
8974 bpr 27
exit if (!(grep {$_ eq $LANG} treate_language()));
28
 
8618 bpr 29
#### wims keywords
8887 bpr 30
sub underscore { my ($a)=@_ ; $a=~ s/\_/ /g ; $a; }
9070 bpr 31
## hack for suffix
9205 bpr 32
sub suffix { my ($a)=@_ ; $a=~ s/(e|s|l|r)\b//; $a; }
9070 bpr 33
 
8887 bpr 34
sub count { my ($file)=@_ ;
35
 my $refcount={};
36
  open INC, "$file";
37
  while (<INC>){
38
   if (/^(.*):(.*)/) { my @L=split(' ', $2) ; $refcount->{$1}=$#L+1 }
39
  };
40
  close INC;
41
  $refcount
42
}
8995 bpr 43
 
8618 bpr 44
if ($option) {
8995 bpr 45
 my $refcount= count("$moduledir/A.$LANG");
8887 bpr 46
 ## initialisation, will not change
8618 bpr 47
 my %refw = hashdomain('domain/domain') ; my $refw=\%refw;
48
 my %titw = treate_dict ("domain/domain.$LANG"); my $titw=\%titw;
8887 bpr 49
 my (%Next); for my $a (keys %{$refw->{'next'}}) { $Next{$a}=$refw->{'next'}{$a}; }
50
 
51
 my $Tw;
52
 for my $taxo (split(',',$Next{'domain'})){
8974 bpr 53
   if ( !(defined $titw{$taxo})) { $titw{$taxo}=$taxo} ;
9307 obado 54
   $Tw = "!! This file is generated by taxo.pl. Do not modify directly.\n!set lang_exists=yes\n"
8618 bpr 55
     . '<a class="wims_button float_right" onclick="treeToggleAll(\'#tree_'.$taxo.'\');">$name_fold</a>'
8639 bpr 56
     . "\n!set title= $titw{$taxo}\n<h2>$titw{$taxo}<\/h2>\n"
8618 bpr 57
     . '<ul id="tree_' .$taxo.'" class="tree">';
8995 bpr 58
  One ($Next{$taxo}, $refcount, $taxo, $taxo);
8631 bpr 59
  $Tw .= "\n</ul>";
8618 bpr 60
 
8995 bpr 61
  sub One { my ($t, $refcount, $taxo, $chemin) = @_;
8887 bpr 62
    return if (!$t);
63
    for my $tt (split(',', $t)) {
9307 obado 64
      $Tw .= "<li \n".
8988 obado 65
      "!if $tt notitemof \$parm\n".
66
      " class=\"closed\"\n".
67
      "!endif\n".
68
      ">\n";
8618 bpr 69
      my $tt0=$titw->{$tt};
8974 bpr 70
      if(!$tt0) { $tt0=$tt ; # print $tt ."\n" ;
71
      };
8996 bpr 72
      my $chemin1 .= "$chemin,$tt" ;
8887 bpr 73
      my $cc='';
74
      my $tt1=underscore($tt);
9070 bpr 75
      my $T;
76
      if(defined($refcount->{$tt1})) {  $T=$refcount->{$tt1}}
77
        else { if (defined($refcount->{suffix($tt1)})) { $T= $refcount->{suffix($tt1)}}};
9081 obado 78
      if ($T) { $cc="<sup class=\"pastille taxo_nb_elem\">". $T."</sup>" };
8906 obado 79
      $Tw .= "<span class=\"tree_icon\" id=\"$tt\">$tt0</span><span class=\"small hidden\">($tt)</span>$cc\n"
8922 obado 80
          . "!set key=$tt0\n";
9070 bpr 81
     # if ($T) {$Tw .= '!href $search_addr&parm=' . "$tt&browse_parm=$chemin1 &#128270; \$wims_name_search\n";}
82
      $Tw .= '!href $search_addr&parm=' . "$tt&browse_parm=$chemin1 &#128270; \$wims_name_search\n";
8922 obado 83
      $Tw .=  "<ul id=\"list_$tt\">";
8996 bpr 84
      One($Next{$tt}, $refcount,$taxo, $chemin1);
8887 bpr 85
      $Tw .= "\n</ul>";
86
    }
87
    $Tw .= "\n</li>";
8618 bpr 88
 }
8631 bpr 89
 out("$outputtaxo/taxo/$taxo.phtml.$LANG", $Tw);
90
 }
8618 bpr 91
 exit;
92
}
93
####
8886 bpr 94
## will not be modified in the subroutines
8974 bpr 95
## LANG here must be a language for the moment
8650 bpr 96
my %titsheet = treate_dict ("$sheetdir/index/tit.$LANG"); my $titsheet=\%titsheet;
8685 bpr 97
my %addr = reverse_dic ("$moduledir/addr"); my $addr=\%addr;
8884 bpr 98
my %titmodule = treate_dict ("$moduledir/title");my $titmodule=\%titmodule;
9294 bpr 99
my %filetoread=('mathematics'=> 'unisciel',
100
'physics'=> 'unisciel',
101
'biology'=> 'unisciel',
102
'chemistry'=> 'unisciel',
103
'informatics' => 'unisciel',
104
'ecogestion' => 'ecogestion',
9295 bpr 105
'geoscience' => 'unisciel',
9294 bpr 106
);
8886 bpr 107
 
8990 bpr 108
for my $t (glob("$ddir/*.$LANG")) {
109
  $t =~ s,$ddir\/,,g;
110
  my @t_=split('\.',$t); next if !($t_[1] eq $LANG);
9290 bpr 111
  next if $t_[0] eq 'commoncore';
9294 bpr 112
  taxonomy($t_[0], $filetoread{$t_[0]}, $LANG, '_','_');
8990 bpr 113
}
7710 bpr 114
 
8886 bpr 115
## impose order in the list
116
my $ccsstitle='CCSS.Math.Content_'; my @list=();
117
for my $l ('K','1','2','3','4','5','6','7','HS') { push @list, "$ccsstitle$l" }
7700 bpr 118
 
9294 bpr 119
taxonomy ('commoncore', 'commoncore', $LANG, '_','_',@list);
8886 bpr 120
 
9294 bpr 121
sub taxonomy { my ($taxo, $taxo2, $lang, $sep1, $sep2, @list ) = @_ ;
9130 bpr 122
   my $vu={}; my $ref; my $desctaxo;
8884 bpr 123
   my ($title, $desc, $tit) = hashtaxo("$ddir/$taxo.$lang", $sep1, $sep2);
9130 bpr 124
   my @title_ = split(',', $title);
125
   ($title,$desctaxo)=@title_;
126
   if (!(defined $desctaxo)) { $desctaxo='' };
9296 bpr 127
   if ($module) { $ref=hashresultat("$indexdir/$taxo2","$indexdir/$taxo2" . "_sheet", $tit); }
7710 bpr 128
   my ($T);
9307 obado 129
   $T = "!! This file is generated by taxo.pl. Do not modify directly.\n!set lang_exists=yes\n";
8599 bpr 130
   $T .= '<a class="wims_button float_right" onclick="treeToggleAll(\'#tree_'.$taxo.'\');">$name_fold</a>';
9130 bpr 131
   $T .= "\n!set title=$title\n!set desctaxo=$desctaxo\n<h2>$title<\/h2>\n";
8594 obado 132
   $T .= '<ul id="tree_'.$taxo.'" class="tree">';
9307 obado 133
   if (!@list) { @list=sort keys %{$desc} };
8884 bpr 134
   for my $a (@list) { $T .= one($a, $taxo, $desc, $tit, $ref, $vu); };
9290 bpr 135
   $T .= "</ul>";
8590 bpr 136
   if (!$module) {
137
     $T .= "<input type=\"radio\" name=\"taxon_$taxo\" id=\"empty\" value=\"\"/> $joker";
138
   }
9307 obado 139
   $T .= "<div class=\"wims_credits\">";
140
   $T .= " <strong>\$wims_name_credits:</strong> <a href=\"$desctaxo\" target=\"_blank\">$desctaxo</a>";
141
   $T .= "</div>";
142
   $T .= "<!-- Reload dynamic tree display -->";
143
   $T .= "<script type=\"text/javascript\" >";
144
   $T .= "autoInit_trees();";
145
   $T .= "</script>";
146
 
147
 
8590 bpr 148
   out("$outputtaxo/$taxo.phtml.$lang", $T);
7700 bpr 149
}
150
 
8575 bpr 151
 
8884 bpr 152
sub one {my ($a, $taxo, $desc, $tit, $ref, $vu)=@_;
153
  return "" if (defined($vu->{$a}));
8943 bpr 154
  $vu->{$a} = 1;
8575 bpr 155
  my @prec=split('_',$a); my $prec0=join('_',@prec[0..$#prec-1]);
8884 bpr 156
  my $amod = $a;
157
  my $T = '<li class="closed">';
8974 bpr 158
  if (!$tit->{$a}) { print "warning $a has no title" ; $tit->{$a}=$a};
8575 bpr 159
  if (!$ref->{'total'}{$a}) { $ref->{'total'}{$a}=0 } ;
9065 bpr 160
  if (!$ref->{'totalexo'}{$a}) { $ref->{'totalexo'}{$a}=0 } ;
8590 bpr 161
  if (!$module) {
162
       $T .= "<input type=\"radio\" name=\"taxon_$taxo\" id=\"$amod\" value=\"$amod\"/>"
9290 bpr 163
          . "<label for=\"$amod\">$tit->{$a}</label><span class=\"small hidden\">($a)</span>";
8590 bpr 164
  } else {
9290 bpr 165
    $T .= "<span class=\"tree_icon\" id=\"$amod\">$tit->{$a}</span><span class=\"small hidden\">($a)</span> ";
8590 bpr 166
    if ($ref->{'total'}{$a} >0){
9081 obado 167
      $T .= "<sup class=\"pastille taxo_nb_modules\">".$ref->{'total'}{$a}." \$name_M</sup>";
8587 obado 168
    }
9065 bpr 169
    if ($ref->{'totalexo'}{$a} >0){
9081 obado 170
      $T .= "<sup class=\"pastille taxo_nb_exo\">".$ref->{'totalexo'}{$a}." \$name_X</sup>";
9065 bpr 171
    }
8594 obado 172
  }
8884 bpr 173
  if ($ref->{'text'}{$a} || $desc->{$a}){
8594 obado 174
    $T .="<ul id=\"list_$amod\">";
9357 bpr 175
    if ($ref->{'text'}{$a}){ $T .= $ref->{'text'}{$a}; }
176
    if ($ref->{'sheet'}{$a}){ $T .= $ref->{'sheet'}{$a}; }
8884 bpr 177
    if ($desc->{$a}) {
178
      for my $b (sortuniq (split ',', $desc->{$a})) { $T .= one($b, $taxo, $desc, $tit, $ref, $vu) };
8594 obado 179
    }
9290 bpr 180
    $T .= "</ul>";
7710 bpr 181
  }
9296 bpr 182
  $T . "</li>\n";
7700 bpr 183
}
184
 
185
sub hashtaxo { my ($file, $sep1, $sep2)=@_;
8884 bpr 186
  my (%desc, %tit, $title);
7710 bpr 187
  open IN, "$file";
188
  while (<IN>) {
7700 bpr 189
##la premiere ligne est le titre !
7710 bpr 190
    if (!$title) { $title=$_; next}
191
    my ($t0,$t1) = split(":", $_);
192
    my @index = split("$sep1", $t0);
193
    my $cnt = $#index;
194
    foreach my $a (2..$cnt) {
195
      $desc{join($sep2, @index[0..$a-1])} .= join($sep2, @index[0..$a]) . ",";
7709 bpr 196
    }
9130 bpr 197
    if ($t1) { $t1 =~ s/\n//; $tit{$t0} = $t1;}
7709 bpr 198
  }
7710 bpr 199
  close IN;
8884 bpr 200
  ($title, \%desc, \%tit)
7700 bpr 201
}
202
 
8884 bpr 203
sub hashresultat { my ($file, $filesheet, $tit)=@_;
204
  my %ref;
8575 bpr 205
  open IN, "$file";
206
  while (<IN>){
207
    my @ligne=split(':', $_);
208
    next if (!$ligne[0]);
8630 bpr 209
    my @aa=sortuniq(split(',', $ligne[1]));
8575 bpr 210
    my $cnt0=$#aa+1;
9065 bpr 211
    my $cntexo=0;
8575 bpr 212
    for my $a (@aa) {
213
      chomp $a;
214
      my $b = $a; $b =~ s!/!~!g;
8943 bpr 215
      if (!defined($addr{$a})) {print "warning: module $a does not exist on the server\n"; next};
8884 bpr 216
      if (!$titmodule->{$addr{$a}}) { print "$a\n" ; $titmodule->{$a}=$a};
9066 bpr 217
      my $bb= ($titmodule->{$addr{$a}}) ? $titmodule->{$addr{$a}} . "<span class=\"small hidden\">($b)</span>": $b;
9285 obado 218
      my @exo; my $nb=1; my %exos_dic;
8619 bpr 219
      if (-e "../../modules/$a/Extitles") {
9285 obado 220
        %exos_dic=treate_dict("../../modules/$a/Extitles");
221
        @exo= values %exos_dic;
9066 bpr 222
        $nb=$#exo;
223
      };
224
      ##jmevers test
225
      open INN, "../../modules/$a/INDEX";
226
      my $testjm=0;
227
      while (<INN>) { $testjm=1 if ($_=~ /authors\/jm.evers\/proc\/var.def/);} close INN;
228
      if ($testjm){
229
         my @nbexo=`ls ../../modules/$a/exos/exo*`;
230
         $nb=$#nbexo+1;
231
        ###TODO; creer @exo comme dans le cas OEF (liste des titres des exos)
232
      }
233
      if (@exo) {
234
        $nb=$#exo+1;
8884 bpr 235
        $ref{'text'}{$ligne[0]} .="<li class=\"taxo_module closed\">\n" .
9066 bpr 236
        "<span class=\"tree_icon\">$bb</span>"
9081 obado 237
        . ($nb>1?"<sup class=\"pastille taxo_nb_exo\">$nb \$name_X</sup>":"" )
9066 bpr 238
        . "\n!set wims_ref_class=wims_button\n".
8906 obado 239
        "!href target=wims_internal module=$a &rArr;\n" .
9285 obado 240
        '<ul class="smaller">';
241
        foreach my $exo_id (keys %exos_dic) {
9307 obado 242
          $ref{'text'}{$ligne[0]} .='<li rel="'.$exo_id.'">'.$exos_dic{$exo_id}."</li>\n";
243
          #$ref{'text'}{$ligne[0]} .='<li>'.$exos_dic{$exo_id}."</li>";
9285 obado 244
        }
245
        $ref{'text'}{$ligne[0]} .="</ul></li>\n";
9066 bpr 246
        $cntexo += $nb ;
8770 obado 247
      }
248
      else {
8884 bpr 249
        $ref{'text'}{$ligne[0]} .="<li class=\"taxo_module\">\n" .
9066 bpr 250
        "!href target=wims_internal module=$a $bb\n"
251
        . ($nb>1?"<sup class=\"taxo_nb_exo\">$nb</sup>":"" )
9296 bpr 252
        . "</li>\n";
9066 bpr 253
        $cntexo += $nb ;
8770 obado 254
      }
8575 bpr 255
    }
8884 bpr 256
    $ref{'num'}{$ligne[0]}=$cnt0;
9065 bpr 257
    $ref{'numexo'}{$ligne[0]}=$cntexo;
8884 bpr 258
    $ref{'total'}{$ligne[0]}=0;
9065 bpr 259
    $ref{'totalexo'}{$ligne[0]}=0;
8575 bpr 260
  }
8633 bpr 261
  close IN;
262
  if (-e "$filesheet") {
263
   open IN, "$filesheet";
264
   while (<IN>){
265
    my @ligne=split(':', $_);
266
    next if (!$ligne[0]);
267
    my @aa=sortuniq(split(',', $ligne[1]));
268
    my $cnt0=$#aa+1;
269
    for my $a (@aa) {
270
      chomp $a;
271
      my $b = canonify($a);
9290 bpr 272
      if($titsheet->{$b}) { $b = $titsheet->{$b} . "<span class=\"small hidden\">($b)</span>" } else { $b =~ s!/!~!g;}
8884 bpr 273
      $ref{'sheet'}{$ligne[0]} .="<li class=\"taxo_module\">\n"
9290 bpr 274
   . "!href target=wims_internal module=adm/sheet\&+job=read\&+sh=$a $b\n</li>";
8633 bpr 275
      }
8884 bpr 276
   $ref{'numsheet'}{$ligne[0]}=$cnt0;
8633 bpr 277
   }
278
  }
8943 bpr 279
   my @modlist=sortuniq(keys %{$tit});
8577 bpr 280
   for my $id (@modlist) {
281
     my @ok = grep {/^${id}_/} @modlist;
282
     push @ok, $id;
283
     for my $c (@ok) {
8884 bpr 284
      if (!$ref{'num'}{$c}){ $ref{'num'}{$c}=0};
9065 bpr 285
      if (!$ref{'numexo'}{$c}){ $ref{'numexo'}{$c}=0};
8884 bpr 286
      if (!$ref{'numsheet'}{$c}){ $ref{'numsheet'}{$c}=0};
287
       $ref{'total'}{$id} += $ref{'num'}{$c} + $ref{'numsheet'}{$c} ;
9065 bpr 288
       $ref{'totalexo'}{$id} += $ref{'numexo'}{$c} ;
8575 bpr 289
     }
290
   }
8884 bpr 291
   \%ref;
8575 bpr 292
}
8887 bpr 293