<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
  <HEAD>
    <TITLE>Liste de projects STAF-18 (EVA) déposées (14-Jun-1999)</TITLE>
    <!-- Created by: D.K.S., 02-Jun-1999 -->
<!-- Changed by: D.K.S., 14-Jun-1999 -->

<!-- A FAIRE:

- autre metres
- possibilité de voir juste un extrait
- indiquer des "new" quand il y a du new (coordonner avec le fichier XSL)
- possibilité de faire certaines annotations (plus tard ca)
- Interface NNTP pour lire les derniers news http://px.sklar.com/section.html?section_id=5

 -->

  </HEAD>
  <BODY>
    <H1>Liste de projects <A HREF="http://tecfa.unige.ch/tecfa/teaching/staf18/staf18-overview.html">STAF-18</A> (EVA) déposées</H1>

<?php

// Parameters for files, directories and URLs we use

$project_dir "/web/staf/staf-e/staf18/proj/";
$xml_path "http://tecfa2.unige.ch/staf/staf-e/staf18/proj/";
$xml_source_path "http://tecfa2.unige.ch/staf/staf-e/staf18/proj/";
$xml_servlet "http://tecfa2.unige.ch:8080/servlet/XSLatorServlet";
$style_sheet "http://tecfa2.unige.ch/staf/staf-e/staf18/project.xsl";
$style_sheet2 "http://tecfa2.unige.ch/staf/staf-e/staf18/project2.xsl";


// other globals (commented, since no need to init)
# $stack = array();
# $astack = array();
# $pointer = 0;
# $apointer = 0;




// ---------------- Utils
// 'Pops' off and returns the last element of $array. By 
// doing so, the size of $array is reduced by 1.
// Adapted from Harding Shay (mekla@geocities.com)

function pop(&$array) {
  if (!
is_array($array)){ return; }
  
$variable $array[count($array)-1];
  unset(
$array[count($array)-1]);
  return 
$variable;
}


function 
push(&$array,$variable) {
  
$array[count($array)] = $variable;
  return 
count($array);
}



// ---------------- XML Parsing. We get some elements out of the files


// The next 2 are for debugging
function stack_printer ($el) {
  echo 
"$el ";
}
function 
show_stack ($indent) {
  global 
$stack;
  global 
$astack;
  global 
$pointer;
  global 
$apointer;
  global 
$current;

  echo 
"$indent\n";
  
array_walk ($stack'stack_printer');  
  
// echo "Current attrs : ";
  // array_walk ($astack[$apointer], 'stack_printer');  
  // echo "<br>\n";
}


// ----------------------------- XML Comparison

function is_parent ($maman) {
  global 
$stack;
  global 
$pointer;
  
  if (
$pointer == 0) {
    return 
FALSE;
  }
  if (
$stack[$pointer-1] == $maman) {
    return 
TRUE;
  }
  else {
    return 
FALSE;
  }
}

// ----------------------------- contents
// for each thing we want to do we define a function


class Results {
  var 
$tot_completion_days;
  var 
$tot_man_days;
  var 
$wp_completion;
  var 
$project_title;
  var 
$names;
  var 
$spec_approval;
  var 
$n_problems 0;
  var 
$open_problems 0;
  var 
$problems_with_answers 0;
  var 
$problems_with_comments 0;
  var 
$audits "";

  function 
do_planning($attrs) {
    global 
$stack$astack;
    global 
$pointer$apointer$current;
    if ( (
$current == "planning") && is_parent ("workpackage")) {
      
$completion $attrs["completion"];
      
$man_days $attrs["man-days"];
      
// echo "DEBUG: attrs = $attrs, completion = $completion, man_days= $man_days <br>\n";
      
if ($man_days) {
    
$this->wp_completion[] = $completion;
    if ( 
$man_days != "") {
      
$this->tot_man_days += $man_days;
      
$this->tot_completion_days += $man_days $completion 100;
    };
      }
      else {
    
$this->wp_completion[] = "MANQUE";
      }

    }
  }

