Merge branch 'ent-8276-copiado-paradas-planificadas' into 'develop'

Planned downtime copy.

See merge request artica/pandorafms!4662
This commit is contained in:
Daniel Rodriguez 2022-02-02 09:36:18 +00:00
commit 2ed2fdfd6c
3 changed files with 160 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,16 @@ if ($create_downtime || $update_downtime) {
}
}
if ($downtime_copy) {
$result = planned_downtimes_copy($id_downtime);
if ($result['id_downtime'] !== false) {
$id_downtime = $result['id_downtime'];
ui_print_success_message($result['success']);
} else {
ui_print_error_message(__($result['error']));
}
}
// Have any data to show ?
if ($id_downtime > 0) {
// Columns of the table tplanned_downtime.
@ -628,20 +639,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 +672,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 +705,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 +1008,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,88 @@ 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_all_rows_filter(
'tplanned_downtime_agents',
['id_downtime' => $id_downtime]
);
$planned_modules = db_get_all_rows_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'] = __('Copy of ').$planned_downtime['name'];
// Insert new downtime
$result['id_downtime'] = db_process_sql_insert(
'tplanned_downtime',
$planned_downtime
);
if ($result === false) {
$result['error'] = __('Could not be copied');
return $result;
} else {
$result['success'] = __('Successfully copied');
}
if ($planned_agents !== false) {
foreach ($planned_agents as $planned_agent) {
// Unset id.
unset($planned_agent['id']);
// Set id_planned downtime
$planned_agent['id_downtime'] = $result['id_downtime'];
$result['id_agents'][] = db_process_sql_insert(
'tplanned_downtime_agents',
$planned_agent
);
if ($result === false) {
$return['error'] = __('Error adding agents to copied downtime');
break;
}
}
}
if ($result === false) {
return false;
}
if ((bool) $planned_agents['all_modules'] === false
&& $planned_modules !== false
) {
foreach ($planned_modules as $planned_module) {
// Unset id.
unset($planned_module['id']);
// Set id_planned downtime
$planned_module['id_downtime'] = $result['id_downtime'];
$result['id_modules'][] = db_process_sql_insert(
'tplanned_downtime_moduless',
$planned_module
);
if ($result === false) {
$return['error'] = __('Error adding module to copied downtime');
break;
}
}
}
return $result;
}