false]); return; } if (db_process_sql_delete( 'tconfig_os', ['id_os' => $id_os] ) === false ) { echo json_encode(['deleted' => false]); } else { echo json_encode(['deleted' => true]); } } if ($method === 'deleteOSVersion') { global $config; $id_os_version = get_parameter('id_os_version', null); if (empty($id_os_version) === true || $id_os_version < 1) { echo json_encode(['deleted' => false]); } if (db_process_sql_delete( 'tconfig_os_version', ['id_os_version' => $id_os_version] ) === false ) { echo json_encode(['deleted' => false]); } else { echo json_encode(['deleted' => true]); } } if ($method === 'drawOSTable') { // Datatables offset, limit and order. $filter = get_parameter('filter', []); $start = get_parameter('start', 0); $length = get_parameter('length', $config['block_size']); $orderBy = get_datatable_order(true); $sort_field = $orderBy['field']; $order = $orderBy['direction']; $pagination = ''; $pagination = sprintf( ' LIMIT %d OFFSET %d ', $length, $start ); try { ob_start(); $fields = ['*']; $sql_filters = []; if (isset($filter['free_search']) === true && empty($filter['free_search']) === false ) { $sql_filters[] = sprintf( ' AND (`name` like "%%%s%%" OR `description` like "%%%s%%") ', $filter['free_search'], $filter['free_search'] ); } if (isset($order) === true) { $dir = 'asc'; if ($order == 'desc') { $dir = 'desc'; }; if (in_array( $sort_field, [ 'id_os', 'name', 'description', ] ) === true ) { $order_by = sprintf( 'ORDER BY `%s` %s', $sort_field, $dir ); } } // Retrieve data. $sql = sprintf( 'SELECT %s FROM tconfig_os WHERE 1=1 %s %s %s', join(',', $fields), join(' ', $sql_filters), $order_by, $pagination ); $count_sql = sprintf( 'SELECT id_os FROM tconfig_os WHERE 1=1 %s', join(' ', $sql_filters) ); $return = db_get_all_rows_sql($sql); if ($return === false) { $data = []; } else { $data = $return; } $data = array_map( function ($item) { $item['icon_img'] = ui_print_os_icon($item['id_os'], false, true); if (is_management_allowed() === true) { if (is_metaconsole() === true) { $osNameUrl = 'index.php?sec=advanced&sec2=advanced/component_management&tab=os_manage&action=edit&tab2=list&id_os='.$item['id_os']; } else { $osNameUrl = 'index.php?sec=gsetup&sec2=godmode/setup/os&action=edit&tab=manage_os&id_os='.$item['id_os']; } $item['name'] = html_print_anchor( [ 'href' => $osNameUrl, 'content' => $item['name'], ], true ); } else { $item['name'] = $item['name']; } $item['description'] = ui_print_truncate_text( $item['description'], 'description', true, true ); if (is_management_allowed() === true) { $item['enable_delete'] = false; if ($item['id_os'] > 16) { $item['enable_delete'] = true; } } return $item; }, $data ); // Retrieve counter. $count = db_get_value('count(*)', '('.$count_sql.') t'); // Datatables format: RecordsTotal && recordsfiltered. echo json_encode( [ 'data' => $data, 'recordsTotal' => $count, 'recordsFiltered' => $count, ] ); // Capture output. $response = ob_get_clean(); } catch (Exception $e) { echo json_encode(['error' => $e->getMessage()]); exit; } // If not valid, show error with issue. json_decode($response); if (json_last_error() == JSON_ERROR_NONE) { // If valid dump. echo $response; } else { echo json_encode( ['error' => $response] ); } exit; } if ($method === 'drawOSVersionTable') { // Datatables offset, limit and order. $filter = get_parameter('filter', []); $start = get_parameter('start', 0); $length = get_parameter('length', $config['block_size']); $orderBy = get_datatable_order(true); $sort_field = $orderBy['field']; $order = $orderBy['direction']; $pagination = ''; $pagination = sprintf( ' LIMIT %d OFFSET %d ', $length, $start ); try { ob_start(); $fields = ['*']; $sql_filters = []; if (isset($filter['free_search']) === true && empty($filter['free_search']) === false ) { $sql_filters[] = sprintf( ' AND (`product` like "%%%s%%" OR `version` like "%%%s%%") ', $filter['free_search'], $filter['free_search'] ); } if (isset($order) === true) { $dir = 'asc'; if ($order == 'desc') { $dir = 'desc'; }; if (in_array( $sort_field, [ 'product', 'version', 'end_of_support', ] ) === true ) { $order_by = sprintf( 'ORDER BY `%s` %s', $sort_field, $dir ); } } // Retrieve data. $sql = sprintf( 'SELECT %s FROM tconfig_os_version WHERE 1=1 %s %s %s', join(',', $fields), join(' ', $sql_filters), $order_by, $pagination ); $count_sql = sprintf( 'SELECT id_os_version FROM tconfig_os_version WHERE 1=1 %s', join(' ', $sql_filters) ); $return = db_get_all_rows_sql($sql); if ($return === false) { $data = []; } else { // Format end of life date. $return = array_map( function ($item) { $date_string = date_w_fixed_tz($item['end_of_support']); $timestamp = strtotime($date_string); $date_without_time = date('F j, Y', $timestamp); $item['end_of_support'] = $date_without_time; return $item; }, $return ); $data = $return; } // Retrieve counter. $count = db_get_value('count(*)', '('.$count_sql.') t'); // Datatables format: RecordsTotal && recordsfiltered. echo json_encode( [ 'data' => $data, 'recordsTotal' => $count, 'recordsFiltered' => $count, ] ); // Capture output. $response = ob_get_clean(); } catch (Exception $e) { echo json_encode(['error' => $e->getMessage()]); exit; } // If not valid, show error with issue. json_decode($response); if (json_last_error() == JSON_ERROR_NONE) { // If valid dump. echo $response; } else { echo json_encode( ['error' => $response] ); } exit; }