commit 8c2a3d1e0886cf4674405107c5487a09c489495f
Author: Eric Seigne <eric.seigne@ryxeo.com>
Date:   Thu Jan 16 14:21:22 2014 +0100

    amelioration des listes d'années pour les liens des epacks (automatique maintenant)

diff --git a/plugins/anet_epacks/front/plugin_anet_epacks.verif_contract_epack.php b/plugins/anet_epacks/front/plugin_anet_epacks.verif_contract_epack.php
index cc86fcd..a22b0c8 100644
--- a/plugins/anet_epacks/front/plugin_anet_epacks.verif_contract_epack.php
+++ b/plugins/anet_epacks/front/plugin_anet_epacks.verif_contract_epack.php
@@ -25,7 +25,7 @@ print "<div style=\"text-align:left\">";
 $automatique = "";
 $manuel = "";
 
-$query = "SELECT FK_enduser,code FROM glpi_plugin_anet_epacks WHERE FK_contract='0' AND FK_enduser>'0'";
+$query = "SELECT FK_enduser,code FROM glpi_plugin_anet_epacks WHERE (FK_contract='0' OR FK_contract='-1') AND FK_enduser>'0'";
 $result = $DB->query($query);
 //print $query;
 while($data=$DB->fetch_array($result)) {
@@ -37,19 +37,23 @@ while($data=$DB->fetch_array($result)) {
   $data1=$DB->fetch_array($result1);
   $clientfinal = $data1['completename'];
 
-
-  $query2 = "SELECT * FROM glpi_contracts WHERE FK_entities='" . $enduser  . "'";
+  //order by pour prendre le dernier contrat ... si on recolle automatiquement et qu'il y a un ancien contrat il faut recoller avecle plus recent
+  $query2 = "SELECT *,(TO_DAYS(begin_date) + (duration*30)) AS endDay FROM glpi_contracts WHERE FK_entities='" . $enduser  . "' AND (TO_DAYS(begin_date) + (duration*30)) > TO_DAYS(NOW()) AND deleted='0' ORDER BY begin_date DESC LIMIT 1";
+  //print "<pre>$query2</pre>";
   $result2 = $DB->query($query2);
   $data2=$DB->fetch_array($result2);
-
-  if(trim($data2['name'])) {
-    $query3 = "UPDATE glpi_plugin_anet_epacks SET FK_contract='" . $data2['ID']  . "' WHERE FK_enduser='$enduser' AND FK_contract='0'";
+  if(trim($data2['name']) != "") {
+    $query3 = "UPDATE glpi_plugin_anet_epacks SET FK_contract='" . $data2['ID']  . "' WHERE FK_enduser='$enduser'";
+    //$query3 = "UPDATE glpi_plugin_anet_epacks SET FK_contract='-1' WHERE FK_enduser='$enduser'";
     $automatique .= "<p>Recollement automatique pour $code -> $clientfinal -> nouvelle ref contrat: " . $data2['ID'] . "</p>";
+    //print $query3;
     $result3 = $DB->query($query3);
     $data3=$DB->fetch_array($result3);
   }
   else {
-    $manuel .= "<tr><td>$code</td><td>$clientfinal</td><td>$enduser</td><td>" . $data2['ID'] . "</td></tr>\n";
+    if(is_array($data2)) {
+      $manuel .= "<tr><td>$code</td><td>$clientfinal</td><td>$enduser</td><td>" . $data2['ID'] . "</td></tr>\n";
+    }
   }
  }
 
diff --git a/plugins/anet_epacks/front/plugin_anet_epacks.view.php b/plugins/anet_epacks/front/plugin_anet_epacks.view.php
index 51e6c40..dc7210f 100644
--- a/plugins/anet_epacks/front/plugin_anet_epacks.view.php
+++ b/plugins/anet_epacks/front/plugin_anet_epacks.view.php
@@ -20,7 +20,11 @@ if($result) {
   if($data['name'] == "revendeur") {
     print "<h1>Liste synthétique de vos epacks</h1>";
     $entityid = $data['FK_entities'];
-print "<p>Liste des epacks attribués: <a href=\"" . $PHP_SELF . "\">Tous</a> - <a href=\"" . $PHP_SELF . "?year=2008\">2008</a> - <a href=\"" . $PHP_SELF . "?year=2009\">2009</a> - <a href=\"" . $PHP_SELF . "?year=2010\">2010</a> - <a href=\"" . $PHP_SELF . "?year=2011\">2011</a>.</p>";
+    print "<p>Liste des epacks attribués: <a href=\"" . $PHP_SELF . "\">Tous</a> - ";
+    for($i=2008; $i <= date("Y"); $i++) {
+	print "<a href=\"" . $PHP_SELF . "?year=$i\">$i</a> - ";
+      }
+    print "</p>";
 
 //Les packs attribués
 //Permet de limiter un peu l'affichage, il faudra faire un système de recherche ou pagination à terme
@@ -74,7 +78,14 @@ print "</table>";
 checkRight("config","w");
 //checkSeveralRightsOr(array("config" => "w", "profile" => "w"));
 
-print "<p>Liste des epacks attribués: <a href=\"" . $PHP_SELF . "\">Tous</a> - <a href=\"" . $PHP_SELF . "?year=2008\">2008</a> - <a href=\"" . $PHP_SELF . "?year=2009\">2009</a> - <a href=\"" . $PHP_SELF . "?year=2010\">2010</a> - <a href=\"" . $PHP_SELF . "?year=2011\">2011</a>.</p>";
+//print "<p>Liste des epacks attribués: <a href=\"" . $PHP_SELF . "\">Tous</a> - <a href=\"" . $PHP_SELF . "?year=2008\">2008</a> - <a href=\"" . $PHP_SELF . "?year=2009\">2009</a> - <a href=\"" . $PHP_SELF . "?year=2010\">2010</a> - <a href=\"" . $PHP_SELF . "?year=2011\">2011</a>.</p>";
+
+ print "<p>Liste des epacks attribués: <a href=\"" . $PHP_SELF . "\">Tous</a> - ";
+ for($i=2008; $i <= date("Y"); $i++) {
+     print "<a href=\"" . $PHP_SELF . "?year=$i\">$i</a> - ";
+   }
+ print "</p>";
+
 
 global $DB;
 
@@ -95,6 +106,7 @@ $result = $DB->query($query) or die($DB->error());
 
 print "<table class='tab_cadre' width='100%' cellpadding='2'>\n";
   print "<tr class='tab_bg_3'>
+  <td>N°</td>
   <td>Nom</td>
   <td>Création</td>
   <td>Activation</td>
@@ -107,6 +119,7 @@ print "<table class='tab_cadre' width='100%' cellpadding='2'>\n";
 for($i = 0; $i < $DB->numrows($result); $i++) {
   $data=$DB->fetch_array($result);
   print "<tr class='tab_bg_3'>\n";
+  print "  <td>" . ($i+1) . "</td>";
   print "  <td>" . $data['clientderyxeo'] . "</td>
   <td>" . $data['creation_date'] . "</td>
   <td>" . $data['activation_date'] . "</td>
@@ -143,6 +156,7 @@ $result = $DB->query($query) or die($DB->error());
 
 print "<table class='tab_cadre' width='100%' cellpadding='2'>\n";
   print "<tr class='tab_bg_3'>
+  <td>N°</td>
   <td>Nom</td>
   <td>Date de création du pack</td>
   <td>Date d'activation du pack</td>
@@ -155,6 +169,7 @@ print "<table class='tab_cadre' width='100%' cellpadding='2'>\n";
 for($i = 0; $i < $DB->numrows($result); $i++) {
   $data=$DB->fetch_array($result);
   print "<tr class='tab_bg_3'>\n";
+  print "  <td>" . ($i+1) . "</td>";
   print "  <td>" . $data['clientderyxeo'] . "</td>
   <td>" . $data['creation_date'] . "</td>
   <td>" . $data['activation_date'] . "</td>
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 50010d4..c45550f 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
@@ -229,8 +229,8 @@ function local_make_array($q,$maintenance,$enduser=1) {
 	  $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];
+	    $ssh_status .= "<br /><font color=\"green\">LAST&nbsp;OK</font>";
+	    $ssh_dateLastOK = "<br />" . str_replace(" ","&nbsp;",$dataLastOK[0]);
 	  }
 	}
 	else {
