commit 3eab25319338139b00175002a093b3da959a8b4c
Author: Eric Seigne <eric.seigne@ryxeo.com>
Date:   Fri Jun 18 18:43:37 2010 +0200

    listing prenant en compte les dsi / iatice

diff --git a/plugins/anet_epacks/front/plugin_anet_epacks.verif_comptes_dsi.php b/plugins/anet_epacks/front/plugin_anet_epacks.verif_comptes_dsi.php
index 2254953..cd12ba9 100644
--- a/plugins/anet_epacks/front/plugin_anet_epacks.verif_comptes_dsi.php
+++ b/plugins/anet_epacks/front/plugin_anet_epacks.verif_comptes_dsi.php
@@ -37,5 +37,8 @@ print "<p>Corrections faites !</p>\n";
 verif_et_update(5);
 verif_et_update(6);
 
+$query = "UPDATE `glpi_users` SET FK_entities='1' WHERE `FK_entities` = 0 AND email NOT LIKE '%ryxeo.com'";
+$result = $DB->query($query);
+
 commonFooter();
 ?>
diff --git a/plugins/anet_epacks/front/plugin_anet_epacks.view_array_recap.php b/plugins/anet_epacks/front/plugin_anet_epacks.view_array_recap.php
index a4d8ef1..84747b4 100644
--- a/plugins/anet_epacks/front/plugin_anet_epacks.view_array_recap.php
+++ b/plugins/anet_epacks/front/plugin_anet_epacks.view_array_recap.php
@@ -129,66 +129,101 @@ LIMIT 500;";
   return $query;
 }
 
