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

View File

@ -405,6 +405,7 @@ else {
if ($write_permisson || $manage_permisson) { if ($write_permisson || $manage_permisson) {
$table->head['stop'] = __('Stop downtime'); $table->head['stop'] = __('Stop downtime');
$table->head['copy'] = __('Copy');
$table->head['edit'] = __('Edit'); $table->head['edit'] = __('Edit');
$table->head['delete'] = __('Delete'); $table->head['delete'] = __('Delete');
} }
@ -492,6 +493,8 @@ else {
if (check_acl_restricted_all($config['id_user'], $downtime['id_group'], 'AW') if (check_acl_restricted_all($config['id_user'], $downtime['id_group'], 'AW')
|| check_acl_restricted_all($config['id_user'], $downtime['id_group'], 'AD') || 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. // 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>'; $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. // Delete.
@ -504,6 +507,8 @@ else {
if (check_acl_restricted_all($config['id_user'], $downtime['id_group'], 'AW') if (check_acl_restricted_all($config['id_user'], $downtime['id_group'], 'AW')
|| check_acl_restricted_all($config['id_user'], $downtime['id_group'], 'AD') || 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. // 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>'; $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. // Delete.
@ -513,11 +518,13 @@ else {
$data['delete'] = ''; $data['delete'] = '';
} }
} else { } else {
$data['copy'] = '';
$data['edit'] = ''; $data['edit'] = '';
$data['delete'] = ''; $data['delete'] = '';
} }
} else { } else {
$data['stop'] = ''; $data['stop'] = '';
$data['copy'] = '';
$data['edit'] = ''; $data['edit'] = '';
$data['delete'] = ''; $data['delete'] = '';
} }

View File

@ -919,3 +919,73 @@ function delete_planned_downtimes($filter)
return $return; 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;
}