WIP:Planned downtime copy.

This commit is contained in:
Calvo 2022-01-27 18:23:07 +01:00
parent 4da16bedf8
commit a92fe64b64
3 changed files with 144 additions and 57 deletions

View File

@ -135,6 +135,7 @@ $first_create = (int) get_parameter('first_create');
$create_downtime = (int) get_parameter('create_downtime');
$update_downtime = (int) get_parameter('update_downtime');
$edit_downtime = (int) get_parameter('edit_downtime');
$downtime_copy = (int) get_parameter('downtime_copy');
$id_downtime = (int) get_parameter('id_downtime');
$id_agent = (int) get_parameter('id_agent');
@ -420,6 +421,15 @@ if ($create_downtime || $update_downtime) {
}
}
if ($downtime_copy) {
$result = planned_downtimes_copy($id_downtime);
if ($result === true) {
ui_print_error_message(__('Successfully copied'));
} else {
ui_print_error_message(__('Could not be copied'));
}
}
// Have any data to show ?
if ($id_downtime > 0) {
// Columns of the table tplanned_downtime.
@ -628,20 +638,20 @@ $table->data[5][1] = "
<tr><td>".ui_get_using_system_timezone_warning().'</td></tr>
<tr>
<td>'.__('Type Periodicity:').'&nbsp;'.html_print_select(
[
'weekly' => __('Weekly'),
'monthly' => __('Monthly'),
],
'type_periodicity',
$type_periodicity,
'change_type_periodicity();',
'',
0,
true,
false,
true,
'',
$disabled_in_execution
[
'weekly' => __('Weekly'),
'monthly' => __('Monthly'),
],
'type_periodicity',
$type_periodicity,
'change_type_periodicity();',
'',
0,
true,
false,
true,
'',
$disabled_in_execution
)."</td>
</tr>
<tr>
@ -661,31 +671,31 @@ $table->data[5][1] = "
<tr>
<td>".__('From day:').'</td>
<td>'.html_print_select(
$days,
'periodically_day_from',
$periodically_day_from,
'',
'',
0,
true,
false,
true,
'',
$disabled_in_execution
$days,
'periodically_day_from',
$periodically_day_from,
'',
'',
0,
true,
false,
true,
'',
$disabled_in_execution
).'</td>
<td>'.__('To day:').'</td>
<td>'.html_print_select(
$days,
'periodically_day_to',
$periodically_day_to,
'',
'',
0,
true,
false,
true,
'',
$disabled_in_execution
$days,
'periodically_day_to',
$periodically_day_to,
'',
'',
0,
true,
false,
true,
'',
$disabled_in_execution
).'</td>
<td>'.ui_print_help_tip(__('The end day must be higher than the start day'), true).'</td>
</tr>
@ -694,26 +704,26 @@ $table->data[5][1] = "
<tr>
<td>'.__('From hour:').'</td>
<td>'.html_print_input_text(
'periodically_time_from',
$periodically_time_from,
'',
7,
7,
true,
$disabled_in_execution
'periodically_time_from',
$periodically_time_from,
'',
7,
7,
true,
$disabled_in_execution
).ui_print_help_tip(
__('The end time must be higher than the start time'),
true
).'</td>
<td>'.__('To hour:').'</td>
<td>'.html_print_input_text(
'periodically_time_to',
$periodically_time_to,
'',
7,
7,
true,
$disabled_in_execution
'periodically_time_to',
$periodically_time_to,
'',
7,
7,
true,
$disabled_in_execution
).ui_print_help_tip(
__('The end time must be higher than the start time'),
true
@ -997,13 +1007,13 @@ $table->data['module'][1] = "
<td class='cell_delete_button' style='text-align: right; width:10%;' id=''>".'<a class="link_delete"
onclick="if(!confirm(\''.__('Are you sure?').'\')) return false;"
href="">'.html_print_image(
'images/cross.png',
true,
[
'border' => '0',
'alt' => __('Delete'),
'class' => 'invert_filter',
]
'images/cross.png',
true,
[
'border' => '0',
'alt' => __('Delete'),
'class' => 'invert_filter',
]
).'</a>'."</td>
</tr>
<tr class='datos2' id='add_modules_row'>