+//Special pour les "dsi" quand on convertis a la vollee les comptes post-only en dsi pour les animtice
+function local_make_query_dsi($data, $entityid, $maintenance) {
+  $query = "SELECT e.*, e.FK_enduser as entityid, g3.name as client, g4.name as serveur, g4.os_license_number, g4.os_license_id, g4.otherserial, ssh.*,
+(g5.nbeleves+g5.nbprofs) as nbusers, g5.nbpc as nbpc
+FROM glpi_plugin_anet_epacks AS e
+LEFT JOIN glpi_plugin_anet_epacks_ssh_max AS ssh ON e.FK_serveur=ssh.FK_serveur
+LEFT JOIN glpi_entities AS g3 ON e.FK_client=g3.ID OR e.FK_enduser=g3.ID
+LEFT JOIN glpi_computers AS g4 ON e.FK_serveur=g4.ID
+LEFT JOIN glpi_plugin_anet_epacks_recencement_max AS g5 ON e.FK_serveur=g5.FK_serveur\n";
+
+  //WHERE e.Fk_Serveur > '0'\n";
+  if($data['name'] == "dsi") {
+    if($maintenance == 0 || $maintenance ==  1) {
+      $query .= "WHERE e.FK_enduser='$entityid' AND e.FK_contract >= '0' AND e.FK_activation > '0'\n";
+    }
+    else if($maintenance == -1) {
+      $query .= "WHERE e.FK_enduser='$entityid' AND e.FK_contract='-1' AND e.FK_activation > '0'\n";
+    }
+    //GROUP BY e.FK_serveur
+    $query .= "GROUP BY e.FK_serveur
+ORDER BY client ASC
+LIMIT 500;";
+  }
+  else {
+    $query = "";
+  }
+
+  //  if($maintenance == -1) {
+  //print $query;
+  //  }
+  return $query;
+}
+
+
+function local_make_raw($q,$maintenance) {
+
+}
+
 
 function local_make_array($q,$maintenance) {
   global $DB;
-  global $DB;
   global $glpiid;
 
+  global $total_nbpc_maint;
+  global $total_nbusers_maint;
+  global $total_nbpc_hors_maint;
+  global $total_nbusers_hors_maint;
+  global $num_debut_ligne;
+  global $tab_deja_affiche;
+
+
   $result = $DB->query($q) or die($DB->error());
-    
-  print "<table style=\"width:100%; padding: 0 10px 0 10px;\">
-<tr class='tab_bg_2'>
-  <th>Nom</th>
-  <th><img src=\"img/stock_channel.png\" alt=\"Télémaintenance (SSH)\" title=\"Télémaintenance (SSH)\"></th>
-  <th>Date du test</th>
-  <th>Adresse DynDNS</th>
-  <th><img src=\"img/computer.png\" alt=\"Nombre de postes\" title=\"Nombre de postes clients\"></th>
-  <th><img src=\"img/stock_people.png\" alt=\"Nombre d'utilisateurs\" title=\"Nombre d'utilisateurs\"></th>
-  <th><img src=\"img/stock_hand-signed.png\" title=\"Contrat\"></th>
-</tr>\n";
-    
+       
   $total_nbpc = 0;
   $total_nbusers = 0;
   //La liste des entites qu'on affiche
-  $tab_deja_affiche = array();
-  $num_debut_ligne = 0;
 
   for($i = 0; $i < $DB->numrows($result); $i++) {
     $num_debut_ligne++;
     $data=$DB->fetch_array($result);
-    $tab_deja_affiche[] = $data['entityid'];
-    $ssh_dateLastOK = "";
-    if($data['sshstatus'] == 1)
-      $ssh_status = "<font color=\"green\">OK</font>";
-    else if($data['sshdate']) {
-      $ssh_status = "<font color=\"red\">ERR</font>";
-      //Es-ce qu'on a deja reussi a se connecter sur ce serveur ?
-      $queryLastOK = "SELECT sshdate FROM glpi_plugin_anet_epacks_ssh WHERE FK_serveur='" . $data['FK_serveur'] . "' AND sshstatus=1 ORDER BY sshdate DESC LIMIT 1";
-      if($resultLastOK = $DB->query($queryLastOK)) {
-	$dataLastOK = $DB->fetch_array($resultLastOK);
-	if($dataLastOK[0]) {
-	  //	  print_r($dataLastOK);
-	  $ssh_status .= "<br /><font color=\"green\">LAST OK</font>";
-	  $ssh_dateLastOK = "<br />" . $dataLastOK[0];
+
+    if(! in_array($data['entityid'],$tab_deja_affiche)) {
+      $tab_deja_affiche[] = $data['entityid'];
+      $ssh_dateLastOK = "";
+      if($data['sshstatus'] == 1)
+	$ssh_status = "<font color=\"green\">OK</font>";
+      else if($data['sshdate']) {
+	$ssh_status = "<font color=\"red\">ERR</font>";
+	//Es-ce qu'on a deja reussi a se connecter sur ce serveur ?
+	$queryLastOK = "SELECT sshdate FROM glpi_plugin_anet_epacks_ssh WHERE FK_serveur='" . $data['FK_serveur'] . "' AND sshstatus=1 ORDER BY sshdate DESC LIMIT 1";
+	if($resultLastOK = $DB->query($queryLastOK)) {
+	  $dataLastOK = $DB->fetch_array($resultLastOK);
+	  if($dataLastOK[0]) {
+	    //	  print_r($dataLastOK);
+	    $ssh_status .= "<br /><font color=\"green\">LAST OK</font>";
+	    $ssh_dateLastOK = "<br />" . $dataLastOK[0];
+	  }
+	}
+	else {
+	  $ssh_dateLastOK = "";
 	}
+	//print $queryLastOK;
+      }
+      else
+	$ssh_status = "<font color=\"orange\">???</font>";
+      $s .= "<tr class='tab_bg_2'>
+  <td align=\"left\">\n";
+      if($data['entityid'] > 0) {
+	$s .= "    " . $num_debut_ligne . ". <a href=\"../../manageentity/index.php?active_entity=" . $data['entityid'] . "\">" . $data['client'] . ": " . $data['serveur'] . "</a>\n";
       }
       else {
-	$ssh_dateLastOK = "";
+	$s .= "    " . $num_debut_ligne . ". " . $data['client'] . ": " . $data['serveur'] . "(abonnement zen jamais activé)\n";
       }
-      //print $queryLastOK;
-    }
-    else
-      $ssh_status = "<font color=\"orange\">???</font>";
-    print "<tr class='tab_bg_2'>
-  <td align=\"left\">\n";
-    if($data['entityid'] > 0) {
-      print "    " . $num_debut_ligne . ". <a href=\"../../manageentity/index.php?active_entity=" . $data['entityid'] . "\">" . $data['client'] . ": " . $data['serveur'] . "</a>\n";
-    }
-    else {
-      print "    " . $num_debut_ligne . ". " . $data['client'] . ": " . $data['serveur'] . "(abonnement zen jamais activé)\n";
-    }
-    print "  </td>
+      
+      $s .= "  </td>
   <td>" . $ssh_status . "</td>
   <td>" . $data['sshdate'] . $ssh_dateLastOK . "</td>
   <td align=\"left\">" . $data['os_license_id'] . " " . $data['otherserial'] . "<br />" . $data['os_license_number'] . " " . $data['otherserial'] ."</td>
@@ -197,13 +232,14 @@ function local_make_array($q,$maintenance) {
   <td>
   </td>
 </tr>\n";
-    /*
-     <a href=\"../../../front/contract.php?contains[0]=" . $data['client'] . "\"><img src=\"img/stock_hand-signed.png\" title=\"Contrat\"></a>
-     <a href=\"../../../front/tracking.php?contains[0]=" . $data['client'] . "\"><img src=\"img/stock_web-support.png\" title=\"Tickets\"></a>
-     <a href=\"../../../front/user.php?contains[0]=" . $data['client'] . "\"><img src=\"img/stock_people.png\" title=\"Droits d'accès\"></a>
-    */
-    $total_nbpc += $data['nbpc'];
-    $total_nbusers += $data['nbusers'];
+      /*
+       <a href=\"../../../front/contract.php?contains[0]=" . $data['client'] . "\"><img src=\"img/stock_hand-signed.png\" title=\"Contrat\"></a>
+       <a href=\"../../../front/tracking.php?contains[0]=" . $data['client'] . "\"><img src=\"img/stock_web-support.png\" title=\"Tickets\"></a>
+       <a href=\"../../../front/user.php?contains[0]=" . $data['client'] . "\"><img src=\"img/stock_people.png\" title=\"Droits d'accès\"></a>
+      */
+      $total_nbpc += $data['nbpc'];
+      $total_nbusers += $data['nbusers'];
+    }
   }
   
   //Maintenant toutes les entités sur lesquelles on a des droits recursifs
@@ -241,13 +277,18 @@ LEFT JOIN glpi_plugin_anet_epacks_recencement_max AS g5 ON e.FK_serveur=g5.FK_se
   if(trim($listentity) != "")
     $query .= " AND g3.parentID IN (" . $listentity . ")\n";
   //GROUP BY e.FK_serveur
-  $query .= "GROUP BY e.FK_client
+  else {
+    $query = "";
+  }
+  if($query != "") 
+    $query .= "GROUP BY e.FK_client
 ORDER BY client
 LIMIT 500;";
   
   //print $query;
   
-  $result = $DB->query($query) or die($DB->error());
+  if($query != "") 
+    $result = $DB->query($query) or die($DB->error());
   
   for($i = 0; $i < $DB->numrows($result); $i++) {
     $num_debut_ligne++;
@@ -276,15 +317,15 @@ LIMIT 500;";
       }
       else
 	$ssh_status = "<font color=\"orange\">???</font>";
-      print "<tr class='tab_bg_2'>
+      $s .= "<tr class='tab_bg_2'>
   <td align=\"left\">\n";
       if($data['entityid'] > 0) {
-	print "    " . $num_debut_ligne . ". <a href=\"../../manageentity/index.php?active_entity=" . $data['entityid'] . "\">" . $data['client'] . ": " . $data['serveur'] . "</a>\n";
+	$s .= "    " . $num_debut_ligne . ". <a href=\"../../manageentity/index.php?active_entity=" . $data['entityid'] . "\">" . $data['client'] . ": " . $data['serveur'] . "</a>\n";
       }
       else {
-	print "    " . $num_debut_ligne . ". " . $data['client'] . ": " . $data['serveur'] . "(abonnement zen jamais activé)\n";
+	$s .= "    " . $num_debut_ligne . ". " . $data['client'] . ": " . $data['serveur'] . "(abonnement zen jamais activé)\n";
       }
-      print "  </td>
+      $s .= "  </td>
   <td>" . $ssh_status . "</td>
   <td>" . $data['sshdate'] . $ssh_dateLastOK . "</td>
   <td align=\"left\">" . $data['os_license_id'] . " " . $data['otherserial'] . "<br />" . $data['os_license_number'] . " " . $data['otherserial'] . "</td>
@@ -312,18 +353,44 @@ LIMIT 500;";
    <a href=\"../../../front/central.php?active_entity=" . $data['entityid'] . "\"><img src=\"img/stock_about.png\" title=\"Incarner le client " . $data['client'] . "\"></a>
    <a href=\"../../../front/computer.php?contains[0]=" . $data['client'] . "\"><img src=\"img/stock_form-add-field.png\" title=\"Inventaire\"></a>
   */
-  
-  print "<tr class='tab_bg_2'>
+  if($maintenance == 0) {
+    $total_nbpc_maint += $total_nbpc;
+    $total_nbusers_maint += $total_nbusers;
+  }
+  else {
+    $total_nbpc_hors_maint += $total_nbpc;
+    $total_nbusers_hors_maint += $total_nbusers;
+  }
+  return $s;
+}
+
+function local_make_array_header() {
+  return   "<table style=\"width:100%; padding: 0 10px 0 10px;\">
+<tr class='tab_bg_2'>
+  <th>Nom</th>
+  <th><img src=\"img/stock_channel.png\" alt=\"Télémaintenance (SSH)\" title=\"Télémaintenance (SSH)\"></th>
+  <th>Date du test</th>
+  <th>Adresse DynDNS</th>
+  <th><img src=\"img/computer.png\" alt=\"Nombre de postes\" title=\"Nombre de postes clients\"></th>
+  <th><img src=\"img/stock_people.png\" alt=\"Nombre d'utilisateurs\" title=\"Nombre d'utilisateurs\"></th>
+  <th><img src=\"img/stock_hand-signed.png\" title=\"Contrat\"></th>
+</tr>\n";
+
+}
+
+function local_make_array_footer($total_nbpc, $total_nbusers) {
+  $s .= "<tr class='tab_bg_2'>
   <td colspan=\"4\">Totaux: </td>
   <td>" . $total_nbpc . "</td>
   <td>" . $total_nbusers . "</td>
   <td></td>
 </tr>\n";
-  
-  print "</table>";
-  
+
+  $s .= "</table>";
+  return $s;
 }
 
+
 commonHeader("AbulEdu.NET -- Tableau récapitulatif -- Accueil RyXéo",$_SERVER['PHP_SELF'],"config","plugins");
 
 $glpiid = $_SESSION['glpiID'];
@@ -335,29 +402,51 @@ $query = "SELECT glpi_profiles.name AS name,glpi_users_profiles.FK_entities as F
 //print $query;
 //exit;
 
+$total_nbpc_maint    = 0;
+$total_nbusers_maint = 0;
+$total_nbpc_hors_maint    = 0;
+$total_nbusers_hors_maint = 0;
+$tab_deja_affiche = array();
+
 $result = $DB->query($query);
 if($result) {
-  $data=$DB->fetch_array($result);
-  $entityid = $data['FK_entities'];
-  if($data['name'] == "revendeur" || $data['name'] == "dsi" || $data['name'] == "super-admin") {
+  while($data=$DB->fetch_array($result)) {
     $entityid = $data['FK_entities'];
-    
-    //print $query;
-    //exit;
+    if($data['name'] == "revendeur" || $data['name'] == "dsi" || $data['name'] == "super-admin") {
+      //print $query;
+      $entityid = $data['FK_entities'];
       
-    print "<h1>Tableau récapitulatif de vos serveurs sous maintenance</h1>";
-    $maintenance = 0;
-    $querySM = local_make_query($data, $entityid, $maintenance);
-    local_make_array($querySM,$maintenance);
-
-    print "<h1>Tableau récapitulatif de vos serveurs hors maintenance</h1>";
-    $maintenance = -1;
-    $queryHM = local_make_query($data, $entityid, $maintenance);
-    local_make_array($queryHM,$maintenance);
-    
-    commonFooter();
-    exit;
+      //print $query;
+      //exit;
+      
+      $maintenance = 0;
+      $querySM = local_make_query($data, $entityid, $maintenance);
+      $str_sous_maint .= local_make_array($querySM,$maintenance);
+      
+      $querySM = local_make_query_dsi($data, $entityid, $maintenance);
+      //print $querySM;
+      if($querySM != "")
+	$str_sous_maint .= local_make_array($querySM,$maintenance);
+      
+      $num_debut_ligne = 0;
+      $maintenance = -1;
+      $queryHM = local_make_query($data, $entityid, $maintenance);
+      $str_hors_maint .= local_make_array($queryHM,$maintenance);
+    }
   }
+
+  print "<h1>Tableau récapitulatif de vos serveurs sous maintenance</h1>";
+  print local_make_array_header();
+  print $str_sous_maint;
+  print local_make_array_footer($total_nbpc_maint,$total_nbusers_maint);
+
+  print "<h1>Tableau récapitulatif de vos serveurs hors maintenance</h1>";
+  print local_make_array_header();
+  print $str_hors_maint;
+  print local_make_array_footer($total_nbpc_hors_maint,$total_nbusers_hors_maint);
+
+  commonFooter();
+  exit;
  }
 
 ?>
