static function httpSendFile($params)
 {
     if (!isset($params['file'])) {
         header("HTTP/1.1 500");
         exit;
     }
     $matches = array();
     preg_match('/.\\/..\\/([^\\/]+)/', $params['file'], $matches);
     $sha512 = $matches[1];
     //      $short_sha512 = substr($sha512, 0, 6);
     $repoPath = GLPI_PLUGIN_DOC_DIR . "/fusioninventory/files/repository/";
     $filePath = $repoPath . PluginFusioninventoryDeployFile::getDirBySha512($sha512) . '/' . $sha512;
     if (!is_file($filePath)) {
         header("HTTP/1.1 404");
         print "\n" . $filePath . "\n\n";
         exit;
     } else {
         if (!is_readable($filePath)) {
             header("HTTP/1.1 403");
             exit;
         }
     }
     error_reporting(0);
     header('Content-Description: File Transfer');
     header('Content-Type: application/octet-stream');
     header('Content-Disposition: attachment; filename=' . $sha512);
     header('Content-Transfer-Encoding: binary');
     header('Expires: 0');
     header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
     header('Pragma: public');
     header('Content-Length: ' . filesize($filePath));
     if (ob_get_level() > 0) {
         ob_clean();
     }
     flush();
     readfile($filePath);
     exit;
 }
 /**
  * Used to export package
  *
  */
 function exportPackage($packages_id)
 {
     $this->getFromDB($packages_id);
     if (empty($this->fields['uuid'])) {
         $input = array('id' => $this->fields['id'], 'uuid' => Rule::getUuid());
         $this->update($input);
     }
     $pfDeployOrder = new PluginFusioninventoryDeployOrder();
     $pfDeployFile = new PluginFusioninventoryDeployFile();
     // Generate JSON
     $a_xml = array();
     $input = $this->fields;
     unset($input['id']);
     $a_xml['package'] = $input;
     $a_xml['orders'] = array();
     $a_xml['files'] = array();
     $a_xml['manifests'] = array();
     $a_xml['repository'] = array();
     $a_files = array();
     $a_data = $pfDeployOrder->find("`plugin_fusioninventory_deploypackages_id`='" . $this->fields['id'] . "'");
     foreach ($a_data as $data) {
         unset($data['id']);
         unset($data['plugin_fusioninventory_deploypackages_id']);
         $a_xml['orders'][] = $data;
         $json = json_decode($data['json'], true);
         $a_files = array_merge($a_files, $json['associatedFiles']);
     }
     // Add files
     foreach ($a_files as $files_id => $data) {
         $a_pkgfiles = current($pfDeployFile->find("`sha512`='" . $files_id . "'", '', 1));
         if (count($a_pkgfiles) > 0) {
             unset($a_pkgfiles['id']);
             $a_xml['files'][] = $a_pkgfiles;
         }
     }
     // Create zip with JSON and files
     $name = preg_replace("/[^a-zA-Z0-9]/", '', $this->fields['name']);
     $filename = GLPI_PLUGIN_DOC_DIR . "/fusioninventory/files/export/" . $this->fields['uuid'] . "." . $name . ".zip";
     if (file_exists($filename)) {
         unlink($filename);
     }
     $zip = new ZipArchive();
     if ($zip->open($filename) == TRUE) {
         if ($zip->open($filename, ZipArchive::CREATE) == TRUE) {
             $zip->addEmptyDir('files');
             $zip->addEmptyDir('files/manifests');
             $zip->addEmptyDir('files/repository');
             foreach ($a_files as $hash => $data) {
                 $sha512 = file_get_contents(GLPI_PLUGIN_DOC_DIR . "/fusioninventory/files/manifests/" . $hash);
                 $sha512 = trim($sha512);
                 $zip->addFile(GLPI_PLUGIN_DOC_DIR . "/fusioninventory/files/manifests/" . $hash, "files/manifests/" . $hash);
                 $a_xml['manifests'][] = $hash;
                 $file = PluginFusioninventoryDeployFile::getDirBySha512($sha512) . "/" . $sha512;
                 $zip->addFile(GLPI_PLUGIN_DOC_DIR . "/fusioninventory/files/repository/" . $file, "files/repository/" . $file);
                 $a_xml['repository'][] = $file;
             }
             $json_string = json_encode($a_xml);
             $zip->addFromString('information.json', $json_string);
         }
         $zip->close();
         Session::addMessageAfterRedirect(__("Package exported in", "fusioninventory") . " " . GLPI_PLUGIN_DOC_DIR . "/fusioninventory/files/export/" . $this->fields['uuid'] . "." . $name . ".zip");
     }
 }