Subversion Repositories wimsdev

Rev

Rev 16874 | Rev 17905 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

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