commit e213dd82124dbc7cbb4b08ad13066132841b2f18
Author: root <root@anet>
Date:   Mon Mar 23 19:41:06 2015 +0100

    pas commite depuis trop longtemps, et ajout du debut de support epack pour tabuledu

diff --git a/htdocs/mac/contract.php b/htdocs/mac/contract.php
index d636ee8..18f7a6b 100644
--- a/htdocs/mac/contract.php
+++ b/htdocs/mac/contract.php
@@ -1,15 +1,22 @@
 <?php
 /*
   gestion des contrats - affichage et rappel
+  http://www.abuledu.net/mac/contract.php/view=toto/mac=08:D8:34:B8:90:CD
 */
 
 $g_http_request = $_SERVER['REQUEST_URI'];
-ereg(".*mac=(.*)",$_SERVER['REQUEST_URI'],$regs);
-$mac = addslashes(strtoupper($regs[1]));
+preg_match("/.*mac=(.*)/",$_SERVER['REQUEST_URI'],$regs);
+$mac  = addslashes(strtoupper($regs[1]));
+
+preg_match("/.*view=(.*)\/mac=/",$_SERVER['REQUEST_URI'],$regs);
+$view = addslashes($regs[1]);
+
+//print "on a $mac et $view";
+
 //Ou du POST
 if(trim($mac) == "") {
   $mac = addslashes(strtoupper($_POST['mac']));
- }
+}
 
 $_SERVER['REQUEST_URI'] = "";
 $_SERVER['HTTP_REFERER'] = "";
@@ -17,22 +24,28 @@ define('GLPI_ROOT', '..');
 include (GLPI_ROOT . "/inc/includes.php");
 
 //On recupere l'id du serveur dont la macaddr correspond
-$query = "SELECT ID FROM glpi_computers WHERE glpi_computers.os_license_number LIKE '" . $mac . ".%'";
+$query = "SELECT FK_computers AS ID FROM glpi_computer_device WHERE specificity ='" . $mac . "'";
 $result = $DB->query($query);
 $data = $DB->fetch_assoc($result);
 //print_r($data);
 
 if($data['ID']) {
   $serverid=$data['ID'];
+  
+  //Quand on a le serverID il faut trouver l'entite dans laquelle il se trouve
+  $queryEntity = "SELECT FK_entities AS EntityID FROM glpi_computers WHERE ID='$serverid'";
+  $resultEntity = $DB->query($queryEntity);
+  $dataEntity = $DB->fetch_assoc($resultEntity);
+  $entityID = $dataEntity['EntityID'];
+  
   //Et ensuite on cherche dans les contrats ce qui correspond
   // -> contrat non supprime
   // -> contrat correspondant a ce serveur
   // -> contrat de type 1 ()
-  $query2 = "SELECT UNIX_TIMESTAMP(c.begin_date + INTERVAL c.duration MONTH) as endcontract,c.* FROM glpi_contract_device, glpi_contracts as c WHERE 
+  $query2 = "SELECT UNIX_TIMESTAMP(c.begin_date + INTERVAL c.duration MONTH) as endcontract,c.* FROM glpi_contracts as c WHERE 
   c.deleted='0' AND
-  glpi_contract_device.FK_device = '" . $serverid . "' AND
-  glpi_contract_device.device_type = '1' AND
-  c.ID=glpi_contract_device.FK_contract";
+  c.FK_entities='$entityID'";
+
   //print $query2;
   $result2 = $DB->query($query2);
   $data2 = $DB->fetch_assoc($result2);
@@ -41,11 +54,23 @@ if($data['ID']) {
   //print mktime() . " -- ";
   $endc = $data2['endcontract'];
   if($endc > mktime()) {
-    print $endc . ":" . "DIRECT:" . $data2['name'] . ":";
+    if($view == "web") {
+      header('Location: http://www.abuledu.net/mac/view/direct.php');
+      exit;
+    }
+    else {
+      print $endc . ":" . "DIRECT:" . $data2['name'] . ":";
+    }
   }
   //Reconduction automatique ...
   else if($endc < mktime() && $data2['recursive']=='1') {
-    print mktime(0,0,0, date("m",$endc)+$data2['periodicity'], date("d",$endc), date("Y",$endc)) . ":" . "DIRECT:" . $data2['name'] . ":" . "Renouvellement automatique";
+    if($view == "web") {
+      header('Location: http://www.abuledu.net/mac/view/direct.php');
+      exit;
+    }
+    else {
+      print mktime(0,0,0, date("m",$endc)+$data2['periodicity'], date("d",$endc), date("Y",$endc)) . ":" . "DIRECT:" . $data2['name'] . ":" . "Renouvellement automatique";
+    }
   }
   else {
     //Le serveur a ete installe par un partenaire qui a un contrat global mais pas encore d'avenant pour ce serveur
@@ -61,16 +86,34 @@ if($data['ID']) {
     */
     $endc = $data3['endcontract'];
     if($endc > mktime()) {
-      print $endc . ":PARTNER" . ":" . $data3['name'] . ":" . "Avenant pour ce serveur manquant";
+      if($view == "web") {
+	header('Location: http://www.abuledu.net/mac/view/partner.php');
+	exit;
+      }
+      else {
+	print $endc . ":PARTNER" . ":" . $data3['name'] . ":" . "Avenant pour ce serveur manquant";
+      }
     }
     else{
       //Le serveur existe dans notre base mais c'est tout
-      print "000:WAITING:000:";
+      if($view == "web") {
+	header('Location: http://www.abuledu.net/mac/view/waiting.php');
+	exit;
+      }
+      else {
+	print "000:WAITING:000:";
+      }
     }
   }
  }
  else {
-   print "000:FORBIDDEN:000:NOT";
+   if($view == "web") {
+     header('Location: http://www.abuledu.net/mac/view/forbidden.php');
+     exit;
+   }
+   else {
+     print "000:FORBIDDEN:000:NOT";
+   }
  }
 
 ?>
