Subversion Repositories wimsdev

Rev

Rev 17905 | Blame | Compare with Previous | Last modification | View Log | RSS feed

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