Projet

Général

Profil

Révision e213dd82 htdocs/mac/contract.php

Voir les différences:

htdocs/mac/contract.php
1 1
<?php
2 2
/*
3 3
  gestion des contrats - affichage et rappel
4
  http://www.abuledu.net/mac/contract.php/view=toto/mac=08:D8:34:B8:90:CD
4 5
*/
5 6

  
6 7
$g_http_request = $_SERVER['REQUEST_URI'];
7
ereg(".*mac=(.*)",$_SERVER['REQUEST_URI'],$regs);
8
$mac = addslashes(strtoupper($regs[1]));
8
preg_match("/.*mac=(.*)/",$_SERVER['REQUEST_URI'],$regs);
9
$mac  = addslashes(strtoupper($regs[1]));
10

  
11
preg_match("/.*view=(.*)\/mac=/",$_SERVER['REQUEST_URI'],$regs);
12
$view = addslashes($regs[1]);
13

  
14
//print "on a $mac et $view";
15

  
9 16
//Ou du POST
10 17
if(trim($mac) == "") {
11 18
  $mac = addslashes(strtoupper($_POST['mac']));
12
 }
19
}
13 20

  
14 21
$_SERVER['REQUEST_URI'] = "";
15 22
$_SERVER['HTTP_REFERER'] = "";
......
17 24
include (GLPI_ROOT . "/inc/includes.php");
18 25

  
19 26
//On recupere l'id du serveur dont la macaddr correspond
20
$query = "SELECT ID FROM glpi_computers WHERE glpi_computers.os_license_number LIKE '" . $mac . ".%'";
27
$query = "SELECT FK_computers AS ID FROM glpi_computer_device WHERE specificity ='" . $mac . "'";
21 28
$result = $DB->query($query);
22 29
$data = $DB->fetch_assoc($result);
23 30
//print_r($data);
24 31

  
25 32
if($data['ID']) {
26 33
  $serverid=$data['ID'];
34
  
35
  //Quand on a le serverID il faut trouver l'entite dans laquelle il se trouve
36
  $queryEntity = "SELECT FK_entities AS EntityID FROM glpi_computers WHERE ID='$serverid'";
37
  $resultEntity = $DB->query($queryEntity);
38
  $dataEntity = $DB->fetch_assoc($resultEntity);
39
  $entityID = $dataEntity['EntityID'];
40
  
27 41
  //Et ensuite on cherche dans les contrats ce qui correspond
28 42
  // -> contrat non supprime
29 43
  // -> contrat correspondant a ce serveur
30 44
  // -> contrat de type 1 ()
31
  $query2 = "SELECT UNIX_TIMESTAMP(c.begin_date + INTERVAL c.duration MONTH) as endcontract,c.* FROM glpi_contract_device, glpi_contracts as c WHERE 
45
  $query2 = "SELECT UNIX_TIMESTAMP(c.begin_date + INTERVAL c.duration MONTH) as endcontract,c.* FROM glpi_contracts as c WHERE 
32 46
  c.deleted='0' AND
33
  glpi_contract_device.FK_device = '" . $serverid . "' AND
34
  glpi_contract_device.device_type = '1' AND
35
  c.ID=glpi_contract_device.FK_contract";
47
  c.FK_entities='$entityID'";
48

  
36 49
  //print $query2;
37 50
  $result2 = $DB->query($query2);
38 51
  $data2 = $DB->fetch_assoc($result2);
......
41 54
  //print mktime() . " -- ";
42 55
  $endc = $data2['endcontract'];
43 56
  if($endc > mktime()) {
44
    print $endc . ":" . "DIRECT:" . $data2['name'] . ":";
57
    if($view == "web") {
58
      header('Location: http://www.abuledu.net/mac/view/direct.php');
59
      exit;
60
    }
61
    else {
62
      print $endc . ":" . "DIRECT:" . $data2['name'] . ":";
63
    }
45 64
  }
46 65
  //Reconduction automatique ...
47 66
  else if($endc < mktime() && $data2['recursive']=='1') {
48
    print mktime(0,0,0, date("m",$endc)+$data2['periodicity'], date("d",$endc), date("Y",$endc)) . ":" . "DIRECT:" . $data2['name'] . ":" . "Renouvellement automatique";
67
    if($view == "web") {
68
      header('Location: http://www.abuledu.net/mac/view/direct.php');
69
      exit;
70
    }
71
    else {
72
      print mktime(0,0,0, date("m",$endc)+$data2['periodicity'], date("d",$endc), date("Y",$endc)) . ":" . "DIRECT:" . $data2['name'] . ":" . "Renouvellement automatique";
73
    }
49 74
  }
50 75
  else {
51 76
    //Le serveur a ete installe par un partenaire qui a un contrat global mais pas encore d'avenant pour ce serveur
......
61 86
    */
62 87
    $endc = $data3['endcontract'];
63 88
    if($endc > mktime()) {
64
      print $endc . ":PARTNER" . ":" . $data3['name'] . ":" . "Avenant pour ce serveur manquant";
89
      if($view == "web") {
90
	header('Location: http://www.abuledu.net/mac/view/partner.php');
91
	exit;
92
      }
93
      else {
94
	print $endc . ":PARTNER" . ":" . $data3['name'] . ":" . "Avenant pour ce serveur manquant";
95
      }
65 96
    }
66 97
    else{
67 98
      //Le serveur existe dans notre base mais c'est tout
68
      print "000:WAITING:000:";
99
      if($view == "web") {
100
	header('Location: http://www.abuledu.net/mac/view/waiting.php');
101
	exit;
102
      }
103
      else {
104
	print "000:WAITING:000:";
105
      }
69 106
    }
70 107
  }
71 108
 }
72 109
 else {
73
   print "000:FORBIDDEN:000:NOT";
110
   if($view == "web") {
111
     header('Location: http://www.abuledu.net/mac/view/forbidden.php');
112
     exit;
113
   }
114
   else {
115
     print "000:FORBIDDEN:000:NOT";
116
   }
74 117
 }
75 118

  
76 119
?>

Formats disponibles : Unified diff

Redmine Appliance - Powered by TurnKey Linux