Projet

Général

Profil

Paste
Statistiques
| Branche: | Révision:

ryxeo-glpi-git / plugins / anet_epacks / front / plugin_anet_epacks.view_array_recap.php @ f8b606aa

Historique | Voir | Annoter | Télécharger (14 ko)

1
<?php
2

    
3
  /*
4
    Creation de la vue ...
5
    CREATE  ALGORITHM = TEMPTABLE VIEW glpi_plugin_anet_epacks_ssh_max AS SELECT *
6
    FROM `glpi_plugin_anet_epacks_ssh` as s1
7
    WHERE sshdate=(SELECT MAX(sshdate) FROM `glpi_plugin_anet_epacks_ssh` as s2 WHERE s1.FK_serveur=s2.FK_serveur)
8

9
    Comme c'est super long et cause un lag monstrueux a l ouverture on remplace par une table "normale" qui est
10
    periodiquement remise a jour ...
11

12
    CREATE TABLE IF NOT EXISTS `glpi_plugin_anet_epacks_ssh_max` (
13
    `ID` int(11) NOT NULL auto_increment,
14
    `sshstatus` binary(1) NOT NULL,
15
    `FK_serveur` int(11) NOT NULL,
16
    `log` text collate utf8_unicode_ci NOT NULL,
17
    `sshdate` datetime NOT NULL,
18
    PRIMARY KEY  (`ID`),
19
    KEY `FK_serveur` (`FK_serveur`)
20
    ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ; 
21
    
22
    A lancer periodiquement (?)
23
    TRUNCATE TABLE `glpi_plugin_anet_epacks_ssh_max` ;
24
    INSERT INTO glpi_plugin_anet_epacks_ssh_max SELECT * FROM `glpi_plugin_anet_epacks_ssh` as s1  WHERE sshdate=(SELECT MAX(sshdate) FROM `glpi_plugin_anet_epacks_ssh` as s2 WHERE s1.FK_serveur=s2.FK_serveur) ;
25
    
26

27
    on utilise la meme astuce pour l autre view: glpi_plugin_anet_epacks_recencement_max
28

29
    CREATE TABLE IF NOT EXISTS `glpi_plugin_anet_epacks_recencement_max` (
30
    `id` int(11) NOT NULL auto_increment,
31
    `ladate` timestamp NOT NULL default CURRENT_TIMESTAMP,
32
    `site` text collate utf8_unicode_ci NOT NULL,
33
    `phone` varchar(20) collate utf8_unicode_ci NOT NULL,
34
    `rvd` varchar(100) collate utf8_unicode_ci NOT NULL,
35
    `adresse1` text collate utf8_unicode_ci NOT NULL,
36
    `adresse2` text collate utf8_unicode_ci NOT NULL,
37
    `ville` varchar(100) collate utf8_unicode_ci NOT NULL,
38
    `cpostal` varchar(10) collate utf8_unicode_ci NOT NULL,
39
    `pays` varchar(100) collate utf8_unicode_ci NOT NULL,
40
    `nom` varchar(100) collate utf8_unicode_ci NOT NULL,
41
    `prenom` varchar(100) collate utf8_unicode_ci NOT NULL,
42
    `email` varchar(100) collate utf8_unicode_ci NOT NULL,
43
    `mac0` varchar(15) collate utf8_unicode_ci NOT NULL,
44
    `mac1` varchar(15) collate utf8_unicode_ci NOT NULL,
45
    `proc` varchar(100) collate utf8_unicode_ci NOT NULL,
46
    `ram` varchar(100) collate utf8_unicode_ci NOT NULL,
47
    `hdd0` varchar(100) collate utf8_unicode_ci NOT NULL,
48
    `hdd1` varchar(100) collate utf8_unicode_ci NOT NULL,
49
    `anet` varchar(100) collate utf8_unicode_ci NOT NULL,
50
    `tel` varchar(20) collate utf8_unicode_ci NOT NULL,
51
    `contrat` varchar(100) collate utf8_unicode_ci NOT NULL,
52
    `nbprofs` int(11) NOT NULL,
53
    `nbeleves` int(11) NOT NULL,
54
    `nbpc` int(11) NOT NULL,
55
    `ip` varchar(16) collate utf8_unicode_ci NOT NULL,
56
    `FK_serveur` int(11) default NULL,
57
    PRIMARY KEY  (`id`),
58
    UNIQUE KEY `FK_serveur` (`FK_serveur`)
59
    ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
60
    
61
    Et lance periodiquement
62
    TRUNCATE TABLE `glpi_plugin_anet_epacks_recencement_max` ;
63
    INSERT INTO glpi_plugin_anet_epacks_recencement_max SELECT * FROM glpi_plugin_anet_epacks_recencement as s1
64
    WHERE ladate=(SELECT MAX(ladate) FROM `glpi_plugin_anet_epacks_recencement` as s2 WHERE s1.FK_serveur=s2.FK_serveur) ;
65

66
    En fait, ca se passe dans anet.ryxeo.com/statistiques.php
67

68
  */
