$id_layout)); $result = db_process_sql_delete('tlayout', array ('id' => $id_layout)); if ($result) { db_pandora_audit( "Visual console builder", "Delete visual console #$id_layout"); ui_print_success_message(__('Successfully deleted')); db_clean_cache(); } else { db_pandora_audit( "Visual console builder", "Fail try to delete visual console #$id_layout"); ui_print_error_message( __('Not deleted. Error deleting data')); } $id_layout = 0; } if ($copy_layout) { // Number of inserts $ninsert = (int) 0; // Return from DB the source layout $layout_src = db_get_all_rows_filter("tlayout", array("id" => $id_layout)); // Name of dst $name_dst = get_parameter ("name_dst", $layout_src[0]['name'] . " copy"); // Create the new Console $idGroup = $layout_src[0]['id_group']; $background = $layout_src[0]['background']; $height = $layout_src[0]['height']; $width = $layout_src[0]['width']; $visualConsoleName = $name_dst; $values = array( 'name' => $visualConsoleName, 'id_group' => $idGroup, 'background' => $background, 'height' => $height, 'width' => $width); $result = db_process_sql_insert('tlayout', $values); $idNewVisualConsole = $result; if ($result) { $ninsert = 1; // Return from DB the items of the source layout $data_layout_src = db_get_all_rows_filter( "tlayout_data", array("id_layout" => $id_layout)); if (!empty($data_layout_src)) { //By default the id parent 0 is always 0. $id_relations = array(0 => 0); for ($a = 0; $a < count($data_layout_src); $a++) { // Changing the source id by the new visual console id $data_layout_src[$a]['id_layout'] = $idNewVisualConsole; $old_id = $data_layout_src[$a]['id']; // Unsetting the source's id unset($data_layout_src[$a]['id']); // Configure the cloned Console $result = db_process_sql_insert('tlayout_data', $data_layout_src[$a]); $id_relations[$old_id] = 0; if ($result !== false) { $id_relations[$old_id] = $result; } if ($result) $ninsert++; }// for each item of console $inserts = count($data_layout_src) + 1; // If the number of inserts is correct, the copy is completed if ($ninsert == $inserts) { //Update the ids of parents $items = db_get_all_rows_filter("tlayout_data", array("id_layout" => $idNewVisualConsole)); foreach ($items as $item) { $new_parent = $id_relations[$item['parent_item']]; db_process_sql_update('tlayout_data', array('parent_item' => $new_parent), array('id' => $item['id'])); } ui_print_success_message(__('Successfully copied')); db_clean_cache(); } else { ui_print_error_message(__('Not copied. Error copying data')); } } else { // If the array is empty the copy is completed ui_print_success_message(__('Successfully copied')); db_clean_cache(); } } else { ui_print_error_message(__('Not copied. Error copying data')); } } } if ($ag_group > 0) { $ag_groups = array(); $ag_groups = (array)$ag_group; if ($recursion) { $ag_groups = groups_get_id_recursive($ag_group, true); } } echo "