roles) || count ( array_intersect( $calculatg_settings['excel_export_allowed_roles'], $wp_current_user->roles ) ) === 0 ) {
wp_send_json(
array(
'redirect' => true,
'redirect_url' => $calculatg_settings['restricted_user_redirect_url']
)
);
}
if ( isset($_POST['check']) ) {
wp_send_json(
array(
'redirect' => false,
'redirect_url' => ''
)
);
}
$type = sanitize_text_field( $_POST['type'] );
switch($type) {
case '1':
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load( CALCULATG_PLUGIN_DIR . '/files/F1.xlsx' );
$sheet = $spreadsheet->getActiveSheet();
$post_data = array_map('sanitize_text_field', $_POST);
$post_data = array_map('stripslashes', $post_data);
$sheet->setCellValue('B8', $post_data['application_str']);
$sheet->setCellValue('B10', $post_data['resistance_str']);
$sheet->setCellValue('B12', $post_data['aggregate_origin_str']);
$sheet->setCellValue('B14', $post_data['gravel_size_str']);
$sheet->setCellValue('E14', $post_data['sand_moisture_str']);
$sheet->setCellValue('B16', $post_data['volume_liters_str']);
$sheet->setCellValue('E20', $post_data['tab_str']);
if ( $post_data['active_tab'] == '0' ) {
$sheet->setCellValue('E16', $post_data['tab1_number_of_stirrers']);
$sheet->setCellValue('B20', $post_data['tab1_approximate_volume']);
$sheet->setCellValue('B22', $post_data['tab1_agua']);
$sheet->setCellValue('E22', $post_data['tab1_agua_botes']);
$sheet->setCellValue('B24', $post_data['tab1_cemento']);
$sheet->setCellValue('E24', $post_data['tab1_cemento_sacos']);
$sheet->setCellValue('B26', $post_data['tab1_arena']);
$sheet->setCellValue('E26', $post_data['tab1_arena_botes']);
$sheet->setCellValue('B28', $post_data['tab1_grava']);
$sheet->setCellValue('E28', $post_data['tab1_grava_botes']);
$sheet->setCellValue('F22', 'litros');
$sheet->setCellValue('F24', 'litros');
$sheet->setCellValue('F26', 'litros');
$sheet->setCellValue('F28', 'litros');
}
else if ( $post_data['active_tab'] == '1' ) {
$sheet->setCellValue('B20', $post_data['tab2_manufacturer_volume']);
$sheet->setCellValue('B22', $post_data['tab2_agua']);
$sheet->setCellValue('E22', $post_data['tab2_agua_botes']);
$sheet->setCellValue('B24', $post_data['tab2_cemento']);
$sheet->setCellValue('E24', $post_data['tab2_cemento_sacos']);
$sheet->setCellValue('B26', $post_data['tab2_arena']);
$sheet->setCellValue('E26', $post_data['tab2_arena_botes']);
$sheet->setCellValue('B28', $post_data['tab2_grava']);
$sheet->setCellValue('E28', $post_data['tab2_grava_botes']);
}
else if ( $post_data['active_tab'] == '2' ) {
$sheet->setCellValue('B20', $post_data['tab3_approximate_volume']);
$sheet->setCellValue('B22', $post_data['tab3_agua']);
$sheet->setCellValue('E22', $post_data['tab3_agua_botes']);
$sheet->setCellValue('B24', $post_data['tab3_cemento']);
$sheet->setCellValue('E24', $post_data['tab3_cemento_sacos']);
$sheet->setCellValue('B26', $post_data['tab3_arena']);
$sheet->setCellValue('E26', $post_data['tab3_arena_botes']);
$sheet->setCellValue('B28', $post_data['tab3_grava']);
$sheet->setCellValue('E28', $post_data['tab3_grava_botes']);
}
else if ( $post_data['active_tab'] == '3' ) {
$sheet->setCellValue('B20', $post_data['tab4_manufacturer_volume']);
$sheet->setCellValue('B22', $post_data['tab4_agua_botes']);
$sheet->setCellValue('E22', $post_data['tab3_agua_botes_2']);
$sheet->setCellValue('B24', $post_data['tab4_cemento_sacos']);
$sheet->setCellValue('E24', $post_data['tab4_cemento_sacos_2']);
$sheet->setCellValue('B26', $post_data['tab4_arena_botes']);
$sheet->setCellValue('E26', $post_data['tab4_arena_botes_2']);
$sheet->setCellValue('B28', $post_data['tab4_grava_botes']);
$sheet->setCellValue('E28', $post_data['tab4_grava_botes_2']);
}
$writer = new Xlsx($spreadsheet);
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment; filename="Dosification Concreto.xlsx"');
$writer->save("php://output");
//$writer->save(CALCULATG_PLUGIN_DIR . '/temp/Dosification Concreto.xlsx');
break;
}
exit;
}
public function shortcode_handler( $atts = array() ) {
$atts = shortcode_atts( array(
'type' => '1',
), $atts, CALCULATG_TEXT_DOMAIN );
extract( $atts );
wp_enqueue_style('calculatg-css', plugin_dir_url(__FILE__) . '/css/calculatg.css', '', CALCULATG_VERSION);
wp_enqueue_style('jquery-ui-tabs', '//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css', '', CALCULATG_VERSION);
wp_enqueue_script("jquery-ui-tabs");
$calculatg_settings = get_option('calculatg_settings', array());
$html = '';
ob_start();
switch( $type ) {
case '1':
default:
wp_enqueue_script('calculatg-js', plugin_dir_url(__FILE__) . '/js/dosification-concreto.js', ['jquery'], CALCULATG_VERSION, true);
wp_localize_script( 'calculatg-js', 'calculatg_obj',
array(
'ajaxurl' => admin_url( 'admin-ajax.php' )
)
);
include_once 'files/dosification-concreto.html';
break;
}
$html .= ob_get_clean();
$html .= '
';
return $html;
}
}
$calculatg = new CalculaTG;