69

    
70
  // Affiche le tableau recap de tous les serveurs
71

    
72
if(!defined('GLPI_ROOT')){
73
  define('GLPI_ROOT', '../../..');
74
 }
75
include_once (GLPI_ROOT . "/inc/includes.php");
76
//include_once (GLPI_CONFIG_DIR . "/config_db_slave.php");
77

    
78
//On essaye d'utiliser le proxy/cache mysql
79
//$DBSlave = new DBSlave;
80

    
81
//Fabrique la requete en fonction des besoins de liste des serveurs sous maintenance ou non
82
//$maintenance = 1 -> ceux qui sons sous maintenance (sur)
83
//$maintenance = 0 -> ceux qu'on ne sais pas (ça sera a faire quand on aura saisi tous les contrats)
84
//$maintenance = -1 -> ceux qui ne veulent pas de maintenance
85
//le champ peut etre a deux -> on ne veut meme plus les afficher
86
//
87
//
88
function local_make_query($data, $entityid, $maintenance) {
89
  $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.*,
90
(g5.nbeleves+g5.nbprofs) as nbusers, g5.nbpc as nbpc
91
FROM glpi_plugin_anet_epacks AS e
92
LEFT JOIN glpi_plugin_anet_epacks_ssh_max AS ssh ON e.FK_serveur=ssh.FK_serveur
93
LEFT JOIN glpi_entities AS g3 ON e.FK_client=g3.ID
94
LEFT JOIN glpi_computers AS g4 ON e.FK_serveur=g4.ID
95
LEFT JOIN glpi_plugin_anet_epacks_recencement_max AS g5 ON e.FK_serveur=g5.FK_serveur\n";
96

    
97
  //WHERE e.Fk_Serveur > '0'\n";
98
  if($data['name'] == "revendeur" || $data['name'] == "dsi") {
99
    if($maintenance == 0 || $maintenance ==  1) {
100
      $query .= "WHERE e.FK_contract >= '0' AND e.FK_activation='" . $entityid . "'\n";
101
    }
102
    else if($maintenance == -1) {
103
      $query .= "WHERE e.FK_contract='-1' AND e.FK_activation='" . $entityid . "'\n";
104
    }
105
      //GROUP BY e.FK_serveur
106
    $query .= "GROUP BY e.FK_serveur
107
ORDER BY client ASC
108
LIMIT 500;";
109
  }
110
  else {
111
    //On n'affiche pas les serveurs qui ne sont pas "Zen"
112
    if($maintenance == 0 || $maintenance ==  1) {
113
      $query .= "WHERE e.FK_contract >= '0' AND e.FK_Serveur>'0'\n";
114
    }
115
    else if($maintenance == -1) {
116
      $query .= "WHERE e.FK_contract='-1' AND e.FK_Serveur>'0'\n";
117
    }
118
    //GROUP BY e.FK_serveur
119
    //On ne peut pas group by client a cause de l'historique ou on avait pas la meme structure
120
    //de base
121
    $query .= "GROUP BY e.FK_serveur
122
ORDER BY client ASC
123
LIMIT 500;";
124
  }
125

    
126
  //  if($maintenance == -1) {
127
  //print $query;
128
  //  }
129
  return $query;
130
}
131

    
132

    
133
function local_make_array($q,$maintenance) {
134
  global $DB;
135
  global $DB;
136
  global $glpiid;
137

    
138
  $result = $DB->query($q) or die($DB->error());
139
    
140
  print "<table style=\"width:100%; padding: 0 10px 0 10px;\">
141
<tr class='tab_bg_2'>
142
  <th>Nom</th>
143
  <th><img src=\"img/stock_channel.png\" alt=\"Télémaintenance (SSH)\" title=\"Télémaintenance (SSH)\"></th>
144
  <th>Date du test</th>
145
  <th>Adresse DynDNS</th>
146
  <th><img src=\"img/computer.png\" alt=\"Nombre de postes\" title=\"Nombre de postes clients\"></th>
147
  <th><img src=\"img/stock_people.png\" alt=\"Nombre d'utilisateurs\" title=\"Nombre d'utilisateurs\"></th>
148
  <th><img src=\"img/stock_hand-signed.png\" title=\"Contrat\"></th>
149
</tr>\n";
150
    
151
  $total_nbpc = 0;
152
  $total_nbusers = 0;
153
  //La liste des entites qu'on affiche
154
  $tab_deja_affiche = array();
155
    
156
  for($i = 0; $i < $DB->numrows($result); $i++) {
157
    $data=$DB->fetch_array($result);
158
    $tab_deja_affiche[] = $data['entityid'];
159
    $ssh_dateLastOK = "";
160
    if($data['sshstatus'] == 1)
161
      $ssh_status = "<font color=\"green\">OK</font>";
162
    else if($data['sshdate']) {
163
      $ssh_status = "<font color=\"red\">ERR</font>";
164
      //Es-ce qu'on a deja reussi a se connecter sur ce serveur ?
165
      $queryLastOK = "SELECT sshdate FROM glpi_plugin_anet_epacks_ssh WHERE FK_serveur='" . $data['FK_serveur'] . "' AND sshstatus=1 ORDER BY sshdate DESC LIMIT 1";
166
      if($resultLastOK = $DB->query($queryLastOK)) {
167
        $dataLastOK = $DB->fetch_array($resultLastOK);
168
        if($dataLastOK[0]) {
169
          //          print_r($dataLastOK);
170
          $ssh_status .= "<br /><font color=\"green\">LAST OK</font>";
171
          $ssh_dateLastOK = "<br />" . $dataLastOK[0];
172
        }
173
      }
174
      else {
175
        $ssh_dateLastOK = "";
176
      }
177
      //print $queryLastOK;
178
    }
179
    else
180
      $ssh_status = "<font color=\"orange\">???</font>";
181
    print "<tr class='tab_bg_2'>
182
  <td align=\"left\">\n";
183
    if($data['entityid'] > 0) {
184
      print "    " . ($i+1) . ". <a href=\"../../manageentity/index.php?active_entity=" . $data['entityid'] . "\">" . $data['client'] . ": " . $data['serveur'] . "</a>\n";
185
    }
186
    else {
187
      print "    " . ($i+1) . ". " . $data['client'] . ": " . $data['serveur'] . "(abonnement zen jamais activé)\n";
188
    }
189
    print "  </td>
190
  <td>" . $ssh_status . "</td>
191
  <td>" . $data['sshdate'] . $ssh_dateLastOK . "</td>
192
  <td align=\"left\">" . $data['os_license_id'] . "<br />" . $data['os_license_number'] . "</td>
193
  <td>" . $data['nbpc'] . "</td>
194
  <td>" . $data['nbusers'] . "</td>
195
  <td>
196
  </td>
197
</tr>\n";
198
    /*
199
     <a href=\"../../../front/contract.php?contains[0]=" . $data['client'] . "\"><img src=\"img/stock_hand-signed.png\" title=\"Contrat\"></a>
200
     <a href=\"../../../front/tracking.php?contains[0]=" . $data['client'] . "\"><img src=\"img/stock_web-support.png\" title=\"Tickets\"></a>
201
     <a href=\"../../../front/user.php?contains[0]=" . $data['client'] . "\"><img src=\"img/stock_people.png\" title=\"Droits d'accès\"></a>
202
    */
203
    $total_nbpc += $data['nbpc'];
204
    $total_nbusers += $data['nbusers'];
205
  }
206
  
207
  //Maintenant toutes les entités sur lesquelles on a des droits recursifs
208
  $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";
209
  //print $queryR;
210
  $resultR = $DB->query($queryR);
211
  $listentity = "";
212
  for($r = 0; $r < $DB->numrows($resultR); $r++) {
213
    $dataR=$DB->fetch_array($resultR);
214
    $entityparent = $dataR['entity'];
215
    if($listentity != "")
216
      $listentity .= ", '" . $entityparent . "'";
217
    else
218
      $listentity = "'" . $entityparent . "'";
219
  }
220
  //$query = "SELECT ID FROM glpi_entities WHERE parentID='" . $entityparent . "'";
221
  
222
  $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.*,
223
(sum(g5.nbeleves)+sum(g5.nbprofs)) as nbusers, g5.nbpc as nbpc
224
FROM glpi_plugin_anet_epacks AS e
225
LEFT JOIN glpi_plugin_anet_epacks_ssh_max AS ssh ON e.FK_serveur=ssh.FK_serveur
226
LEFT JOIN glpi_entities AS g3 ON e.FK_client=g3.ID
227
LEFT JOIN glpi_computers AS g4 ON e.FK_serveur=g4.ID
228
LEFT JOIN glpi_plugin_anet_epacks_recencement_max AS g5 ON e.FK_serveur=g5.FK_serveur\n";
229
  //WHERE e.Fk_Serveur > '0'\n";
230

    
231

    
232
  if($maintenance == 0 || $maintenance ==  1) {
233
    $query .= "WHERE e.FK_contract >= '0'";
234
  }
235
  else if($maintenance == -1) {
236
    $query .= "WHERE e.FK_contract='-1'";
237
  }
238

    
239
  if(trim($listentity) != "")
240
    $query .= " AND g3.parentID IN (" . $listentity . ")\n";
241
  //GROUP BY e.FK_serveur
242
  $query .= "GROUP BY e.FK_client
243
ORDER BY client
244
LIMIT 500;";
245
  
246
  //print $query;
247
  
248
  $result = $DB->query($query) or die($DB->error());
249
  
250
  for($i = 0; $i < $DB->numrows($result); $i++) {
251
    $data=$DB->fetch_array($result);
252
    $ssh_dateLastOK = "";
253
    if(! in_array($data['entityid'],$tab_deja_affiche)) {
254
      $tab_deja_affiche[] = $data['entityid'];
255
      if($data['sshstatus'] == 1)
256
        $ssh_status = "<font color=\"green\">OK</font>";
257
      else if($data['sshdate']) {
258
        $ssh_status = "<font color=\"red\">ERR</font>";
259
        //Es-ce qu'on a deja reussi a se connecter sur ce serveur ?
260
        $queryLastOK = "SELECT sshdate FROM glpi_plugin_anet_epacks_ssh WHERE FK_serveur='" . $data['FK_serveur'] . "' AND sshstatus=1 ORDER BY sshdate DESC LIMIT 1";
261
        if($resultLastOK = $DB->query($queryLastOK)) {
262
          $dataLastOK = $DB->fetch_array($resultLastOK);
263
          if($dataLastOK[0]) {
264
            //          print_r($dataLastOK);
265
            $ssh_status .= "<br /><font color=\"green\">LAST OK</font>";
266
            $ssh_dateLastOK = "<br />" . $dataLastOK[0];
267
          }
268
        }
269
        else {
270
          $ssh_dateLastOK = "";
271
        }
272
        //print $queryLastOK;
273
      }
274
      else
275
        $ssh_status = "<font color=\"orange\">???</font>";
276
      print "<tr class='tab_bg_2'>
277
  <td align=\"left\">\n";
278
      if($data['entityid'] > 0) {
279
        print "    " . ($i+1) . ". <a href=\"../../manageentity/index.php?active_entity=" . $data['entityid'] . "\">" . $data['client'] . ": " . $data['serveur'] . "</a>\n";
280
      }
281
      else {
282
        print "    " . ($i+1) . ". " . $data['client'] . ": " . $data['serveur'] . "(abonnement zen jamais activé)\n";
283
      }
284
      print "  </td>
285
  <td>" . $ssh_status . "</td>
286
  <td>" . $data['sshdate'] . $ssh_dateLastOK . "</td>
287
  <td align=\"left\">" . $data['os_license_id'] . "<br />" . $data['os_license_number'] . "</td>
288
  <td>" . $data['nbpc'] . "</td>
289
  <td>" . $data['nbusers'] . "</td>
290
  <td>
291
  </td>
292
</tr>\n";
293
      /*
294
          <a href=\"../../../front/contract.php?contains[0]=" . $data['client'] . "\"><img src=\"img/stock_hand-signed.png\" title=\"Contrat\"></a>
295
          <a href=\"../../../front/tracking.php?contains[0]=" . $data['client'] . "\"><img src=\"img/stock_web-support.png\" title=\"Tickets\"></a>
296
          <a href=\"../../../front/user.php?contains[0]=" . $data['client'] . "\"><img src=\"img/stock_people.png\" title=\"Droits d'accès\"></a>
297
      */
298
      $total_nbpc += $data['nbpc'];
299
      $total_nbusers += $data['nbusers'];
300
    }
301
    else {
302
      //print "deja affiché :: " . $data['entityid'];
303
    }
304
  }
305
  
306
  
307
  
308
  /*
309
   <a href=\"../../../front/central.php?active_entity=" . $data['entityid'] . "\"><img src=\"img/stock_about.png\" title=\"Incarner le client " . $data['client'] . "\"></a>
310
   <a href=\"../../../front/computer.php?contains[0]=" . $data['client'] . "\"><img src=\"img/stock_form-add-field.png\" title=\"Inventaire\"></a>
311
  */
312
  
313
  print "<tr class='tab_bg_2'>
314
  <td colspan=\"4\">Totaux: </td>
315
  <td>" . $total_nbpc . "</td>
316
  <td>" . $total_nbusers . "</td>
317
  <td></td>
318
</tr>\n";
319
  
320
  print "</table>";
321
  
322
}
323

    
324
commonHeader("AbulEdu.NET -- Tableau récapitulatif -- Accueil RyXéo",$_SERVER['PHP_SELF'],"config","plugins");
325

    
326
$glpiid = $_SESSION['glpiID'];
327

    
328
global $DB;
329

    
330
$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";
331

    
332
//print $query;
333
//exit;
334

    
335
$result = $DB->query($query);
336
if($result) {
337
  $data=$DB->fetch_array($result);
338
  $entityid = $data['FK_entities'];
339
  if($data['name'] == "revendeur" || $data['name'] == "dsi" || $data['name'] == "super-admin") {
340
    $entityid = $data['FK_entities'];
341
    
342
    //print $query;
343
    //exit;
344
      
345
    print "<h1>Tableau récapitulatif de vos serveurs sous maintenance</h1>";
346
    $maintenance = 0;
347
    $querySM = local_make_query($data, $entityid, $maintenance);
348
    local_make_array($querySM,$maintenance);
349

    
350
    print "<h1>Tableau récapitulatif de vos serveurs hors maintenance</h1>";
351
    $maintenance = -1;
352
    $queryHM = local_make_query($data, $entityid, $maintenance);
353
    local_make_array($queryHM,$maintenance);
354
    
355
    commonFooter();
356
    exit;
357
  }
358
 }
359

    
360
?>
Redmine Appliance - Powered by TurnKey Linux