mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-31 01:35:36 +02:00
Ent 6990 copiar informes
This commit is contained in:
parent
9b6ad55910
commit
51844da01b
@ -160,7 +160,7 @@ $pure = get_parameter('pure', 0);
|
|||||||
$schedule_report = get_parameter('schbutton', '');
|
$schedule_report = get_parameter('schbutton', '');
|
||||||
$pagination = (int) get_parameter('pagination', $config['block_size']);
|
$pagination = (int) get_parameter('pagination', $config['block_size']);
|
||||||
|
|
||||||
if ($action == 'edit' && $idReport > 0) {
|
if ($action === 'edit' && $idReport > 0) {
|
||||||
$report_group = db_get_value(
|
$report_group = db_get_value(
|
||||||
'id_group',
|
'id_group',
|
||||||
'treport',
|
'treport',
|
||||||
@ -512,6 +512,7 @@ switch ($action) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'copy_report':
|
||||||
case 'delete_report':
|
case 'delete_report':
|
||||||
case 'list':
|
case 'list':
|
||||||
$buttons = [
|
$buttons = [
|
||||||
@ -657,6 +658,81 @@ switch ($action) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($action === 'copy_report') {
|
||||||
|
$copy = false;
|
||||||
|
switch ($type_access_selected) {
|
||||||
|
case 'group_view':
|
||||||
|
if ($config['id_user'] == $report['id_user']
|
||||||
|
|| is_user_admin($config['id_user'])
|
||||||
|
) {
|
||||||
|
$copy = true;
|
||||||
|
// Owner can delete.
|
||||||
|
} else {
|
||||||
|
$copy = check_acl(
|
||||||
|
$config['id_user'],
|
||||||
|
$report['id_group'],
|
||||||
|
'RM'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'group_edit':
|
||||||
|
if ($config['id_user'] == $report['id_user']
|
||||||
|
|| is_user_admin($config['id_user'])
|
||||||
|
) {
|
||||||
|
$copy = true;
|
||||||
|
// Owner can delete.
|
||||||
|
} else {
|
||||||
|
$copy = check_acl(
|
||||||
|
$config['id_user'],
|
||||||
|
$report['id_group'],
|
||||||
|
'RM'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'user_edit':
|
||||||
|
if ($config['id_user'] == $report['id_user']
|
||||||
|
|| is_user_admin($config['id_user'])
|
||||||
|
) {
|
||||||
|
$copy = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
// Default.
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $copy && !empty($type_access_selected)) {
|
||||||
|
db_pandora_audit(
|
||||||
|
'ACL Violation',
|
||||||
|
'Trying to access report builder copy'
|
||||||
|
);
|
||||||
|
include 'general/noaccess.php';
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = reports_copy_report($idReport);
|
||||||
|
if ($result !== false) {
|
||||||
|
db_pandora_audit(
|
||||||
|
'Report management',
|
||||||
|
'Copy report #'.$idReport
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
db_pandora_audit(
|
||||||
|
'Report management',
|
||||||
|
'Fail try to copy report #'.$idReport
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
ui_print_result_message(
|
||||||
|
$result,
|
||||||
|
__('Successfully copied'),
|
||||||
|
__('Could not be copied')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
$id_group = (int) get_parameter('id_group', 0);
|
$id_group = (int) get_parameter('id_group', 0);
|
||||||
$search = trim(get_parameter('search', ''));
|
$search = trim(get_parameter('search', ''));
|
||||||
|
|
||||||
@ -1092,6 +1168,27 @@ switch ($action) {
|
|||||||
$data[$next] .= '</form>';
|
$data[$next] .= '</form>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$data[$next] .= '<form method="post" style="display: inline"; onsubmit="if (!confirm(\''.__('Are you sure?').'\')) return false;">';
|
||||||
|
$data[$next] .= html_print_input_hidden(
|
||||||
|
'id_report',
|
||||||
|
$report['id_report'],
|
||||||
|
true
|
||||||
|
);
|
||||||
|
$data[$next] .= html_print_input_hidden(
|
||||||
|
'action',
|
||||||
|
'copy_report',
|
||||||
|
true
|
||||||
|
);
|
||||||
|
$data[$next] .= html_print_input_image(
|
||||||
|
'dup',
|
||||||
|
'images/copy.png',
|
||||||
|
1,
|
||||||
|
'',
|
||||||
|
true,
|
||||||
|
['title' => __('Duplicate')]
|
||||||
|
);
|
||||||
|
$data[$next] .= '</form> ';
|
||||||
|
|
||||||
if ($delete) {
|
if ($delete) {
|
||||||
$data[$next] .= '<form method="post" class="inline_line" onsubmit="if (!confirm (\''.__('Are you sure?').'\')) return false">';
|
$data[$next] .= '<form method="post" class="inline_line" onsubmit="if (!confirm (\''.__('Are you sure?').'\')) return false">';
|
||||||
$data[$next] .= html_print_input_image(
|
$data[$next] .= html_print_input_image(
|
||||||
|
@ -275,13 +275,12 @@ function reports_get_content($id_report_content, $filter=false, $fields=false)
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all the contents of a report.
|
* Creates the contents of a report.
|
||||||
*
|
*
|
||||||
* @param int Report id to get contents.
|
* @param int Report id to get contents.
|
||||||
* @param array Extra filters for the contents.
|
* @param array values to be created.
|
||||||
* @param array Fields to be fetched. All fields by default
|
|
||||||
*
|
*
|
||||||
* @return array All the contents of a report.
|
* @return boolean true id succed, false otherwise.
|
||||||
*/
|
*/
|
||||||
function reports_create_content($id_report, $values)
|
function reports_create_content($id_report, $values)
|
||||||
{
|
{
|
||||||
@ -305,7 +304,11 @@ function reports_create_content($id_report, $values)
|
|||||||
|
|
||||||
switch ($config['dbtype']) {
|
switch ($config['dbtype']) {
|
||||||
case 'mysql':
|
case 'mysql':
|
||||||
unset($values['`order`']);
|
if (isset($values['`order`'])) {
|
||||||
|
unset($values['`order`']);
|
||||||
|
} else {
|
||||||
|
unset($values['order']);
|
||||||
|
}
|
||||||
|
|
||||||
$order = (int) db_get_value('MAX(`order`)', 'treport_content', 'id_report', $id_report);
|
$order = (int) db_get_value('MAX(`order`)', 'treport_content', 'id_report', $id_report);
|
||||||
$values['`order`'] = ($order + 1);
|
$values['`order`'] = ($order + 1);
|
||||||
@ -900,3 +903,100 @@ function reports_get_report_types($template=false, $not_editor=false)
|
|||||||
|
|
||||||
return $types;
|
return $types;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function reports_copy_report($id_report)
|
||||||
|
{
|
||||||
|
$report = reports_get_report($id_report);
|
||||||
|
|
||||||
|
// Unset original report id_report.
|
||||||
|
unset($report['id_report']);
|
||||||
|
|
||||||
|
$original_name = $report['name'];
|
||||||
|
$original_group = $report['id_group'];
|
||||||
|
|
||||||
|
$copy_name = io_safe_input(sprintf(__('copy of %s'), io_safe_output($original_name)));
|
||||||
|
|
||||||
|
$copy_report = reports_create_report($copy_name, $original_group, $report);
|
||||||
|
|
||||||
|
if ($copy_report !== false) {
|
||||||
|
$original_contents = reports_get_contents($id_report);
|
||||||
|
if (empty($original_contents) === false) {
|
||||||
|
foreach ($original_contents as $original_content) {
|
||||||
|
$original_content['id_report'] = $copy_report;
|
||||||
|
$original_id_rc = $original_content['id_rc'];
|
||||||
|
unset($original_content['id_rc']);
|
||||||
|
$result_content = db_process_sql_insert('treport_content', $original_content);
|
||||||
|
|
||||||
|
if ($result_content === false) {
|
||||||
|
$result = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (io_safe_output($original_content['type'])) {
|
||||||
|
case 'SLA':
|
||||||
|
case 'SLA_monthly':
|
||||||
|
case 'SLA_weekly':
|
||||||
|
case 'SLA_hourly':
|
||||||
|
case 'availability_graph':
|
||||||
|
|
||||||
|
$slas = db_get_all_rows_field_filter('treport_content_sla_combined', 'id_report_content', $original_id_rc);
|
||||||
|
if ($slas === false) {
|
||||||
|
$slas = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($slas as $sla) {
|
||||||
|
unset($sla['id']);
|
||||||
|
|
||||||
|
// Set id report to copy id.
|
||||||
|
$sla['id_report_content'] = $result_content;
|
||||||
|
$sla_copy = db_process_sql_insert('treport_content_sla_combined', $sla);
|
||||||
|
|
||||||
|
if ($sla_copy === false) {
|
||||||
|
reports_delete_content($result_content);
|
||||||
|
$result = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'general':
|
||||||
|
case 'top_n':
|
||||||
|
case 'availability':
|
||||||
|
case 'exception':
|
||||||
|
|
||||||
|
$items = db_get_all_rows_field_filter('treport_content_item', 'id_report_content', $original_id_rc);
|
||||||
|
if ($items === false) {
|
||||||
|
$items = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($items as $item) {
|
||||||
|
unset($item['id']);
|
||||||
|
|
||||||
|
// Set id report to copy id.
|
||||||
|
$item['id_report_content'] = $result_content;
|
||||||
|
$item_copy = db_process_sql_insert('treport_content_item', $item);
|
||||||
|
|
||||||
|
if ($item_copy === false) {
|
||||||
|
reports_delete_content($result_content);
|
||||||
|
$result = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
// Empty default.
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($result === false) {
|
||||||
|
reports_delete_report($copy_report);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user