function regerar_rank()
{
    $bd = new bd();
    //        $var  = "ESPVIDA;FECTOT;MORT1;MORT5;RAZDEP;SOBRE40;SOBRE60;T_ENV;E_ANOSESTUDO;T_ANALF11A14;T_ANALF15A17;T_ANALF15M;T_ANALF18A24;T_ANALF18M;T_ANALF25A29;T_ANALF25M;T_ATRASO_0_BASICO;T_ATRASO_0_FUND;T_ATRASO_0_MED;T_ATRASO_1_BASICO;T_ATRASO_1_FUND;T_ATRASO_1_MED;T_ATRASO_2_BASICO;T_ATRASO_2_FUND;T_ATRASO_2_MED;T_FBBAS;T_FBFUND;T_FBMED;T_FBPRE;T_FBSUPER;T_FLBAS;T_FLFUND;T_FLMED;T_FLPRE;T_FLSUPER;T_FREQ0A3;T_FREQ11A14;T_FREQ15A17;T_FREQ18A24;T_FREQ25A29;T_FREQ4A5;T_FREQ4A6;T_FREQ5A6;T_FREQ6;T_FREQ6A14;T_FREQ6A17;T_FREQFUND1517;T_FREQFUND1824;T_FREQFUND45;T_FREQMED1824;T_FREQMED614;T_FREQSUPER1517;T_FUND11A13;T_FUND12A14;T_FUND15A17;T_FUND16A18;T_FUND18A24;T_FUND18M;T_FUND25M;T_MED18A20;T_MED18A24;T_MED18M;T_MED19A21;T_MED25M;T_SUPER25M;CORTE1;CORTE2;CORTE3;CORTE4;CORTE9;GINI;PIND;PINDCRI;PMPOB;PMPOBCRI;PPOB;PPOBCRI;PREN10RICOS;PREN20;PREN20RICOS;PREN40;PREN60;PREN80;PRENTRAB;R1040;R2040;RDPC;RDPC1;RDPC10;RDPC2;RDPC3;RDPC4;RDPC5;RDPCT;RIND;RMPOB;RPOB;THEIL;CPR;EMP;P_AGRO;P_COM;P_CONSTR;P_EXTR;P_FORMAL;P_FUND;P_MED;P_SERV;P_SIUP;P_SUPER;P_TRANSF;REN0;REN1;REN2;REN3;REN5;RENOCUP;T_ATIV;T_ATIV1014;T_ATIV1517;T_ATIV1824;T_ATIV18M;T_ATIV2529;T_DES;T_DES1014;T_DES1517;T_DES1824;T_DES18M;T_DES2529;THEILtrab;TRABCC;TRABPUB;TRABSC;T_AGUA;T_BANAGUA;T_DENS;T_LIXO;T_LUZ;AGUA_ESGOTO;PAREDE;T_CRIFUNDIN_TODOS;T_FORA4A5;T_FORA6A14;T_FUNDIN_TODOS;T_FUNDIN_TODOS_MMEIO;T_FUNDIN18MINF;T_M10A14CF;T_M15A17CF;T_MULCHEFEFIF014;T_NESTUDA_NTRAB_MMEIO;T_OCUPDESLOC_1;T_RMAXIDOSO;T_SLUZ;HOMEM0A4;HOMEM10A14;HOMEM15A19;HOMEM20A24;HOMEM25A29;HOMEM30A34;HOMEM35A39;HOMEM40A44;HOMEM45A49;HOMEM50A54;HOMEM55A59;HOMEM5A9;HOMEM60A64;HOMEM65A69;HOMEM70A74;HOMEM75A79;HOMEMTOT;HOMENS80;MULH0A4;MULH10A14;MULH15A19;MULH20A24;MULH25A29;MULH30A34;MULH35A39;MULH40A44;MULH45A49;MULH50A54;MULH55A59;MULH5A9;MULH60A64;MULH65A69;MULH70A74;MULH75A79;MULHER80;MULHERTOT;PEA;PEA1014;PEA1517;PEA18M;peso1;PESO1114;PESO1113;PESO1214;peso13;PESO15;peso1517;PESO1524;PESO1618;PESO18;Peso1820;PESO1824;Peso1921;PESO25;peso4;peso5;peso6;PESO610;Peso617;PESO65;PESOM1014;PESOM1517;PESOM15M;PESOM25M;pesoRUR;pesotot;pesourb;PIA;PIA1014;PIA1517;PIA18M;POP;POPT;I_ESCOLARIDADE;I_FREQ_PROP;IDHM;IDHM_E;IDHM_L;IDHM_R";
    //
    //
    //        $ex = explode(';',$var);
    //
    //        $result = array();
    //
    //        foreach($ex as $v){
    //            $v = trim($v);
    //            $sql = "select id from variavel where sigla ILIKE '$v'";
    //            $arr = $bd->ExecutarSQL($sql);
    //            echo $arr[0]['id'].",$v<br />";
    //        }
    //        $result = array();
    //        foreach($ex as $v){
    //            $v = trim($v);
    //            $sql = "select id from municipio where substring(geocodmun::text from 0 for 7) = '$v'";
    //            $arr = $bd->ExecutarSQL($sql);
    //            if(count($arr) > 1){
    //                die("ERROOOOOOOOOO: $v");
    //            }
    //            if($c > 10) die();
    //            echo $arr[0]['id']."<br />";
    //            $result[] = $arr[0]["id"];
    //            $c++;
    //        }
    //        $lines = file("config/rank_save.csv");
    //        $insert = array();
    //        $sql = "INSERT INTO rank(fk_municipio,posicao_idh,posicao_e_idh,posicao_idhe,posicao_e_idhe,posicao_idhr,posicao_e_idhr,posicao_idhl,posicao_e_idhl) VALUES ";
    //        foreach($lines as $linha){
    //            $insert[] = "(".implode(',',explode(';', $linha)).")";
    //        }
    //        $sql .= implode(',', $insert);
    //        $bd->insert($sql);
    //        die($sql);
    die;
    return;
    $bd = new bd();
    $ALL = array();
    $bd->insert("TRUNCATE TABLE rank");
    $SQL1 = "SELECT fk_municipio,valor,fk_variavel FROM valor_variavel_mun\n                                  WHERE fk_variavel IN (196) and fk_ano_referencia = 3 ORDER BY valor_variavel_mun.valor desc";
    $SQLR = "SELECT fk_municipio,valor,fk_variavel FROM valor_variavel_mun\n                                  WHERE fk_variavel IN (197) and fk_ano_referencia = 3 ORDER BY valor_variavel_mun.valor desc";
    $SQLL = "SELECT fk_municipio,valor,fk_variavel FROM valor_variavel_mun\n                                  WHERE fk_variavel IN (198) and fk_ano_referencia = 3 ORDER BY valor_variavel_mun.valor desc";
    $SQLE = "SELECT fk_municipio,valor,fk_variavel FROM valor_variavel_mun\n                                  WHERE fk_variavel IN (199) and fk_ano_referencia = 3 ORDER BY valor_variavel_mun.valor desc";
    $arr = $bd->ExecutarSQL($SQL1);
    $last = "";
    $posicao = 0;
    foreach ($arr as $key => $v) {
        $v["valor"] = cutNumber($v["valor"], 3, ',', '');
        if ($last != $v["valor"]) {
            $posicao++;
        }
        $last = $v["valor"];
        $ALL[$v["fk_municipio"]][$v["fk_variavel"]] = $posicao;
    }
    $arr = $bd->ExecutarSQL($SQLR);
    $last = "";
    $posicao = 0;
    foreach ($arr as $key => $v) {
        $v["valor"] = cutNumber($v["valor"], 3, ',', '');
        if ($last != $v["valor"]) {
            $posicao++;
        }
        $last = $v["valor"];
        $ALL[$v["fk_municipio"]][$v["fk_variavel"]] = $posicao;
    }
    $arr = $bd->ExecutarSQL($SQLL);
    $last = "";
    $posicao = 0;
    foreach ($arr as $key => $v) {
        $v["valor"] = cutNumber($v["valor"], 3, ',', '');
        if ($last != $v["valor"]) {
            $posicao++;
        }
        $last = $v["valor"];
        $ALL[$v["fk_municipio"]][$v["fk_variavel"]] = $posicao;
    }
    $arr = $bd->ExecutarSQL($SQLE);
    $last = "";
    $posicao = 0;
    foreach ($arr as $key => $v) {
        $v["valor"] = cutNumber($v["valor"], 3, ',', '');
        if ($last != $v["valor"]) {
            $posicao++;
        }
        $last = $v["valor"];
        $ALL[$v["fk_municipio"]][$v["fk_variavel"]] = $posicao;
    }
    for ($i = 1; $i <= 27; $i++) {
        $SQL = "SELECT fk_municipio,valor,fk_variavel FROM valor_variavel_mun\n                        INNER JOIN municipio as m ON (fk_municipio = m.id)\n                        WHERE fk_variavel IN (196) and fk_ano_referencia = 3 AND m.fk_estado = {$i} order by valor";
        $arr = $bd->ExecutarSQL($SQL);
        $last = "";
        $posicao = 0;
        foreach ($arr as $key => $v) {
            $v["valor"] = cutNumber($v["valor"], 3, ',', '');
            if ($last != $v["valor"]) {
                $posicao++;
            }
            $last = $v["valor"];
            $ALL[$v["fk_municipio"]][$v["fk_variavel"] . "e"] = $posicao;
        }
        $SQL = "SELECT fk_municipio,valor,fk_variavel FROM valor_variavel_mun\n                        INNER JOIN municipio as m ON (fk_municipio = m.id)\n                        WHERE fk_variavel IN (197) and fk_ano_referencia = 3 AND m.fk_estado = {$i} order by valor";
        $arr = $bd->ExecutarSQL($SQL);
        $last = "";
        $posicao = 0;
        foreach ($arr as $key => $v) {
            $v["valor"] = cutNumber($v["valor"], 3, ',', '');
            if ($last != $v["valor"]) {
                $posicao++;
            }
            $last = $v["valor"];
            $ALL[$v["fk_municipio"]][$v["fk_variavel"] . "e"] = $posicao;
        }
        $SQL = "SELECT fk_municipio,valor,fk_variavel FROM valor_variavel_mun\n                        INNER JOIN municipio as m ON (fk_municipio = m.id)\n                        WHERE fk_variavel IN (198) and fk_ano_referencia = 3 AND m.fk_estado = {$i} order by valor";
        $arr = $bd->ExecutarSQL($SQL);
        $last = "";
        $posicao = 0;
        foreach ($arr as $key => $v) {
            $v["valor"] = cutNumber($v["valor"], 3, ',', '');
            if ($last != $v["valor"]) {
                $posicao++;
            }
            $last = $v["valor"];
            $ALL[$v["fk_municipio"]][$v["fk_variavel"] . "e"] = $posicao;
        }
        $SQL = "SELECT fk_municipio,valor,fk_variavel FROM valor_variavel_mun\n                        INNER JOIN municipio as m ON (fk_municipio = m.id)\n                        WHERE fk_variavel IN (199) and fk_ano_referencia = 3 AND m.fk_estado = {$i} order by valor";
        $arr = $bd->ExecutarSQL($SQL);
        $last = "";
        $posicao = 0;
        foreach ($arr as $key => $v) {
            $v["valor"] = cutNumber($v["valor"], 3, ',', '');
            if ($last != $v["valor"]) {
                $posicao++;
            }
            $last = $v["valor"];
            $ALL[$v["fk_municipio"]][$v["fk_variavel"] . "e"] = $posicao;
        }
        echo $i . "<br />";
    }
    $SQL2 = array();
    foreach ($ALL as $key => $v) {
        $SQL2[] = "({$key},{$v[196]},{$v[197]},{$v[198]},{$v[199]},{$v["196e"]},{$v["197e"]},{$v["198e"]},{$v["199e"]})";
    }
    $s = join(",", $SQL2);
    $SQL = "INSERT INTO rank(fk_municipio,posicao_idh,posicao_idhr,posicao_idhl,posicao_idhe,posicao_e_idh,posicao_e_idhr,posicao_e_idhl,posicao_e_idhe) values {$s}";
    die($SQL);
    //$bd->insert($SQL);
    //header("location: ../admin");
}
 /**
  * Pega o retorno do SQL
  * @param string $SQL recebe a sql e executa
  * @example <br />array(1) {
  *   <br />[2365]=>
  *   <br />array(2) {
  *     <br />["nome"]=>
  *     <br />string(19) "ABADIA DOS DOURADOS"
  *     <br />[0]=>
  *     <br />array(3) {
  *       <br />["valor"]=>
  *       <br />string(6) "72.936"
  *       <br />["fk_ano_referencia"]=>
  *       <br />string(1) "3"
  *       <br />["fk_variavel"]=>
  *       <br />string(1) "1"
  *     <br />}
  *   <br />}
  */
 private function iRunSQLSecundarioCC($ResultadosMain, $SQL)
 {
     //die($SQL);
     if (strpos($SQL, "()")) {
         die(json_encode(array("erro" => 1, "msg" => " Houve um erro desconhecido no servidor, recarregue a página. <br />Código: #001")));
     }
     $tempArry = parent::ExecutarSQL($SQL, "iRunSQLSecundario22");
     //die(var_dump($tempArry));
     $dv = 0;
     $Formatado = array();
     foreach ($tempArry as $key => $val) {
         if ($val['country'] === 'true') {
             //Paises
             //$Formatado[]=$val['nome'];
             $this->varOnly = false;
             if (!$this->varOnly) {
                 $arg = $val;
                 //die(var_dump($arg));
                 unset($arg['im']);
                 unset($arg['nome']);
                 unset($arg['country']);
                 unset($arg['rm']);
                 unset($arg['u']);
                 unset($arg['uf']);
                 unset($arg['udh']);
                 unset($arg['is_ri']);
                 unset($arg['reg']);
                 unset($arg['cod']);
                 unset($val['rm']);
                 unset($val['u']);
                 unset($val['uf']);
                 unset($val['udh']);
                 unset($val['is_ri']);
                 unset($val['reg']);
                 unset($val['cod']);
                 if (in_array($arg["iv"], PublicMethods::$ArrayPadding3ZerosDireita)) {
                     $arg["v"] = cutNumber($arg["v"], 3, '.', '');
                 } elseif (in_array($val["iv"], PublicMethods::$ArrayPadding2ZerosDireita)) {
                     $arg["v"] = cutNumber($arg["v"], 2, '.', '');
                 } else {
                     $arg["v"] = cutNumber($arg["v"], 2, '.', '');
                 }
                 //if($this->isSearchName)
                 $Formatado[$val['im']]["nome"] = $val["nome"];
                 $Formatado[$val['im']]["country"] = $val["country"];
                 $Formatado[$val['im']]["id"] = str_replace("10000", "", $val["im"]);
                 $Formatado[$val['im']]["esp"] = 10;
                 $Formatado[$val['im']]["vs"][$val["iv"] . "_" . $val["ka"]] = $arg;
             } else {
                 if (in_array($val["iv"], PublicMethods::$ArrayPadding3ZerosDireita)) {
                     $val["v"] = cutNumber($val["v"], 3, '.', '');
                 } elseif (in_array($val["iv"], PublicMethods::$ArrayPadding2ZerosDireita)) {
                     $val["v"] = cutNumber($val["v"], 2, '.', '');
                 } else {
                     $val["v"] = cutNumber($arg["v"], 2, '.', '');
                 }
                 $Formatado[$key] = $val;
             }
         } elseif ($val['rm'] === 'true') {
             //RMs
             //$Formatado[]=$val['nome'];
             if (!$this->varOnly) {
                 $arg = $val;
                 //die(var_dump($arg));
                 unset($arg['im']);
                 unset($arg['nome']);
                 unset($arg['rm']);
                 unset($arg['country']);
                 unset($arg['u']);
                 unset($arg['uf']);
                 unset($arg['udh']);
                 unset($arg['is_ri']);
                 unset($arg['reg']);
                 unset($arg['cod']);
                 unset($val['country']);
                 unset($val['u']);
                 unset($val['uf']);
                 unset($val['udh']);
                 unset($val['is_ri']);
                 unset($val['reg']);
                 unset($val['cod']);
                 if (in_array($arg["iv"], PublicMethods::$ArrayPadding3ZerosDireita)) {
                     $arg["v"] = cutNumber($arg["v"], 3, '.', '');
                 } elseif (in_array($val["iv"], PublicMethods::$ArrayPadding2ZerosDireita)) {
                     $arg["v"] = cutNumber($arg["v"], 2, '.', '');
                 } else {
                     $arg["v"] = cutNumber($arg["v"], 2, '.', '');
                 }
                 //if($this->isSearchName)
                 $Formatado[$val['im']]["nome"] = $val["nome"];
                 //$Formatado[$val['im']]["u"] = $val["u"];
                 $Formatado[$val['im']]["rm"] = $val["rm"];
                 $Formatado[$val['im']]["id"] = str_replace("10000", "", $val["im"]);
                 $Formatado[$val['im']]["esp"] = 6;
                 $Formatado[$val['im']]["vs"][$val["iv"] . "_" . $val["ka"]] = $arg;
             } else {
                 foreach ($tempArry as $key => $val) {
                     if (in_array($val["iv"], PublicMethods::$ArrayPadding3ZerosDireita)) {
                         $val["v"] = cutNumber($val["v"], 3, '.', '');
                     } elseif (in_array($val["iv"], PublicMethods::$ArrayPadding2ZerosDireita)) {
                         $val["v"] = cutNumber($val["v"], 2, '.', '');
                     } else {
                         $val["v"] = cutNumber($arg["v"], 2, '.', '');
                     }
                     $Formatado[$key] = $val;
                 }
             }
         } elseif ($val['reg'] === 'true') {
             //Regional
             //$Formatado[]=$val['nome'];
             if (!$this->varOnly) {
                 $arg = $val;
                 //die(var_dump($arg));
                 unset($arg['im']);
                 unset($arg['nome']);
                 unset($arg['reg']);
                 unset($arg['country']);
                 unset($arg['u']);
                 unset($arg['uf']);
                 unset($arg['rm']);
                 unset($arg['udh']);
                 unset($arg['is_ri']);
                 unset($arg['cod']);
                 unset($val['country']);
                 unset($val['u']);
                 unset($val['uf']);
                 unset($val['rm']);
                 unset($val['udh']);
                 unset($val['is_ri']);
                 unset($val['cod']);
                 if (in_array($arg["iv"], PublicMethods::$ArrayPadding3ZerosDireita)) {
                     $arg["v"] = cutNumber($arg["v"], 3, '.', '');
                 } elseif (in_array($val["iv"], PublicMethods::$ArrayPadding2ZerosDireita)) {
                     $arg["v"] = cutNumber($arg["v"], 2, '.', '');
                 } else {
                     $arg["v"] = cutNumber($arg["v"], 2, '.', '');
                 }
                 //if($this->isSearchName)
                 $Formatado[$val['im']]["nome"] = $val["nome"];
                 //$Formatado[$val['im']]["u"] = $val["u"];
                 $Formatado[$val['im']]["reg"] = $val["reg"];
                 $Formatado[$val['im']]["id"] = str_replace("10000", "", $val["im"]);
                 $Formatado[$val['im']]["esp"] = 3;
                 $Formatado[$val['im']]["vs"][$val["iv"] . "_" . $val["ka"]] = $arg;
             } else {
                 foreach ($tempArry as $key => $val) {
                     if (in_array($val["iv"], PublicMethods::$ArrayPadding3ZerosDireita)) {
                         $val["v"] = cutNumber($val["v"], 3, '.', '');
                     } elseif (in_array($val["iv"], PublicMethods::$ArrayPadding2ZerosDireita)) {
                         $val["v"] = cutNumber($val["v"], 2, '.', '');
                     } else {
                         $val["v"] = cutNumber($arg["v"], 2, '.', '');
                     }
                     $Formatado[$key] = $val;
                 }
             }
         } elseif ($val['udh'] === 'true') {
             //UHDs
             //$Formatado[]=$val['nome'];
             if (!$this->varOnly) {
                 $arg = $val;
                 //die(var_dump($arg));
                 unset($arg['im']);
                 unset($arg['nome']);
                 unset($arg['udh']);
                 unset($arg['country']);
                 unset($arg['u']);
                 unset($arg['uf']);
                 unset($arg['rm']);
                 unset($arg['is_ri']);
                 unset($arg['reg']);
                 unset($arg['cod']);
                 unset($val['country']);
                 unset($val['u']);
                 unset($val['uf']);
                 unset($val['rm']);
                 unset($val['is_ri']);
                 unset($val['reg']);
                 unset($val['cod']);
                 if (in_array($arg["iv"], PublicMethods::$ArrayPadding3ZerosDireita)) {
                     $arg["v"] = cutNumber($arg["v"], 3, '.', '');
                 } elseif (in_array($val["iv"], PublicMethods::$ArrayPadding2ZerosDireita)) {
                     $arg["v"] = cutNumber($arg["v"], 2, '.', '');
                 } else {
                     $arg["v"] = cutNumber($arg["v"], 2, '.', '');
                 }
                 //if($this->isSearchName)
                 $Formatado[$val['im']]["nome"] = $val["nome"];
                 //$Formatado[$val['im']]["u"] = $val["u"];
                 $Formatado[$val['im']]["udh"] = $val["udh"];
                 $Formatado[$val['im']]["id"] = str_replace("10000", "", $val["im"]);
                 $Formatado[$val['im']]["esp"] = 5;
                 $Formatado[$val['im']]["vs"][$val["iv"] . "_" . $val["ka"]] = $arg;
             } else {
                 foreach ($tempArry as $key => $val) {
                     if (in_array($val["iv"], PublicMethods::$ArrayPadding3ZerosDireita)) {
                         $val["v"] = cutNumber($val["v"], 3, '.', '');
                     } elseif (in_array($val["iv"], PublicMethods::$ArrayPadding2ZerosDireita)) {
                         $val["v"] = cutNumber($val["v"], 2, '.', '');
                     } else {
                         $val["v"] = cutNumber($arg["v"], 2, '.', '');
                     }
                     $Formatado[$key] = $val;
                 }
             }
         } elseif (strlen($val['u']) and !strlen($val['uf'])) {
             //Estatual
             if (!$this->varOnly) {
                 $arg = $val;
                 unset($arg['im']);
                 unset($arg['nome']);
                 unset($arg['u']);
                 unset($arg['cod']);
                 unset($arg['country']);
                 unset($arg['rm']);
                 unset($arg['uf']);
                 unset($arg['udh']);
                 unset($arg['is_ri']);
                 unset($arg['reg']);
                 unset($val['country']);
                 unset($val['rm']);
                 unset($val['uf']);
                 unset($val['udh']);
                 unset($val['is_ri']);
                 unset($val['reg']);
                 if (in_array($arg["iv"], PublicMethods::$ArrayPadding3ZerosDireita)) {
                     $arg["v"] = cutNumber($arg["v"], 3, '.', '');
                 } elseif (in_array($val["iv"], PublicMethods::$ArrayPadding2ZerosDireita)) {
                     $arg["v"] = cutNumber($arg["v"], 2, '.', '');
                 } else {
                     $arg["v"] = cutNumber($arg["v"], 2, '.', '');
                 }
                 //if($this->isSearchName)
                 $Formatado[$val['im']]["nome"] = $val["nome"];
                 $Formatado[$val['im']]["u"] = $val["u"];
                 $Formatado[$val['im']]["cod"] = $val["cod"];
                 $Formatado[$val['im']]["id"] = str_replace("10000", "", $val["im"]);
                 $Formatado[$val['im']]["esp"] = 4;
                 $Formatado[$val['im']]["vs"][$val["iv"] . "_" . $val["ka"]] = $arg;
             } else {
                 if (in_array($val["iv"], PublicMethods::$ArrayPadding3ZerosDireita)) {
                     $val["v"] = cutNumber($val["v"], 3, '.', '');
                 } elseif (in_array($val["iv"], PublicMethods::$ArrayPadding2ZerosDireita)) {
                     $val["v"] = cutNumber($val["v"], 2, '.', '');
                 } else {
                     $val["v"] = cutNumber($arg["v"], 2, '.', '');
                 }
                 $Formatado[$key] = $val;
             }
         } elseif (strlen($val['u']) and strlen($val['uf'])) {
             //Municipal
             //$Formatado[]=$val['nome'];
             if (!$this->varOnly) {
                 //$dv++;
                 $arg = $val;
                 unset($arg['im']);
                 unset($arg['nome']);
                 unset($arg['uf']);
                 unset($arg['cod']);
                 unset($arg['country']);
                 unset($arg['rm']);
                 unset($arg['u']);
                 unset($arg['udh']);
                 unset($arg['is_ri']);
                 unset($arg['reg']);
                 unset($val['country']);
                 unset($val['rm']);
                 unset($val['u']);
                 unset($val['udh']);
                 unset($val['is_ri']);
                 unset($val['reg']);
                 if (in_array($arg["iv"], PublicMethods::$ArrayPadding3ZerosDireita)) {
                     $arg["v"] = cutNumber($arg["v"], 3, '.', '');
                 } elseif (in_array($val["iv"], PublicMethods::$ArrayPadding2ZerosDireita)) {
                     $arg["v"] = cutNumber($arg["v"], 2, '.', '');
                 } else {
                     $arg["v"] = cutNumber($arg["v"], 2, '.', '');
                 }
                 //if($this->isSearchName){
                 //if(isset($val["nome"]))
                 $Formatado[$val['im']]["nome"] = $val["nome"];
                 if (isset($val["uf"])) {
                     $Formatado[$val['im']]["uf"] = $val["uf"];
                 }
                 //}
                 $Formatado[$val['im']]["cod"] = $val["cod"];
                 $Formatado[$val['im']]["id"] = $val["im"];
                 $Formatado[$val['im']]["esp"] = 2;
                 $Formatado[$val['im']]["vs"][$val["iv"] . "_" . $val["ka"]] = $arg;
             } else {
                 foreach ($tempArry as $key => $val) {
                     if (in_array($val["iv"], PublicMethods::$ArrayPadding3ZerosDireita)) {
                         $val["v"] = cutNumber($val["v"], 3, '.', '');
                     } elseif (in_array($val["iv"], PublicMethods::$ArrayPadding2ZerosDireita)) {
                         $val["v"] = cutNumber($val["v"], 2, '.', '');
                     } else {
                         $val["v"] = cutNumber($arg["v"], 2, '.', '');
                     }
                     $Formatado[$key] = $val;
                 }
             }
         }
     }
     //die(var_dump($Formatado));
     //die(var_dump($dv));
     $this->results = $Formatado;
 }
 public function draw()
 {
     $ts = false;
     $counter = 0;
     $last = "0";
     $answer = "";
     $j = 0;
     foreach ($this->data as $key => $val) {
         $label = "";
         $class = "bolinhaRank ";
         $n = (double) cutNumber($val["vs"][INDICADOR_IDH]['v'], 3, '.');
         $n = (double) cutNumber($val["vs"][INDICADOR_IDH]['v'], 3, '.');
         //Indica a cor da bolinha que será usada
         if ($n < Ranking::vB) {
             $class .= "bolinhaMuitoRuim";
             $label = $this->lang->getString("rankin_m_baixo");
         } elseif ($n < Ranking::vC) {
             $class .= "bolinhaRuim";
             $label = $this->lang->getString("rankin_baixo");
         } elseif ($n < Ranking::vD) {
             $class .= "bolinhaMedia";
             $label = $this->lang->getString("rankin_medio");
         } elseif ($n < Ranking::vE) {
             $class .= "bolinhaBom";
             $label = $this->lang->getString("rankin_alto");
         } else {
             $class .= "bolinhaOtimo";
             $label = $this->lang->getString("rankin_fm_alto");
         }
         if (cutNumber($val["vs"][$this->pOrdem_id]['v'], 3, '.', '') != $last) {
             $counter++;
         }
         //Preparação do link para o perfil
         if ($this->pEspc == 'municipal') {
             $link = "<a href=" . $_SESSION['lang'] . '/perfil_m/' . $this->trataNome($val['mun']) . '_' . ($espc2Convertida = strtolower($val['uf']) . " target='_blank'>");
             $balao = "data-original-title='' title data-placement='bottom";
         }
         if ($this->pEspc == 'estadual') {
             $link = "<a href=" . $_SESSION['lang'] . '/perfil_uf/' . $this->trataNome($val['n']) . " target='_blank'>";
         }
         if ($this->pEspc == 'rm') {
             if ($val['ativo'] == 't') {
                 $link = "<a href=" . $_SESSION['lang'] . '/perfil_rm/' . $this->trataNome($val['n']) . " target='_blank'>";
             } else {
                 $link = '';
             }
         }
         if ($this->pEspc == 'udh') {
             $link = "<a href=" . $_SESSION['lang'] . '/perfil_udh/' . $val['idgeo'] . " target='_blank'>";
         }
         echo "<tr class='rank'>";
         $answer .= "<td class='numRank'>{$link}{$val["ot"]} º</a></td>";
         $answer .= "<td class='rankLugar' >{$link}{$val["n"]}</a></td>";
         $c = 0;
         foreach ($val["vs"] as $k => $v) {
             $val["vs"][$k]["v"] = cutNumber($v["v"], 3, ',', '');
             if ($k == INDICADOR_IDH) {
                 $answer .= "<td class='cell_rank td_rank_cell _{$c}'>" . $link . $val["vs"][$k]["v"] . "<div class='{$class} float-right' data-original-title='{$label}' title data-placement='bottom'></div></a></td>";
             } else {
                 $answer .= "<td class='cell_rank td_rank_cell _{$c}'>" . $link . $val["vs"][$k]["v"] . "</a></td>";
             }
             $c++;
         }
         $last = $val["vs"][$this->pOrdem_id]['v'];
         $answer .= "</tr>";
         $ts = !$ts;
         $j++;
     }
     $this->pStart = $counter;
     echo "<table class='rank_table'>";
     echo "<thead><th class='numRank padding-10px-bottom'>{$this->lang->getString("rankin_posicao")}</th><th class='rankLugar'>{$this->lang->getString("rankin_Lugar")}</th>";
     $or = "asc";
     foreach ($this->data as $key => $val) {
         $c = 0;
         foreach ($val["vs"] as $k => $v) {
             $or = "asc";
             $class = "";
             $class_ds = "";
             if ($v["k"] == $this->pOrdem_id) {
                 if ($this->pOrdem == "asc") {
                     $or = "desc";
                     $class_ds = "destaqueRank1";
                     $class = "rank_arrow rank_arrow_down";
                 } else {
                     $class_ds = "destaqueRank1";
                     $class = "rank_arrow rank_arrow_up";
                 }
             }
             switch ($v["k"]) {
                 case INDICADOR_IDH:
                     echo "<th onclick=\"sendData({$v["k"]},'{$or}',{$this->pPag},'{$this->pEspc}',{$this->pStart},{$this->pEstado})\" class='indicRank'><div class='{$class}' data-original-title='Ordenar' data-placement='bottom' ></div><div style='clear: both'></div><div class='nameIndcRank idh-td-rank {$class_ds} j_{$c}'>{$this->lang->getString("rankin_idhm")}</div></th>";
                     break;
                 case INDICADOR_RENDA:
                     echo "<th onclick=\"sendData({$v["k"]},'{$or}',{$this->pPag},'{$this->pEspc}',{$this->pStart},{$this->pEstado})\" class='indicRank'><div class='{$class}' data-original-title='Ordenar' data-placement='bottom'></div><div style='clear: both'></div><div class='nameIndcRank {$class_ds} j_{$c}'>{$this->lang->getString("rankin_renda2")}</div></th>";
                     break;
                 case INDICADOR_LONGEVIDADE:
                     echo "<th onclick=\"sendData({$v["k"]},'{$or}',{$this->pPag},'{$this->pEspc}',{$this->pStart},{$this->pEstado})\" class='indicRank'><div class='{$class}' data-original-title='Ordenar' data-placement='bottom'></div><div style='clear: both'></div><div class='nameIndcRank {$class_ds} j_{$c}'>{$this->lang->getString("rankin_Long")}</div></th>";
                     break;
                 case INDICADOR_EDUCACAO:
                     echo "<th onclick=\"sendData({$v["k"]},'{$or}',{$this->pPag},'{$this->pEspc}',{$this->pStart},{$this->pEstado})\" class='indicRank'><div class='{$class}' data-original-title='Ordenar' data-placement='bottom'></div><div style='clear: both'></div><div class='nameIndcRank {$class_ds} j_{$c}'>{$this->lang->getString("rankin_edu")}</div></th>";
                     break;
                 default:
                     break;
             }
             $c++;
         }
         break;
     }
     echo "</thead>";
     echo $answer;
     if (!$this->showBtn) {
         if ($j > 99) {
             echo "<tr id='tr_load_more'><td colspan='100%'><a class='button-carregar-mais' style='float:right' type='button'>{$this->lang->getString("rankin_exibir_all")}</a></td></tr>";
         }
     } else {
         ?>
         <script>
             $('html, body').animate({
                 scrollTop: $("tr:eq(100)").offset().top - 300
             }, 300);
         </script>
         <?php 
         if ($j > 99) {
             echo "<tr id='tr_load_more'><td colspan='100%'><a style='float:right;cursor:pointer' type='button' onclick='javascript:\$(\"html,body\").scrollTop(0)'></a></td></tr>";
         }
     }
     echo "</table>";
 }