static function move_item($params) { //get current order json $datas = json_decode(PluginFusioninventoryDeployOrder::getJson($params['orders_id']), TRUE); //get data on old index $moved_check = $datas['jobs']['actions'][$params['old_index']]; //remove this old index in json unset($datas['jobs']['actions'][$params['old_index']]); //insert it in new index (array_splice for insertion, ex : http://stackoverflow.com/a/3797526) array_splice($datas['jobs']['actions'], $params['new_index'], 0, array($moved_check)); //update order PluginFusioninventoryDeployOrder::updateOrderJson($params['orders_id'], $datas); }
static function addFileInRepo($params) { $deployFile = new self(); $filename = addslashes($params['filename']); $file_tmp_name = $params['file_tmp_name']; $maxPartSize = 1024 * 1024; $repoPath = GLPI_PLUGIN_DOC_DIR . "/fusioninventory/files/repository/"; $tmpFilepart = tempnam(GLPI_PLUGIN_DOC_DIR . "/fusioninventory/", "filestore"); $sha512 = hash_file('sha512', $file_tmp_name); $short_sha512 = substr($sha512, 0, 6); $file_present_in_repo = FALSE; if ($deployFile->checkPresenceFile($sha512)) { $file_present_in_repo = TRUE; } $file_present_in_db = $deployFile->getFromDBByQuery("WHERE shortsha512 = '" . $short_sha512 . "'"); //Manifest files contains the multiparts list attached to the file $manifest_path = GLPI_PLUGIN_DOC_DIR . "/fusioninventory/files/manifests/"; $manifest_filename = $manifest_path . $sha512; $new_entry = array('name' => $filename, 'p2p' => $params['p2p'], 'p2p-retention-duration' => $params['p2p-retention-duration'], 'uncompress' => $params['uncompress']); $fdIn = fopen($file_tmp_name, 'rb'); if (!$fdIn) { return FALSE; } $fdPart = NULL; $multiparts = array(); do { clearstatcache(); if (file_exists($tmpFilepart)) { if (feof($fdIn) || filesize($tmpFilepart) >= $maxPartSize) { $part_sha512 = $deployFile->registerFilepart($repoPath, $tmpFilepart, $file_present_in_repo); unlink($tmpFilepart); $multiparts[] = $part_sha512; } } if (feof($fdIn)) { break; } $data = fread($fdIn, 1024 * 1024); $fdPart = gzopen($tmpFilepart, 'a'); gzwrite($fdPart, $data, strlen($data)); gzclose($fdPart); } while (1); // $new_entry['multiparts'] = $multiparts; //create manifest file if (!$file_present_in_repo) { $handle = fopen($manifest_filename, "w+"); if ($handle) { foreach ($multiparts as $sha) { fwrite($handle, $sha . "\n"); } fclose($handle); } } //TODO: Add a new files interface to list, create, manage entities and visibility // entity on a file is just anticipated and will be fully used later if (!$file_present_in_db) { $entry = array("name" => $filename, "filesize" => $params['filesize'], "mimetype" => $params['mime_type'], "sha512" => $sha512, "shortsha512" => $short_sha512, "comments" => "", "date_mod" => date('Y-m-d H:i:s'), "entities_id" => 0, "is_recursive" => 1); $deployFile->add($entry); } //get current order json $datas = json_decode(PluginFusioninventoryDeployOrder::getJson($params['orders_id']), TRUE); //add new entry $datas['associatedFiles'][$sha512] = $new_entry; if (!in_array($sha512, $datas['jobs']['associatedFiles'])) { $datas['jobs']['associatedFiles'][] = $sha512; } //update order PluginFusioninventoryDeployOrder::updateOrderJson($params['orders_id'], $datas); return TRUE; }
@copyright Copyright (c) 2010-2014 FusionInventory team @license AGPL License 3.0 or (at your option) any later version http://www.gnu.org/licenses/agpl-3.0-standalone.html @link http://www.fusioninventory.org/ @link http://forge.fusioninventory.org/projects/fusioninventory-for-glpi/ @since 2010 ------------------------------------------------------------------------ */ include "../../../inc/includes.php"; Session::checkLoginUser(); if (isset($_POST['update_json'])) { $order = new PluginFusioninventoryDeployOrder(); $json_clean = stripcslashes($_POST['json']); $json = json_decode($json_clean, TRUE); $ret = PluginFusioninventoryDeployOrder::updateOrderJson($_POST['orders_id'], $json); Html::back(); exit; } elseif (isset($_POST['add_item'])) { $data = array_map(array('Toolbox', 'stripslashes_deep'), $_POST); PluginFusioninventoryDeployPackage::alter_json('add_item', $data); Html::back(); } elseif (isset($_POST['save_item'])) { $data = array_map(array('Toolbox', 'stripslashes_deep'), $_POST); PluginFusioninventoryDeployPackage::alter_json('save_item', $data); Html::back(); } elseif (isset($_POST['remove_item'])) { $data = array_map(array('Toolbox', 'stripslashes_deep'), $_POST); PluginFusioninventoryDeployPackage::alter_json('remove_item', $data); Html::back(); }