.
*
* ------------------------------------------------------------------------
*
* This file is used to manage the display part of tasks.
*
* ------------------------------------------------------------------------
*
* @package FusionInventory
* @author David Durieux
* @author Kevin Roy
* @copyright Copyright (c) 2010-2016 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 https://github.com/fusioninventory/fusioninventory-for-glpi
*
*/
if (!defined('GLPI_ROOT')) {
die("Sorry. You can't access this file directly");
}
/**
* Manage the display part of tasks.
*/
class PluginFusioninventoryTaskView extends PluginFusioninventoryCommonView {
/**
* __contruct function where initialize base URLs
*/
function __construct() {
parent::__construct();
$this->base_urls = array_merge( $this->base_urls, [
'fi.job.logs' => $this->getBaseUrlFor('fi.ajax') . "/taskjob_logs.php",
]);
}
/**
* Show job logs
*/
function showJobLogs() {
echo "
";
echo "
";
// add a list limit for include old jobs
$include_oldjobs_id = $this->showDropdownFromArray(
__("Include old jobs", 'fusioninventory'),
null,
[
1 => __('Last'),
2 => 2,
5 => 5,
10 => 10,
25 => 25,
50 => 50,
100 => 100,
250 => 250,
-1 => __('All')
],
['value' => $_SESSION['glpi_plugin_fusioninventory']['includeoldjobs']]
);
// add an auto-refresh control
$refresh_randid = $this->showDropdownFromArray(
__("refresh interval", "fusioninventory"),
null,
[
"off" => __('Off', 'fusioninventory'),
"1" => '1 '._n('second', 'seconds', 1),
"5" => '5 '._n('second', 'seconds', 5),
"10" => '10 '._n('second', 'seconds', 10),
"60" => '1 '._n('minute', 'minutes', 1),
"120" => '2 '._n('minute', 'minutes', 2),
"300" => '5 '._n('minute', 'minutes', 5),
"600" => '10 '._n('minute', 'minutes', 10),
],
['value' => $_SESSION['glpi_plugin_fusioninventory']['refresh']]
);
// display export button
echo "
";
// Add a manual refresh button
echo "
";
echo "";
echo "
"; // .refresh_button
echo "
"; // .fusinv_form
echo "
"; // .fusinv_panel
// Template structure for tasks' blocks
echo "";
// Template structure for jobs' blocks
echo "";
// Template structure for targets' blocks
echo "";
// Template structure for targets' statistics
echo "";
// Template for counters' blocks
echo "";
// List of counter names
echo Html::scriptBlock("$(document).ready(function() {
taskjobs.statuses_order = {
last_executions: [
'agents_prepared',
'agents_running',
'agents_cancelled',
],
last_finish_states: [
'agents_notdone',
'agents_success',
'agents_error'
]
};
taskjobs.statuses_names = {
'agents_notdone': '". __('Not done yet', 'fusioninventory')."',
'agents_error': '". __('In error', 'fusioninventory') . "',
'agents_success': '". __('Successful', 'fusioninventory')."',
'agents_running': '". __('Running', 'fusioninventory')."',
'agents_prepared': '". __('Prepared', 'fusioninventory')."',
'agents_postponed': '". __('Postponed', 'fusioninventory')."',
'agents_cancelled': '". __('Cancelled', 'fusioninventory')."',
};
taskjobs.logstatuses_names = ".
json_encode(PluginFusioninventoryTaskjoblog::dropdownStateValues()).";
});");
// Template for agents' blocks
echo "";
// Display empty block for each jobs display
// which will be rendered later by mustache.js
echo "";
echo "";
echo "";
if (!$new_item) {
echo " ";
$this->showCheckboxField( __('Active'), "is_active" );
$datetime_field_options = [
'timestep' => 1,
'maybeempty' => true,
];
$this->showDateTimeField(__('Schedule start', 'fusioninventory'),
"datetime_start", $datetime_field_options
);
$this->showDateTimeField(__('Schedule end', 'fusioninventory'),
"datetime_end", $datetime_field_options
);
$this->showDropdownForItemtype(__('Preparation timeslot', 'fusioninventory'),
"PluginFusioninventoryTimeslot",
['name' => 'plugin_fusioninventory_timeslots_prep_id',
'value' => $this->fields['plugin_fusioninventory_timeslots_prep_id']
]
);
$this->showDropdownForItemtype(
__('Execution timeslot', 'fusioninventory'),
"PluginFusioninventoryTimeslot",
['name' => 'plugin_fusioninventory_timeslots_exec_id',
'value' => $this->fields['plugin_fusioninventory_timeslots_exec_id']]
);
$this->showIntegerField( __('Agent wakeup interval (in minutes)', 'fusioninventory'), "wakeup_agent_time",
['value' => $this->fields['wakeup_agent_time'],
'toadd' => ['0' => __('Never')],
'min' => 1,
'step' => 1
] );
$this->showIntegerField( __('Number of agents to wake up', 'fusioninventory'), "wakeup_agent_counter",
['value' => $this->fields['wakeup_agent_counter'],
'toadd' => ['0' => __('None')],
'min' => 0,
'step' => 1
] );
echo " ";
}
echo "";
echo " | ";
echo "
";
$this->showFormButtons($options);
return true;
}
function showFormButtons($options = []) {
if (isset($this->fields['id'])) {
$ID = $this->fields['id'];
}
echo "";
echo "";
if ($this->isNewID($ID)) {
echo Html::submit(_x('button', 'Add'), ['name' => 'add']);
} else {
echo Html::hidden('id', ['value' => $ID]);
echo Html::submit(_x('button', 'Save'), ['name' => 'update']);
}
echo " | ";
if ($this->fields['is_active']) {
echo "";
echo Html::submit(__('Force start', 'fusioninventory'),
['name' => 'forcestart']);
echo " | ";
}
echo "";
if ($this->can($ID, PURGE)) {
echo Html::submit(_x('button', 'Delete permanently'),
['name' => 'purge',
'confirm' => __('Confirm the final deletion?')
]);
}
echo " | ";
echo "
";
// Close for Form
echo "";
Html::closeForm();
}
/**
* Manage the different actions in when submit form (add, update,purge...)
*
* @param array $postvars
*/
public function submitForm($postvars) {
if (isset($postvars['forcestart'])) {
Session::checkRight('plugin_fusioninventory_task', UPDATE);
$this->getFromDB($postvars['id']);
$this->forceRunning();
Html::back();
} else if (isset ($postvars["add"])) {
Session::checkRight('plugin_fusioninventory_task', CREATE);
$items_id = $this->add($postvars);
Html::redirect(str_replace("add=1", "", $_SERVER['HTTP_REFERER'])."?id=".$items_id);
} else if (isset($postvars["purge"])) {
Session::checkRight('plugin_fusioninventory_task', PURGE);
$pfTaskJob = new PluginFusioninventoryTaskjob();
$taskjobs = $pfTaskJob->find(['plugin_fusioninventory_tasks_id' => $postvars['id']]);
foreach ($taskjobs as $taskjob) {
$pfTaskJob->delete($taskjob);
}
$this->delete($postvars);
Html::redirect(Toolbox::getItemTypeSearchURL(get_class($this)));
} else if (isset($_POST["update"])) {
Session::checkRight('plugin_fusioninventory_task', UPDATE);
$this->getFromDB($postvars['id']);
//Ensure empty value are set to NULL for datetime fields
if (isset($postvars['datetime_start']) && $postvars['datetime_start'] === '') {
$postvars['datetime_start'] = 'NULL';
}
if (isset($postvars['datetime_end']) && $postvars['datetime_end'] === '') {
$postvars['datetime_end'] = 'NULL';
}
$this->update($postvars);
Html::back();
} else if (isset($postvars['export_jobs'])) {
Session::checkRight('plugin_fusioninventory_task', READ);
$this->csvExport($postvars);
}
}
/**
* Define reprepare_if_successful field when get empty item
*/
function getEmpty() {
parent::getEmpty();
$pfConfig = new PluginFusioninventoryConfig();
$this->fields['reprepare_if_successful'] = $pfConfig->getValue('reprepare_job');
}
function rawSearchOptions() {
$tab = [];
$tab[] = [
'id' => 'common',
'name' => __('Characteristics')
];
$tab[] = [
'id' => '1',
'table' => $this->getTable(),
'field' => 'name',
'name' => __('Name'),
'datatype' => 'itemlink',
'autocomplete' => true,
];
return $tab;
}
}