  function 
do_names ($attrs) {
    global 
$current;

    if (
$current == "contact-info") {
      
      
$noms $attrs["first-name"] . " <b>" $attrs["family-name"] . "</b>";
      if (
$noms) { $this->names $this->names $noms; };

      
$work_url $attrs["work-url"];
      if (
$work_url) { 
    
$this->names $this->names "(<a href=\"$work_url\">Page travaux</a>) ";
      } ;
      
// echo "DEBUG: noms = $noms, work_url = $work_url <br>\n";
    
}
  }
  
  function 
do_spec_approval ($attrs) {
    global 
$current;
    if (
$current == "specification") {
      
$approval $attrs["approval"];
      if (
$approval) {
    
$this->spec_approval "<FONT color=\"#007700\">Avis de l'enseignant sur la spécification</font>: $approval";
      }
      else {
    
$this->spec_approval "<FONT color=\"#007700\">Avis de l'enseignant sur la spécification</font>: manquant (probablement pas bon!)";
      }
    }
  }
  
 function 
do_audits ($attrs) {
   global 
$current;
   if (
$current == "audit") {
     
$eval $attrs["eval"];
     if (
$eval) {
       
$date $attrs["mod-day"] . "/" $attrs["mod-month"] . "/" $attrs["mod-year"];
       
$this->audits $date "=&gt;" $this->audits $eval ;
     }
   }
 }

  function 
do_problems ($attrs) {
    global 
$current;
    if (
$current == "problem") {
      
$this->n_problems += 1;
      
$approval $attrs["open"];
      if (
$approval) {
    
$this->open_problems += 1;
      }
    }
    if (
$current == "solution") {
      
$this->problems_with_answers += 1;
    }
    if ( (
$current == "teacher-comments") && is_parent ("problem")) {
      
$this->problems_with_comments += 1;
    }
  }


  function  
set_title ($title) {
    
$this->project_title $title;
  }
  
  
  
// dump out the results
  
  
function  print_results () {
    
// title
    
echo "Titre: <strong>" $this->project_title "</strong><br>\n";
    
    
// Auteurs
    
echo "Auteurs: " $this->names "<br>";
    
    
// Specification approval
    
echo $this->spec_approval "<br>\n" ;

    
// Avancement (faudrait faire une fonction pour cela)
    
echo "<strong>Avancement:</strong> ";
    
printf ("%01.2f"$this->tot_completion_days $this->tot_man_days 100);
    echo  
"% (" $this->tot_completion_days " jours sur " $this->tot_man_days .")<br>\n";
    echo 
"WPs: ";
    
$i 1;
    while ( list (
$junk$wp) = each $this->wp_completion ) ) {
      echo 
"WP_$i: $wp % ";
      
$i++;
    }
    echo 
"<br>\n";

    
// Audits
    
if ($this->audits) {
      echo 
"<FONT color=\"#007700\"><strong>Audits:</strong></FONT> " $this->audits "<br>\n";
    }
    
// Problems
    
echo "<strong>Problèmes</strong> " $this->n_problems .
      
", ouverts=" $this->open_problems .
      
", solutions=" $this->problems_with_answers .
      
", commentaires=" $this->problems_with_comments;



  }
}

// ----------------------------- The 3 XML Parser functions


// grab current element and push it onto the stack
// push its attributs on the astack

function startElement($parser$name$attrs) {
  global 
$stack$astack;
  global 
$pointer$apointer$current;
  global 
$results;
  
  
$pointer push ($stack$name) -;
  
$apointer push ($astack$attrs) -;
  
// the current element
  
$current $name;
  
// show_stack("\n<li>PUSH ". $current . "<ol> stack=\n");

  // Extract data
  
$results->do_planning($attrs);
  
$results->do_names($attrs);
  
$results->do_spec_approval($attrs);
  
$results->do_problems ($attrs);
  
$results->do_audits ($attrs);
}

// pop off the element from the stack
// pop off the attributes from the astack

function endElement($parser$name) {
  global 
$pointer$apointer;
  global 
$stack$astack$current;
    
  
pop ($stack);
  
pop ($astack);
  
$pointer $pointer 1;
  
$apointer $apointer 1;
  
$current FALSE;
  
// show_stack("</ol>\nPOPPED stack=</li>\n");

}