View File

@ -405,6 +405,7 @@ else {
if ($write_permisson || $manage_permisson) {
$table->head['stop'] = __('Stop downtime');
$table->head['copy'] = __('Copy');
$table->head['edit'] = __('Edit');
$table->head['delete'] = __('Delete');
}
@ -492,6 +493,8 @@ else {
if (check_acl_restricted_all($config['id_user'], $downtime['id_group'], 'AW')
|| check_acl_restricted_all($config['id_user'], $downtime['id_group'], 'AD')
) {
// Copy.
$data['copy'] = '<a href="index.php?sec=extensions&sec2=godmode/agentes/planned_downtime.editor&downtime_copy=1&id_downtime='.$downtime['id'].'">'.html_print_image('images/copy.png', true, ['title' => __('Copy'), 'class' => 'invert_filter']).'</a>';
// Edit.
$data['edit'] = '<a href="index.php?sec=extensions&sec2=godmode/agentes/planned_downtime.editor&edit_downtime=1&id_downtime='.$downtime['id'].'">'.html_print_image('images/config.png', true, ['title' => __('Update'), 'class' => 'invert_filter']).'</a>';
// Delete.
@ -504,6 +507,8 @@ else {
if (check_acl_restricted_all($config['id_user'], $downtime['id_group'], 'AW')
|| check_acl_restricted_all($config['id_user'], $downtime['id_group'], 'AD')
) {
// Copy.
$data['copy'] = '<a href="index.php?sec=extensions&sec2=godmode/agentes/planned_downtime.editor&downtime_copy=1&id_downtime='.$downtime['id'].'">'.html_print_image('images/copy.png', true, ['title' => __('Copy'), 'class' => 'invert_filter']).'</a>';
// Edit.
$data['edit'] = '<a href="index.php?sec=extensions&sec2=godmode/agentes/planned_downtime.editor&edit_downtime=1&id_downtime='.$downtime['id'].'">'.html_print_image('images/config.png', true, ['title' => __('Update'), 'class' => 'invert_filter']).'</a>';
// Delete.
@ -513,11 +518,13 @@ else {
$data['delete'] = '';
}
} else {
$data['copy'] = '';
$data['edit'] = '';
$data['delete'] = '';
}
} else {
$data['stop'] = '';
$data['copy'] = '';
$data['edit'] = '';
$data['delete'] = '';
}

View File

@ -919,3 +919,73 @@ function delete_planned_downtimes($filter)
return $return;
}
function planned_downtimes_copy($id_downtime)
{
$planned_downtime = db_get_row_filter(
'tplanned_downtime',
['id' => $id_downtime]
);
$planned_agents = db_get_row_filter(
'tplanned_downtime_agents',
['id_downtime' => $id_downtime]
);
$planned_modules = db_get_row_filter(
'tplanned_downtime_modules',
['id_downtime' => $id_downtime]
);
if ($planned_downtime === false) {
return false;
}
// Unset id.
unset($planned_downtime['id']);
// Change copy name.
$planned_downtime['name'] = __('Coy of ').$planned_downtime['name'];
// Insert new downtime
$result = db_process_sql_insert(
'tplanned_downtime',
$planned_downtime
);
if ($result === false) {
return false;
}
if ($planned_agents !== false) {
// Unser id.
unset($planned_agents['id']);
$result = db_process_sql_insert(
'tplanned_downtime_agents',
$planned_agents
);
}
if ($result === false) {
return false;
}
if ((bool) $planned_agents['all_modules'] === false
&& $planned_modules !== false
) {
// Unser id.
unset($planned_modules['id']);
$result = db_process_sql_insert(
'tplanned_downtime_agents',
$planned_agents
);
}
if ($result === false) {
return false;
}
return true;
}