コード例 #1
0
 static function create_foruns()
 {
     //rodar uma vez só
     if (get_option('foruns_inicializados') !== false) {
         return;
     }
     update_option('foruns_inicializados', true);
     $estados = get_all_states();
     $setoriais = get_setoriais();
     foreach ($estados as $uf => $estado) {
         wp_insert_term($estado, 'estado', array('slug' => $uf));
     }
     foreach ($setoriais as $slug => $setorial) {
         wp_insert_term($setorial, 'setorial', array('slug' => $slug));
     }
     foreach ($estados as $uf => $estado) {
         foreach ($setoriais as $slug => $setorial) {
             $post = array('post_title' => $uf . ' - ' . $setorial, 'post_name' => $uf . '-' . $slug, 'post_type' => 'foruns', 'post_status' => 'publish');
             $new_post = wp_insert_post($post);
             wp_set_object_terms($new_post, $uf, 'estado');
             wp_set_object_terms($new_post, $slug, 'setorial');
         }
     }
 }
function resumo_setorial_estado_page_callback_function()
{
    // setorial, uf, qtd_candidatos, qtd_eleitores, qtd_votantes)
    if (!current_user_can('curate')) {
        return false;
    }
    $data[] = ['setorial', 'uf', 'qtd_candidatos', 'qtd_eleitores', 'qtd_votantes'];
    $uf_selected = $_GET['uf'];
    $setorial_selected = $_GET['setorial'];
    $confirm = $_GET['confirm'];
    $states = get_all_states();
    $setoriais = get_setoriais();
    if (!in_array($uf_selected, array_keys($states))) {
        if ($uf_selected != 'todos') {
            $uf_selected = '';
        }
    } else {
        $data[] = 'uf';
    }
    if (!in_array($setorial_selected, array_keys($setoriais))) {
        if ($setorial_selected != 'todos') {
            $setorial_selected = '';
        }
    } else {
        $data[] = 'setorial';
    }
    ?>
    <div class="wrap span-20">

    <h2>Resumo das setoriais e estados</h2>
    
    <h4>Selecione a UF:</h4>
    <select class="select-state-v" id="filtrar_uf">
      <option></option>
      <?php 
    foreach ($states as $uf_item => $state_item) {
        ?>
      <option value="<?php 
        echo $uf_item;
        ?>
" <?php 
        if ($uf_item == $uf_selected) {
            echo "selected";
        }
        ?>
><?php 
        echo $state_item;
        ?>
</option>
<?php 
    }
    ?>
      <option value="todos" <?php 
    if ($uf_selected == 'todos') {
        echo "selected";
    }
    ?>
>TODOS</option>
    </select>
      
    <h4>Selecione a Setorial:</h4>
    <select class="select-setorial-v" id="filtrar_setorial">
      <option></option>
      <?php 
    foreach ($setoriais as $slug => $setorial_item) {
        ?>
      <option value="<?php 
        echo $slug;
        ?>
" <?php 
        if ($slug == $setorial_selected) {
            echo "selected";
        }
        ?>
><?php 
        echo $setorial_item;
        ?>
</option>
      <?php 
    }
    ?>
      <option value="todos" <?php 
    if ($setorial_selected == 'todos') {
        echo "selected";
    }
    ?>
>TODOS</option>      
    </select>
      <br/>
      <input type="button" value="buscar" id="resumo_setorial_estado" class="filtrar_relatorio">
      <br/><br/>
      
<?php 
    if ($uf_selected != '' || $setorial_selected != '') {
        if ($uf_selected == 'todos') {
            $uf_selected = '';
        }
        if ($setorial_selected == 'todos') {
            $setorial_selected = '';
        }
        $nome_relatorio = "";
        if ($uf_selected && $setorial_selected) {
            $nome_relatorio = "resumo-{$uf_selected}-{$setorial_selected}";
        } else {
            if ($uf_selected && !$setorial_selected) {
                $nome_relatorio = "resumo-resumo-{$uf_selected}";
            } else {
                if (!$uf_selected && $setorial_selected) {
                    $nome_relatorio = "resumo-{$setorial_selected}";
                } else {
                    $nome_relatorio = "resumo-nacional";
                }
            }
        }
        // testa arquivo
        $filename = $nome_relatorio . ".csv";
        $file_web = get_template_directory_uri() . '/relatorios/arquivos/' . $filename;
        $file_path = get_template_directory() . '/relatorios/arquivos/' . $filename;
        clearstatcache();
        if (file_exists($file_path)) {
            echo "<strong>Já existe um relatório disponível para essa consulta:</strong> <br/>";
            echo "<a href='{$file_web}'>{$filename}</a>";
            if (!$confirm) {
                echo "<br/><br/>";
                echo "<h3><a href='" . basename($_SERVER['PHP_SELF']) . "?" . $_SERVER['QUERY_STRING'] . '&confirm=1' . "'>desejo gerar uma nova consulta</a></h3>";
            }
        }
        if ($confirm == 1 || !file_exists($file_path)) {
            if ($uf_selected == '' && $setorial_selected == '') {
                /* listagem TODOS */
                foreach ($states as $uf => $state_item) {
                    foreach ($setoriais as $setorial => $setorial_item) {
                        $qtd_candidatos = get_count_candidates($uf, $setorial, true);
                        $qtd_eleitores = get_count_users_setorial_uf($uf, $setorial);
                        $qtd_votantes = get_votos_estado_setorial($uf, $setorial);
                        $data[] = [$setoriais[$setorial], $states[$uf], $qtd_candidatos, $qtd_eleitores, $qtd_votantes];
                    }
                }
            } else {
                if ($uf_selected != '' && $setorial_selected == '') {
                    // relatorio por só por uf
                    foreach ($setoriais as $setorial => $setorial_item) {
                        $qtd_candidatos = get_count_candidates($uf, $setorial, true);
                        $qtd_eleitores = get_count_users_setorial_uf($uf, $setorial);
                        $qtd_votantes = get_votos_estado_setorial($uf, $setorial);
                        $data[] = [$setorial_item, $states[$uf_selected], $qtd_candidatos, $qtd_eleitores, $qtd_votantes];
                    }
                } else {
                    if ($uf_selected == '' && $setorial_selected != '') {
                        // relatorio só por setorial
                        foreach ($states as $uf => $state_item) {
                            $qtd_candidatos = get_count_candidates($uf, $setorial, true);
                            $qtd_eleitores = get_count_users_setorial_uf($uf, $setorial);
                            $qtd_votantes = get_votos_estado_setorial($uf, $setorial);
                            $data[] = [$setoriais[$setorial_selected], $state_item, $qtd_candidatos, $qtd_eleitores, $qtd_votantes];
                        }
                    } else {
                        if ($uf_selected != '' && $setorial_selected != '') {
                            // relatorio por uf e setorial
                            $qtd_candidatos = get_count_candidates($uf, $setorial, true);
                            $qtd_eleitores = get_count_users_setorial_uf($uf, $setorial);
                            $qtd_votantes = get_votos_estado_setorial($uf, $setorial);
                            $data[] = [$setoriais[$setorial_selected], $states[$uf_selected], $qtd_candidatos, $qtd_eleitores, $qtd_votantes];
                        }
                    }
                }
            }
            ?>
     
          <iframe id="iframeExportar" frameborder="0" src="<?php 
            echo get_template_directory_uri();
            ?>
/baixar-csv.php" data_filename='<?php 
            echo $nome_relatorio;
            ?>
' data_csv='<?php 
            echo json_encode($data);
            ?>
' data_output_path='arquivo'>
      </div>    
<?php 
        }
    }
}
コード例 #3
0
if (isset($employeedetails)) {
    echo $employeedetails['lastname'];
}
?>
"/></td>
                    <td>&nbsp;</td>
                    <td valign="top">Location: </td>
                    <td valign="top"><select name="stateorprovince" id="stateorprovince" class="textfield">
                      <?php 
