function generateSyntheseReport($array, $pdf=TRUE) {
      global $DB;

      if (count($array) == 0) {
         return;
      }
      $end_date = $array['synthesedate_end'];
      $end_date_timestamp = strtotime($end_date);
      $number   = $array['synthesenumber'];
      $period   = $array['syntheseperiod'];

      $componentscatalogs_id = $array['componentscatalogs_id'];

      $pmComponent    = new PluginMonitoringComponent();
      $pmUnavailability = new PluginMonitoringUnavailability();
      $pmServiceevent = new PluginMonitoringServiceevent();

      if ($pdf) {
         PluginMonitoringReport::beginCapture();
      }
      echo "<table class='tab_cadrehov'>";
      foreach ($array['components_id'] as $components_id) {
         $pmComponent->getFromDB($components_id);
         array_unshift($array['perfname'][$components_id], 'avaibility');
         array_unshift($array['perfname_val'][$components_id], 1);
         echo '<tr class="tab_bg_1" height="90">';
         echo '<th colspan="'.(3 + ($number * 2)).'">';
         echo $pmComponent->getName();
         echo '</th>';
         echo '</tr>';

         foreach ($array['perfname'][$components_id] as $num=>$groupname) {
            echo '<tr class="tab_bg_1">';
            echo '<th colspan="'.(3 + ($number * 2)).'">';
            if ($groupname == 'avaibility') {
               echo __('Avaibility', 'monitoring');
            } else {
               echo $groupname;
            }
            echo '</th>';
            echo '</tr>';

            echo '<tr class="tab_bg_1">';
            echo '<th rowspan="2">';
            echo __('Name');
            echo '</th>';
            echo '<th rowspan="2">';
            echo __('Entity');
            echo '</th>';
            echo '<th rowspan="2">';
            echo __('Itemtype');
            echo '</th>';
            $a_year = array();
            for ($i = $number; $i >= 1;$i--) {
               $year = date('Y', strtotime("-".$i." ".$period, $end_date_timestamp));
               if (!isset($a_year[$year])) {
                  $a_year[$year] = 2;
               } else {
                  $a_year[$year] += 2;
               }
            }
            foreach ($a_year as $year=>$colspan) {
               echo '<th colspan="'.$colspan.'">';
               echo $year;
               echo '</th>';
            }
            echo '</tr>';

            echo '<tr class="tab_bg_1">';
            for ($i = $number; $i >= 1;$i--) {
               echo '<th colspan="2">';
               echo Html::convDate(date('m-d', strtotime("-".$i." ".$period, $end_date_timestamp)));
               echo "<br/>";
               echo Html::convDate(date('m-d', strtotime("-".($i-1)." ".$period, $end_date_timestamp)));
               echo '</th>';
            }
            echo '</tr>';

            $query = "SELECT `glpi_plugin_monitoring_componentscatalogs_hosts`.*,
                  `glpi_plugin_monitoring_services`.`id` as sid FROM `glpi_plugin_monitoring_componentscatalogs_hosts`
               LEFT JOIN `glpi_plugin_monitoring_services`
                  ON `glpi_plugin_monitoring_componentscatalogs_hosts`.`id`=`plugin_monitoring_componentscatalogs_hosts_id`
               WHERE `plugin_monitoring_componentscalalog_id`='".$componentscatalogs_id."'
                  AND `plugin_monitoring_components_id`='".$components_id."'";
            $result = $DB->query($query);
            $rownb = true;
            while ($data=$DB->fetch_array($result)) {
               $itemtype = $data['itemtype'];
               $item = new $itemtype();
               $item->getFromDB($data['items_id']);

               if ($groupname == 'avaibility') {
                  $a_times = $pmUnavailability->parseEvents($data['id'], '',
                                                          date('Y-m-d', strtotime("-".($number + 1)." ".$period, $end_date_timestamp)),
                                                          date('Y-m-d', strtotime("-".$number." ".$period, $end_date_timestamp)));
                  $previous_value = round(((($a_times[1] - $a_times[0]) / $a_times[1]) * 100), 3);
               } else {
                  $previous_value = 0;
               }
               echo '<tr class="tab_bg'.(($rownb = !$rownb)?'_4':'_1').'">';
               echo '<td>';
               echo $item->getLink();
               echo '</td>';
               echo '<td>';
               echo Dropdown::getDropdownName("glpi_entities", $item->fields['entities_id']);
               echo '</td>';
               echo '<td>';
               echo $item->getTypeName();
               echo '</td>';
               for ($i = $number; $i >= 1;$i--) {
                  $startdatet = date('Y-m-d', strtotime("-".$i." ".$period, $end_date_timestamp));
                  $enddatet   = date('Y-m-d', strtotime("-".($i-1)." ".$period, $end_date_timestamp));
                  if ($groupname == 'avaibility') {
                     $a_times = $pmUnavailability->parseEvents($data['id'], '', $startdatet, $enddatet);
                     $value = round(((($a_times[1] - $a_times[0]) / $a_times[1]) * 100), 2);
                  } else {
                     $queryevents = "SELECT * FROM `glpi_plugin_monitoring_serviceevents`
                        WHERE `plugin_monitoring_services_id`='".$data['sid']."'
                           AND `date` >= '".$startdatet."'
                           AND `date` <= '".$enddatet."'
                        ORDER BY `date`";
                     $resultevents = $DB->query($queryevents);
                     $_SESSION['plugin_monitoring_checkinterval'] = PluginMonitoringComponent::getTimeBetween2Checks($pmComponent->fields['id']);
                     $ret = $pmServiceevent->getData($resultevents, $pmComponent->fields['graph_template'], $startdatet, $enddatet);
                     if (!isset($ret[0][$groupname])) {
                        $value = 0;
                     } else {
                        $value = round(array_sum($ret[0][$groupname]) / count($ret[0][$groupname]), 2);
                     }
                  }

                  $bgcolor = '';
                  if ($array['perfname_val'][$components_id][$num] == 1) {
                     if ($previous_value < $value) {
                        $bgcolor = 'style="background-color:#d1ffc3"';
                     } else if ($previous_value > $value) {
                        $bgcolor = 'style="background-color:#ffd1d3"';
                     }
                  } else {
                     if ($previous_value < $value) {
                        $bgcolor = 'style="background-color:#ffd1d3"';
                     } else if ($previous_value > $value) {
                        $bgcolor = 'style="background-color:#d1ffc3"';
                     }
                  }

                  echo '<td '.$bgcolor.'>';
                  if ($groupname == 'avaibility') {
                     echo $value."%";
                  } else {
                     if ($value > 3000000000) {
                        echo round($value/1000000000, 2).'T';
                     } else if ($value > 3000000) {
                        echo round($value/1000000, 2).'M';
                     } else if ($value > 3000) {
                        echo round($value/1000, 2).'K';
                     } else {
                        echo $value;
                     }
                  }
                  echo '</td>';
                  echo '<td '.$bgcolor.'>';
                  if ($array['perfname_val'][$components_id][$num] == 1) {
                     if ($previous_value < $value) {
                        echo '<img src="../pics/arrow-up-right.png" width="16" />';
                     } else if ($previous_value == $value) {
                        echo '<img src="../pics/arrow-right.png" width="16" />';
                     } else if ($previous_value > $value) {
                        echo '<img src="../pics/arrow-down-right.png" width="16" />';
                     }
                  } else {
                     if ($previous_value < $value) {
                        echo '<img src="../pics/arrow-up-right_inv.png" width="16" />';
                     } else if ($previous_value == $value) {
                        echo '<img src="../pics/arrow-right.png" width="16" />';
                     } else if ($previous_value > $value) {
                        echo '<img src="../pics/arrow-down-right_inv.png" width="16" />';
                     }
                  }
                  $previous_value = $value;
                  echo '</td>';
               }
               echo "</tr>";

            }
         }
         echo '<tr class="tab_bg_1" height="50">';
         echo '<td colspan="'.(3 + ($number * 2)).'">';
         echo '</td>';
         echo '</tr>';
      }
      echo "</table>";
      if ($pdf) {
         $content = PluginMonitoringReport::endCapture();
         PluginMonitoringReport::generatePDF($content, 'L');
      }
   }
 function generateSyntheseReport($array)
 {
     global $DB;
     $end_date = $array[$array['reporttype'] . 'date_end'];
     $end_date_timestamp = strtotime($end_date);
     $number = $array[$array['reporttype'] . 'number'];
     $period = $array[$array['reporttype'] . 'period'];
     $componentscatalogs_id = $array['componentscatalogs_id'];
     $pmComponent = new PluginMonitoringComponent();
     $pmUnavaibility = new PluginMonitoringUnavaibility();
     $pmServiceevent = new PluginMonitoringServiceevent();
     PluginMonitoringReport::beginCapture();
     $a_groups = array("avaibility");
     foreach ($array['perfname'] as $perfname) {
         $a_groups[] = $perfname;
     }
     $a_groups = array_unique($a_groups);
     foreach ($a_groups as $groupname) {
         foreach ($array['components_id'] as $components_id) {
             $pmComponent->getFromDB($components_id);
             echo "<table class='tab_cadre_fixe'>";
             echo '<tr class="tab_bg_1">';
             echo '<th colspan="' . (3 + $number * 2) . '">';
             echo $pmComponent->getName() . " / ";
             if ($groupname == 'avaibility') {
                 echo __('Avaibility', 'monitoring');
             } else {
                 echo $groupname;
             }
             echo '</th>';
             echo '</tr>';
             echo '<tr class="tab_bg_1">';
             echo '<th>';
             echo __('Name');
             echo '</th>';
             echo '<th>';
             echo __('Entity');
             echo '</th>';
             echo '<th>';
             echo __('Itemtype');
             echo '</th>';
             for ($i = $number; $i >= 1; $i--) {
                 echo '<th colspan="2">';
                 echo Html::convDate(date('Y-m-d', strtotime("-" . $i . " " . $period, $end_date_timestamp)));
                 echo "<br/>";
                 echo Html::convDate(date('Y-m-d', strtotime("-" . ($i - 1) . " " . $period, $end_date_timestamp)));
                 echo '</th>';
             }
             echo '</tr>';
             $query = "SELECT `glpi_plugin_monitoring_componentscatalogs_hosts`.*, \n                  `glpi_plugin_monitoring_services`.`id` as sid FROM `glpi_plugin_monitoring_componentscatalogs_hosts`\n               LEFT JOIN `glpi_plugin_monitoring_services`\n                  ON `glpi_plugin_monitoring_componentscatalogs_hosts`.`id`=`plugin_monitoring_componentscatalogs_hosts_id`\n               WHERE `plugin_monitoring_componentscalalog_id`='" . $componentscatalogs_id . "'\n                  AND `plugin_monitoring_components_id`='" . $components_id . "'";
             $result = $DB->query($query);
             $rownb = true;
             while ($data = $DB->fetch_array($result)) {
                 $itemtype = $data['itemtype'];
                 $item = new $itemtype();
                 $item->getFromDB($data['items_id']);
                 if ($groupname == 'avaibility') {
                     $a_times = $pmUnavaibility->parseEvents($data['id'], '', date('Y-m-d', strtotime("-" . ($number + 1) . " " . $period, $end_date_timestamp)), date('Y-m-d', strtotime("-" . $number . " " . $period, $end_date_timestamp)));
                     $previous_value = round(($a_times[1] - $a_times[0]) / $a_times[1] * 100, 3);
                 } else {
                     $previous_value = 0;
                 }
                 echo '<tr class="tab_bg_1' . (($rownb = !$rownb) ? '_2' : '') . '">';
                 echo '<td>';
                 echo $item->getName();
                 echo '</td>';
                 echo '<td>';
                 echo Dropdown::getDropdownName("glpi_entities", $item->fields['entities_id']);
                 echo '</td>';
                 echo '<td>';
                 echo $item->getTypeName();
                 echo '</td>';
                 for ($i = $number; $i >= 1; $i--) {
                     echo '<td>';
                     $startdatet = date('Y-m-d', strtotime("-" . $i . " " . $period, $end_date_timestamp));
                     $enddatet = date('Y-m-d', strtotime("-" . ($i - 1) . " " . $period, $end_date_timestamp));
                     if ($groupname == 'avaibility') {
                         $a_times = $pmUnavaibility->parseEvents($data['id'], '', $startdatet, $enddatet);
                         $value = round(($a_times[1] - $a_times[0]) / $a_times[1] * 100, 3);
                         echo $value . "%";
                     } else {
                         $queryevents = "SELECT * FROM `glpi_plugin_monitoring_serviceevents`\n                        WHERE `plugin_monitoring_services_id`='" . $data['sid'] . "'\n                           AND `date` >= '" . $startdatet . "'\n                           AND `date` <= '" . $enddatet . "'\n                        ORDER BY `date`";
                         $resultevents = $DB->query($queryevents);
                         $ret = $pmServiceevent->getData($resultevents, $pmComponent->fields['graph_template']);
                         $value = round(array_sum($ret[0][$groupname]) / count($ret[0][$groupname]), 3);
                         echo $value;
                     }
                     echo '</td>';
                     echo '<td>';
                     if ($previous_value < $value) {
                         echo '<img src="../pics/arrow-up-right.png" width="16" />';
                     } else {
                         if ($previous_value == $value) {
                             echo '<img src="../pics/arrow-right.png" width="16" />';
                         } else {
                             if ($previous_value > $value) {
                                 echo '<img src="../pics/arrow-down-right.png" width="16" />';
                             }
                         }
                     }
                     $previous_value = $value;
                     echo '</td>';
                 }
                 echo "</tr>";
             }
             echo "</table>";
         }
         echo "<br/><br/>";
     }
     $content = PluginMonitoringReport::endCapture();
     PluginMonitoringReport::generatePDF($content, 'L');
 }