ID;
// Check if the user is registered as military
$militar = get_user_meta($user_id, 'militar', true);
if ($militar) {
$url = home_url('/apoio-militares/');
return "Solicite apoio de rancho e transporte clicando aqui";
}
return '';
}
add_shortcode('show_page_apoio', 'showPageApoio');
function frontendApoio()
{
if (!is_user_logged_in()) {
return '
É necessário estar logado para acessar esta página.
';
}
global $wpdb;
$current_user = wp_get_current_user();
$user_id = $current_user->ID;
$year = date('Y');
// Check if the user is registered as military
$militar = get_user_meta($user_id, 'militar', true);
if ($militar == 'Não') {
return '
Apenas militares podem solicitar o tipo de apoio fornecido nessa página.
';
$referer = wp_get_referer();
$safe_referer = wp_validate_redirect($referer, home_url());
wp_safe_redirect(home_url());
exit;
}
// Verificar se o militar já solicitou apoio anteriormente
$apoio = $wpdb->get_row($wpdb->prepare("
SELECT * FROM {$wpdb->prefix}sige_apoio WHERE user_id = %d AND ano = %d", $user_id, $year));
if ($apoio == null) {
$apoio = (object) array(
"id" => null,
"almoco_1" => 0,
"almoco_2" => 0,
"almoco_3" => 0,
"rodoviario" => "",
"aereo" => "",
);
}
// Process form submission before any HTML output
if (isset($_POST['submit'])) {
$almoco_1 = isset($_POST['almoco_dia_1']) ? 1 : 0;
$almoco_2 = isset($_POST['almoco_dia_2']) ? 1 : 0;
$almoco_3 = isset($_POST['almoco_dia_3']) ? 1 : 0;
$rodoviario = sanitize_text_field($_POST['apoio_rodoviario']);
$aereo = sanitize_text_field($_POST['apoio_aereo']);
// Store options in database
if ($apoio->id != null) {
$wpdb->update(
"{$wpdb->prefix}sige_apoio",
[
"user_id" => $user_id,
"ano" => $year,
"almoco_1" => $almoco_1,
"almoco_2" => $almoco_2,
"almoco_3" => $almoco_3,
"rodoviario" => $rodoviario,
"aereo" => $aereo
],
["id" => $apoio->id]
);
} else {
$wpdb->insert(
"{$wpdb->prefix}sige_apoio",
[
"user_id" => $user_id,
"ano" => $year,
"almoco_1" => $almoco_1,
"almoco_2" => $almoco_2,
"almoco_3" => $almoco_3,
"rodoviario" => $rodoviario,
"aereo" => $aereo
]
);
}
wp_safe_redirect(esc_url($_SERVER['REQUEST_URI']));
exit;
}
echo '';
}
add_shortcode('apoio', 'frontendApoio');
function getDataApoioRancho(): void
{
global $wpdb;
if (!is_user_logged_in()) {
// Add the style to the head section of the page
echo 'You need to be logged in to view this page.
';
}
$user = wp_get_current_user();
$roles = $user->roles;
$has_access = array('comissao_apoio', 'administrator');
$user_allowed_roles = array_intersect($roles, $has_access);
if (empty($user_allowed_roles)) {
// Add the style for the restricted message
echo '
Sorry, you don\'t have permission to view this content.
';
} else {
$current_year = date('Y');
foreach (range(1, 3) as $day) {
$almoco = <<prefix}usermeta
WHERE meta_key = 'circulo_hierarquico' and user_id in
(SELECT user_id FROM {$wpdb->prefix}sige_apoio WHERE almoco_%d = 1 and ano = %d )
GROUP by meta_value ORDER by meta_value
SQL;
$result = $wpdb->get_results($wpdb->prepare($almoco, $day, $current_year), ARRAY_A);
echo 'Solicitações de almoço para o ' . $day . 'º Dia
';
foreach ($result as $data) {
echo $data['meta_value'] . ': ' . $data['num'] . '
';
}
echo '
';
}
}
}
add_shortcode('DataApoio', 'getDataApoioRancho');