if (isset($employeedetails)) {
    $selected = trim($employeedetails['stateorprovince']);
} else {
    $selected = '';
}
$statearray = array();
$originalarray = get_all_states();
foreach ($originalarray as $state) {
    array_push($statearray, array('state' => $state));
}
echo get_select_options($statearray, 'state', 'state', $selected);
?>
                                        </select></td>
                  </tr>
                  <tr>
                    <td nowrap="nowrap">Gender:</td>
                    <td valign="top"><table border="0" cellpadding="4" cellspacing="0">
                      <tr>
                        <td nowrap="nowrap"><input name="gender_radio" id="female" type="radio" value="Female" onclick="passFormValue('female', 'gender', 'radio');" <?php 
if (isset($employeedetails) && $employeedetails['gender'] == 'Female') {
    echo " checked";
}
コード例 #4
0
function get_count_candidates_states()
{
    global $wpdb;
    $states = get_all_states();
    $count = array();
    foreach ($states as $key => $state) {
        // $count[$key] = $wpdb->get_var( $wpdb->prepare("SELECT count(u.umeta_id) FROM {$wpdb->usermeta} AS u INNER JOIN {$wpdb->usermeta} AS us ON u.user_id = us.user_id where u.meta_key = 'uf' AND u.meta_value = %s AND us.meta_key = 'e_candidato'", $key ) );
        $count[$key] = $wpdb->get_var($wpdb->prepare("SELECT COUNT(u.umeta_id)" . "FROM {$wpdb->posts} as p " . "INNER JOIN {$wpdb->postmeta} as m ON p.ID = m.post_id " . "INNER JOIN {$wpdb->usermeta} as u ON p.post_author = u.user_id " . "WHERE p.post_type = 'projetos' " . "AND m.meta_key = 'subscription-valid' " . "AND u.meta_key = 'uf' AND u.meta_value = %s", $key));
    }
    return $count;
}
コード例 #5
0
function get_state_name_by_uf($uf)
{
    $states = get_all_states();
    if (isset($states[$uf])) {
        return $states[$uf];
    }
}