commit 1b365d67e10a9c841f66116b913c1381d85ea58a
Author: Eric Seigne <eric.seigne@ryxeo.com>
Date:   Wed May 5 20:08:04 2010 +0200

    ajout des serveurs hors maintenance dans le tableau recap
    ajout des liens "marquer hors maintenance" et "créer un contrat"

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 a1dc180..2e019cb 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
@@ -14,23 +14,13 @@ if(!defined('GLPI_ROOT')){
  }
 include_once (GLPI_ROOT . "/inc/includes.php");
 
-commonHeader("AbulEdu.NET -- Tableau récapitulatif -- Accueil RyXéo",$_SERVER['PHP_SELF'],"config","plugins");
-
-$glpiid = $_SESSION['glpiID'];
-
-global $DB;
-$query = "SELECT glpi_profiles.name AS name,glpi_users_profiles.FK_entities as FK_entities FROM glpi_profiles,glpi_users_profiles,glpi_users WHERE glpi_users_profiles.FK_users='" . $glpiid . "' AND glpi_users_profiles.FK_profiles=glpi_profiles.ID AND glpi_users.FK_entities=glpi_users_profiles.FK_entities GROUP BY FK_entities";
-
-//print $query;
-$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") {
-    print "<h1>Tableau récapitulatif de vos serveurs</h1>";
-    $entityid = $data['FK_entities'];
-    
-    $query = "SELECT e.*, e.FK_enduser as entityid, g3.name as client, g4.name as serveur, g4.os_license_number, g4.os_license_id, ssh.*,
+//Fabrique la requete en fonction des besoins de liste des serveurs sous maintenance ou non
+//$maintenance = 1 -> ceux qui sons sous maintenance (sur)
+//$maintenance = 0 -> ceux qu'on ne sais pas (ça sera a faire quand on aura saisi tous les contrats)
+//$maintenance = -1 -> ceux qui ne veulent pas de maintenance
+//le champ peut etre a deux -> on ne veut meme plus les afficher
+function local_make_query($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, ssh.*,
 (sum(g5.nbeleves)+sum(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
@@ -38,31 +28,49 @@ LEFT JOIN glpi_entities AS g3 ON e.FK_client=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'] == "revendeur" || $data['name'] == "dsi") {
+  //WHERE e.Fk_Serveur > '0'\n";
+  if($data['name'] == "revendeur" || $data['name'] == "dsi") {
+    if($maintenance == 0 || $maintenance ==  1) {
       $query .= "WHERE e.FK_contract >= '0' AND e.FK_activation='" . $entityid . "'\n";
+    }
+    else if($maintenance == -1) {
+      $query .= "WHERE e.FK_contract='-1' AND e.FK_activation='" . $entityid . "'\n";
+    }
       //GROUP BY e.FK_serveur
-      $query .= "GROUP BY e.FK_client
+    $query .= "GROUP BY e.FK_client
 ORDER BY client
 LIMIT 500;";
-    }
-    else {
-      //On n'affiche pas les serveurs qui ne sont pas "Zen"
+  }
+  else {
+    //On n'affiche pas les serveurs qui ne sont pas "Zen"
+    if($maintenance == 0 || $maintenance ==  1) {
       $query .= "WHERE e.FK_contract >= '0' AND e.FK_Serveur>'0'\n";
-      //GROUP BY e.FK_serveur
-      //On ne peut pas group by client a cause de l'historique ou on avait pas la meme structure
-      //de base
-      $query .= "GROUP BY e.FK_serveur
+    }
+    else if($maintenance == -1) {
+      $query .= "WHERE e.FK_contract='-1' AND e.FK_Serveur>'0'\n";
+    }
+    //GROUP BY e.FK_serveur
+    //On ne peut pas group by client a cause de l'historique ou on avait pas la meme structure
+    //de base
+    $query .= "GROUP BY e.FK_serveur
 ORDER BY client
 LIMIT 500;";
-    }
-    
-    //print $query;
-    //exit;
-    
-    $result = $DB->query($query) or die($DB->error());
+  }
+
+  //  if($maintenance == -1) {
+  //    print $query;
+  //  }
+  return $query;
+}
+
+
+function local_make_array($q,$maintenance) {
+  global $DB;
+  global $glpiid;
+
+  $result = $DB->query($q) or die($DB->error());
     
-    print "<table>
+  print "<table>
 <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>
@@ -73,15 +81,110 @@ LIMIT 500;";
   <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();
+  $total_nbpc = 0;
+  $total_nbusers = 0;
+  //La liste des entites qu'on affiche
+  $tab_deja_affiche = array();
     
-    for($i = 0; $i < $DB->numrows($result); $i++) {
-      $data=$DB->fetch_array($result);
+  for($i = 0; $i < $DB->numrows($result); $i++) {
+    $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];
+	}
+      }
+      else {
+	$ssh_dateLastOK = "";
+      }
+      //print $queryLastOK;
+    }
+    else
+      $ssh_status = "<font color=\"orange\">???</font>";
+    print "<tr class='tab_bg_2'>
+  <td align=\"left\">\n";
+    if($data['entityid'] > 0) {
+      print "    " . ($i+1) . ". <a href=\"../../manageentity/index.php?active_entity=" . $data['entityid'] . "\">" . $data['client'] . ": " . $data['serveur'] . "</a>\n";
+    }
+    else {
+      print "    " . ($i+1) . ". " . $data['client'] . ": " . $data['serveur'] . "(abonnement zen jamais activé)\n";
+    }
+    print "  </td>
+  <td>" . $ssh_status . "</td>
+  <td>" . $data['sshdate'] . $ssh_dateLastOK . "</td>
+  <td align=\"left\">" . $data['os_license_id'] . "<br />" . $data['os_license_number'] . "</td>
+  <td>" . $data['nbpc'] . "</td>
+  <td>" . $data['nbusers'] . "</td>
+  <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'];
+  }
+  
+  //Maintenant toutes les entités sur lesquelles on a des droits recursifs
+  $queryR = "SELECT glpi_users_profiles.FK_entities as entity FROM glpi_users_profiles WHERE glpi_users_profiles.FK_users='" . $glpiid . "' AND glpi_users_profiles.recursive=1 GROUP BY FK_entities";
+  //print $queryR;
+  $resultR = $DB->query($queryR);
+  $listentity = "";
+  for($r = 0; $r < $DB->numrows($resultR); $r++) {
+    $dataR=$DB->fetch_array($resultR);
+    $entityparent = $dataR['entity'];
+    if($listentity != "")
+      $listentity .= ", '" . $entityparent . "'";
+    else
+      $listentity = "'" . $entityparent . "'";
+  }
+  //$query = "SELECT ID FROM glpi_entities WHERE parentID='" . $entityparent . "'";
+  
+  $query = "SELECT e.*, e.FK_enduser as entityid, g3.name as client, g4.name as serveur, g4.os_license_number, g4.os_license_id, ssh.*,
+(sum(g5.nbeleves)+sum(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
+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($maintenance == 0 || $maintenance ==  1) {
+    $query .= "WHERE e.FK_contract >= '0'";
+  }
+  else if($maintenance == -1) {
+    $query .= "WHERE e.FK_contract='-1'";
+  }
+
+  if(trim($listentity) != "")
+    $query .= " AND g3.parentID IN (" . $listentity . ")\n";
+  //GROUP BY e.FK_serveur
+  $query .= "GROUP BY e.FK_client
+ORDER BY serveur,client
+LIMIT 500;";
+  
+  //print $query;
+  
+  $result = $DB->query($query) or die($DB->error());
+  
+  for($i = 0; $i < $DB->numrows($result); $i++) {
+    $data=$DB->fetch_array($result);
+    $ssh_dateLastOK = "";
+    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']) {
@@ -120,120 +223,64 @@ LIMIT 500;";
   <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'];
-    }
-
-    //Maintenant toutes les entités sur lesquelles on a des droits recursifs
-    $queryR = "SELECT glpi_users_profiles.FK_entities as entity FROM glpi_users_profiles WHERE glpi_users_profiles.FK_users='" . $glpiid . "' AND glpi_users_profiles.recursive=1 GROUP BY FK_entities";
-    //print $queryR;
-    $resultR = $DB->query($queryR);
-    $listentity = "";
-    for($r = 0; $r < $DB->numrows($resultR); $r++) {
-      $dataR=$DB->fetch_array($resultR);
-      $entityparent = $dataR['entity'];
-      if($listentity != "")
-	$listentity .= ", '" . $entityparent . "'";
-      else
-	$listentity = "'" . $entityparent . "'";
-    }
-    //$query = "SELECT ID FROM glpi_entities WHERE parentID='" . $entityparent . "'";
-      
-    $query = "SELECT e.*, e.FK_enduser as entityid, g3.name as client, g4.name as serveur, g4.os_license_number, g4.os_license_id, ssh.*,
-(sum(g5.nbeleves)+sum(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
-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";
-    $query .= "WHERE g3.parentID IN (" . $listentity . ")\n";
-    //GROUP BY e.FK_serveur
-    $query .= "GROUP BY e.FK_client
-ORDER BY serveur,client
-LIMIT 500;";
-    
-    //print $query;
-    
-    $result = $DB->query($query) or die($DB->error());
-    
-    for($i = 0; $i < $DB->numrows($result); $i++) {
-      $data=$DB->fetch_array($result);
-      $ssh_dateLastOK = "";
-      if(! in_array($data['entityid'],$tab_deja_affiche)) {
-	$tab_deja_affiche[] = $data['entityid'];
-	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>";
-	print "<tr class='tab_bg_2'>
-  <td align=\"left\">\n";
-	if($data['entityid'] > 0) {
-	  print "    " . ($i+1) . ". <a href=\"../../manageentity/index.php?active_entity=" . $data['entityid'] . "\">" . $data['client'] . ": " . $data['serveur'] . "</a>\n";
-	}
-	else {
-	  print "    " . ($i+1) . ". " . $data['client'] . ": " . $data['serveur'] . "(abonnement zen jamais activé)\n";
-	}
-	print "  </td>
-  <td>" . $ssh_status . "</td>
-  <td>" . $data['sshdate'] . $ssh_dateLastOK . "</td>
-  <td align=\"left\">" . $data['os_license_id'] . "<br />" . $data['os_license_number'] . "</td>
-  <td>" . $data['nbpc'] . "</td>
-  <td>" . $data['nbusers'] . "</td>
-  <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'];
-      }
-      else {
-	//print "deja affiché :: " . $data['entityid'];
-      }
+      */
+      $total_nbpc += $data['nbpc'];
+      $total_nbusers += $data['nbusers'];
     }
+    else {
+      //print "deja affiché :: " . $data['entityid'];
+    }
+  }
   
-
-    
-    /*
-      <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'>
+  
+  
+  /*
+   <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'>
   <td colspan=\"4\">Totaux: </td>
   <td>" . $total_nbpc . "</td>
   <td>" . $total_nbusers . "</td>
   <td></td>
 </tr>\n";
+  
+  print "</table>";
+  
+}
+
+commonHeader("AbulEdu.NET -- Tableau récapitulatif -- Accueil RyXéo",$_SERVER['PHP_SELF'],"config","plugins");
+
+$glpiid = $_SESSION['glpiID'];
+
+global $DB;
+$query = "SELECT glpi_profiles.name AS name,glpi_users_profiles.FK_entities as FK_entities FROM glpi_profiles,glpi_users_profiles,glpi_users WHERE glpi_users_profiles.FK_users='" . $glpiid . "' AND glpi_users_profiles.FK_profiles=glpi_profiles.ID AND glpi_users.FK_entities=glpi_users_profiles.FK_entities GROUP BY FK_entities";
+
+//print $query;
+$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") {
+    $entityid = $data['FK_entities'];
     
-    
-    print "</table>";
+    //print $query;
+    //exit;
+      
+    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;
diff --git a/plugins/manageentity/inc/plugin_manageentity.functions_display.php b/plugins/manageentity/inc/plugin_manageentity.functions_display.php
index 9122d3c..ab608a4 100644
--- a/plugins/manageentity/inc/plugin_manageentity.functions_display.php
+++ b/plugins/manageentity/inc/plugin_manageentity.functions_display.php
@@ -74,7 +74,7 @@ function plugin_manageentity_showcontractsassociated($instID) {
 	else{
 		echo "<form method='post' action=\"./index.php\">";
 		echo "<div align='center'><table class='tab_cadre' align='center' width='95%'>";
-		echo "<tr><th colspan='3'>".$LANGMANAGEENTITY["manageentity"][3].":</th></tr>";
+		echo "<tr><th colspan='3'>".$LANGMANAGEENTITY["manageentity"][3]." - <a href=\"" . $CFG_GLPI["root_doc"] . "/front/contract.form.php\">[créer un contrat]</a> :</th></tr>";
 		echo "<tr><th>".$LANG["common"][16]."</th>";
 		echo "<th>".$LANG["financial"][4]."</th>";
 		echo "<th>".$LANG["common"][25]."</th>";
@@ -467,7 +467,7 @@ WHERE FK_enduser=".$instID;
 	if ($number > 0) {
 		echo "<br><div align='center'><table class='tab_cadre' align='center' width='95%'>";
 		echo "<tr>";
-		echo "<th colspan='3'>Epack et Installation</th>";
+		echo "<th colspan='3'>Epack et Installation - <a href=\"desactiver_maintenance.php?" . $DB->result($result, $i, "code") . "\">[marquer hors maintenance]</a> - </th>";
 		echo "</tr>";
 		echo "<tr class='tab_bg_2'>";
 		echo "<td width=\"33%\">".$DB->result($result, $i, "code")."</td>";