function 
characterData($parser$data) {
  global 
$pointer$apointer;
  global 
$stack$astack$current;
  global 
$results;


  if ( (
$current == "title") && is_parent ("project"))
    {
      
$results->set_title($data);
    }
}


function 
parse_xml($file) {
  global 
$results;

  
// -------------------- XML Parser INITS

  // create the XML Parser, a new one for each filep
  
$xml_parser xml_parser_create("ISO-8859-1");
  
xml_parser_set_option($xml_parserXML_OPTION_CASE_FOLDINGfalse);
  
xml_set_element_handler($xml_parser,  "startElement",  "endElement");
  
xml_set_character_data_handler($xml_parser,  "characterData");
  
  
// echo "<p>DEBUG: file = $file";
  
if (!($fp fopen($file,  "r"))) {
    die( 
"could not open XML input");
  }
  else {
    
// init per-file global vars
    
$wp_count 0;
  }
  
  while (
$data fread($fp50000)) {
    if (!
xml_parse($xml_parser$datafeof($fp))) {
      die(
sprintf"XML error: %s at line %d",
           
xml_error_string(xml_get_error_code($xml_parser)),
           
xml_get_current_line_number($xml_parser)));
    }
  }
  
// close file and free parser
  
fclose($fp);
  
xml_parser_free($xml_parser);
}

// ----------------------- File stats:


function print_file_stats($file) {
  
$file_info stat($file);
  echo 
"[ ";
  echo 
"uid=$file_info[4], ";
  
$gid $file_info[5];
  echo 
"gid=$gid, ";
  echo 
"size=$file_info[7], ";
  
$date $file_info[9];
  
$unix_date time();
  
setlocale ("LC_TIME""fr");
  
$date_string = (strftime("%A, %d %B %Y, %H:%M"$date));
  echo 
"dernière modif=$date_string";
  echo 
"] <br>\n\n ";
  if (
$gid==1) echo "<b>ATTENTION:</b> Fichier sous édition par DKS! Attendez un peu ... <br>\n";
}



// ----------------------- Main routine: 


if ($projfile
  
// to call like ?projfile=file.xml
{
  
print_file_stats($project_dir.$projfile);
  
// init array that will hold results
  
$results = new Results;
  
// some XML file contents
  
parse_xml($project_dir.$projfile);
}

else 
{
  
// The standard routine
  // gets the files from the xml upload directory

  
$handle=opendir($project_dir);
  
// echo "Directory handle: $handle\n";
  
echo "Projets déposés dans le répertoire : <A HREF=\"$xml_path\">$xml_path</A> <p>\n";
  
  
// read the files into an array
  
$files = array();
  while (
$file readdir($handle)) {
    
$files[] = $file;
  }
  
closedir($handle); 
  
  
// sort them in alphabetical order
  
sort($files);
  
reset($files);
  
  while ( list (
$junk$file) = each ($files) ) {
    
    
$pieces explode("."$file);
    
    if (
$pieces[1] == "xml") {
      
      
// List files
      
$xml_url $xml_path $file;
      
$url $xml_servlet "?xml=" $xml_url "&xsl=" $style_sheet;
      echo 
"<p><A HREF=\"$url\">$file</A>: \n";
      
      
// file stats
      
print_file_stats($project_dir.$file);
      
      
// init the Results class
      
$results = new Results;
      
// Analyse the file
      
parse_xml($project_dir.$file);
      
// print the results
      
$results->print_results ();

    }
    else {
      
// echo "Useless file: $file<br>\n\n";
    
}
  }
}



?>

<hr>

<A HREF="http://tecfa.unige.ch/tecfa/teaching/staf18/pm-eva.html">Gestion de projets</A> | 
<A HREF="http://tecfa.unige.ch/tecfa/teaching/staf18/staf18-overview.html">Retour à STAF-18</A>
<hr>
    <ADDRESS>
      <A NAME="Signature"
     HREF="http://tecfa.unige.ch/tecfa-people/schneider.html">D.K.S.</A>
    </ADDRESS>
  </BODY>
</HTML>