home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Amiga 12 / MA_Cover_12.iso / internet / freedomc_112 / sourcecode / freedomcall / freeextern.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-05-27  |  140.3 KB  |  3,817 lines

  1. /*
  2.   PROGRAMA   : Freedom Call
  3.   UNIT       : FreeExtern.c
  4.   AUTOR      : Cristian Robert Gallas (SuRRouND)
  5.   DATA       : 01/02/1998 a 21.05.1999
  6.   S.O.       : Workbench & AmigaDos
  7.   LINGUAGEM  : SAS C 6.58 + MUI Library
  8.   PLATAFORMA : Amiga ECS & AGA
  9.   DEPENDE    : Mui 3.7+, 2 mb+
  10. */
  11.  
  12. #include <surround.h>
  13. #include "freedom.h"
  14. #include "freegui.h"
  15. #include "freemain.h"
  16. #include "freeextern.h"
  17.  
  18. #include <fcntl.h>
  19. #include <exec/memory.h>
  20. #include <proto/muimaster.h>
  21. #include <clib/alib_protos.h>
  22. #include <clib/dos_protos.h>
  23. #include <clib/exec_protos.h>
  24. #include <libraries/mui.h>
  25. #include <libraries/asl.h>
  26.  
  27. CarregaPilhaCategorias(char categoria[256])
  28. {
  29.   /* CARREGA OS LIMITES PARA UMA VARIAVEL GLOBAL */
  30.   char *categorydir, a, teste[256], lecateg[256];
  31.   int x = 0, pos = 0;
  32.   FILE *entrada;
  33.  
  34.   get(App->CategDiretorio, MUIA_String_Contents, &categorydir);
  35.   sprintf(lecateg, "%s/%s", categorydir, categoria);
  36.  
  37.   if(!(entrada = fopen(lecateg, "r")))
  38.     return 0;
  39.  
  40.   x = 0; pos = 0;
  41.   while(a = getc(entrada), ! feof(entrada))
  42.   {
  43.     teste[x++] = a;
  44.     if(a == '\n') {
  45.       teste[--x] = '\0';
  46.       strcpy(pilha[pos++], teste);
  47.       teste[0] = '\0'; x = 0; }
  48.   }
  49.   pilhafim = --pos;
  50.   fclose(entrada);
  51. }
  52.  
  53. int CarregaBarraStatus(void)
  54. {
  55.   /* CARREGA A DATA DE HOJE NA BARRA DA JANELA GRAFICA */
  56.   char teste[256], dia[20];
  57.   strcpy(dia, DataHora(0));
  58.  
  59.   sprintf(teste, "\033r%s, of %s %s (%s)", Corta(dia, '.', 0), DescricaoMesFREE(atoi(Corta(dia, '.', 1)), 1), Corta(dia, '.', 2), DiaSemanaFREE(dia, 1));
  60.   set(App->Janela2StatusBar, MUIA_Text_Contents, teste);
  61.   return NULL;
  62. }
  63.  
  64. int CarregaLista(struct Hook *objeto, char arq[256])
  65. {
  66.   /* ESTA ROTINA CARREGA APARTIR DE UM ARQUIVO UMA LISTA FLOAT TEXT */
  67.   APTR *text;
  68.   long filesize = 0;
  69.   BPTR entrada;
  70.  
  71.   set(objeto, MUIA_Floattext_Text, NULL);
  72.   if(!(entrada = Open(arq, MODE_OLDFILE)))
  73.     return 0;
  74.   filesize = atof(ExaminaArquivo(arq, 0));
  75.   text = AllocVec(filesize+1, MEMF_ANY|MEMF_CLEAR);
  76.   text[filesize] = '\0';
  77.  
  78.   Read(entrada, text, filesize);
  79.   Close(entrada);
  80.  
  81.   set(objeto, MUIA_Floattext_Text, text);
  82.   FreeVec(text);
  83.   return NULL;
  84. }
  85.  
  86. int TestaPedidoRegistro(void)
  87. {
  88.   /* VERIFICA SE AS INFORMACOES DO PEDIDO DE REGISTRO SAO VALIDAS
  89.      RETORNA: 
  90.      0 - INFORMACOES EM BRANCO
  91.      1 - INFORMACOES INVALIDAS
  92.     -1 - OK */
  93.   char *regemail, *regname, *regcountry, *regcity, *regnumber;
  94.   get(App->RegisterKey, MUIA_String_Contents, ®number);
  95.   get(App->RegisterName, MUIA_String_Contents, ®name);
  96.   get(App->RegisterEmail, MUIA_String_Contents, ®email);
  97.   get(App->RegisterCountry, MUIA_String_Contents, ®country);
  98.   get(App->RegisterCity, MUIA_String_Contents, ®city);
  99.  
  100.   if(!strcmp(regnumber, ""))
  101.     return 0;
  102.   if(strlen(regemail) < 4 || strlen(regname) < 4 || strlen(regcountry) < 2 || strlen(regcity) < 2)
  103.     return 1;
  104.   return -1;
  105. }
  106.  
  107. int CarregaListaLimites(char categoria[256])
  108. {
  109.   /* ROTINA QUE ADICIONA UM LIMITE NOVO A LISTA */
  110.   static struct buffer {
  111.     char lista[256];
  112.   };
  113.   static struct buffer listaarray[50];
  114.  
  115.   char teste[256], a, *categorydir, var1[50], var2[50], var3[50],
  116.        var4[50], var5[50], lecateg[256];
  117.   int x = 0;
  118.   long pos = 0;
  119.   FILE *entrada;
  120.  
  121.   get(App->CategDiretorio, MUIA_String_Contents, &categorydir);
  122.   sprintf(lecateg, "%s/%s", categorydir, categoria);
  123.  
  124.   if(!(entrada = fopen(lecateg, "r")))
  125.     return 0;
  126.  
  127.   DoMethod(App->LimitesLista, MUIM_List_Clear);
  128.   x = 0; pos = 0;
  129.   while(a = getc(entrada), ! feof(entrada))
  130.   {
  131.     teste[x++] = a;
  132.     if(a == '\n')
  133.     {
  134.       teste[--x] = '\0';
  135.       if(strcmp(Corta(teste, ':', 0), "**>money"))
  136.       {
  137.         pos++;
  138.         if(pos < 51)
  139.         {
  140.           strcpy(var1, SegundoHora(Corta(teste, ' ', 0)));
  141.           strcpy(var2, SegundoHora(Corta(teste, ' ', 1)));
  142.           strcpy(var3, Corta(teste, ' ', 2));
  143.           strcpy(var4, Corta(teste, ' ', 3));
  144.           strcpy(var5, Corta(teste, ' ', 4));
  145.           sprintf(teste, "%s %s %s %s %s", var1, var2, var3, var4, var5);
  146.           strcpy(listaarray[pos].lista, teste);
  147.           DoMethod(App->LimitesLista, MUIM_List_InsertSingle, &listaarray[pos].lista[0], MUIV_List_Insert_Bottom);
  148.         }
  149.       }
  150.       teste[0] = '\0'; x = 0;
  151.     }
  152.   }
  153.   fclose(entrada);
  154.   sprintf(teste, LeRegistroDB(lecateg, "money"));
  155.  
  156.   strcpy(var1, Corta(teste, '@', 1));
  157.   if(!strcmp(var1, "CUTERRO"))
  158.     set(App->NomeMoeda, MUIA_String_Contents, "");
  159.   else
  160.     set(App->NomeMoeda, MUIA_String_Contents, var1);
  161.  
  162.   set(App->ComboMoeda, MUIA_Cycle_Active, atof(Corta(teste, '@', 0)));
  163.  
  164.   set(App->NomeCategoria, MUIA_String_Contents, categoria);
  165.   return -1;
  166. }
  167.  
  168. int CarregaListaCategorias(void)
  169. {
  170.   char *categorydir;
  171.  
  172.   DoMethod(App->CategoriesList, MUIM_List_Clear);
  173.   get(App->CategDiretorio, MUIA_String_Contents, &categorydir);
  174.   DiretorioArquivo(categorydir, "T:Freedom.CategoryDir", 0);
  175.  
  176.   /* CARREGA DO ARQUIVO PARA A LISTA */
  177.   CarregaLista(App->CategoriesList, "T:Freedom.CategoryDir");
  178.   remove("T:Freedom.CategoryDir");
  179.   return -1;
  180. }
  181.  
  182. int MsgRegistro(void)
  183. {
  184.   MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg18), TMsg(App->Msg60));
  185.   return NULL;
  186. }
  187.  
  188. LimpaJanelaDesseMes(void)
  189. {
  190.   /* LIMPA OS CAMPOS DA JANELA DE CONSULTA DESSE E DE OUTRO MES */
  191.   set(App->LabelMesUso, MUIA_Text_Contents, TMsg(App->Msg16));
  192.   set(App->LabelMesNumero, MUIA_Text_Contents, TMsg(App->Msg1));
  193.   set(App->NrQuedaLinhaMes, MUIA_Text_Contents, TMsg(App->Msg4));
  194.   set(App->NrLogoutGoodMes, MUIA_Text_Contents, TMsg(App->Msg5));
  195.   set(App->NrDownResetMes, MUIA_Text_Contents, TMsg(App->Msg6));
  196.   set(App->LabelMesUsadas, MUIA_Text_Contents, TMsg(App->Msg7));
  197.   set(App->LabelMesMedia, MUIA_Text_Contents, TMsg(App->Msg9));
  198.   set(App->LabelMesData, MUIA_Text_Contents, TMsg(App->Msg11));
  199.   set(App->LabelMesMaior, MUIA_Text_Contents, TMsg(App->Msg10));
  200.   set(App->LabelMesLow, MUIA_Text_Contents, TMsg(App->Msg12));
  201.   set(App->LabelMesMenor, MUIA_Text_Contents, TMsg(App->Msg13));
  202.   set(App->LabelMesExedentes, MUIA_Text_Contents, TMsg(App->Msg2));
  203.   set(App->LabelUltimaLigacao, MUIA_Text_Contents, TMsg(App->Msg14));
  204.   set(App->LabelPrimeiraLigacao, MUIA_Text_Contents, TMsg(App->Msg15));
  205.   set(App->LabelCost, MUIA_Text_Contents, TMsg(App->Msg75));
  206.   set(App->LabelCostAverage, MUIA_Text_Contents, TMsg(App->Msg76));
  207.   return NULL;
  208. }
  209.  
  210. int ConverteParaFreedom(char file[256])
  211. {
  212.   /* ESTE COMANDO CONVERTE UM ARQUIVO PARA JOGAR NA BASE DO 
  213.      FREEDOM CALL, O FORMATO DEVE SER IGUAL AO FREEDOM.INPUT,
  214.      FREEDOM.IN */
  215.   char a, teste[256], data1[256], *database, saida[256];
  216.   int x = 0;
  217.   FILE *entrada;
  218.   
  219.   get(App->DataBaseName, MUIA_String_Contents, &database);
  220.   if(!(entrada = fopen(file, "r")))
  221.     return 0;
  222.  
  223.   while(a = getc(entrada), ! feof(entrada))
  224.   {
  225.     teste[x++] = a;
  226.     if(a == '\n')
  227.     {
  228.       teste[--x] = '\0';
  229.       strcpy(data1, Corta(teste, ',', 1));
  230.       strcpy(data1, AposCaracter(data1, '.', 1));
  231.       sprintf(saida, "%s/Freedom.%s", database, data1);
  232.       sprintf(teste, "%s\n", teste);
  233.       GravaLinha(saida, teste, "a");
  234.       teste[0] = '\0'; x = 0;
  235.     }
  236.   }
  237.   fclose(entrada);
  238. }
  239.  
  240. APTR Geracao( struct Hook *a0, APTR a2, APTR a1 )
  241. {
  242.    /* ESTA ROTINA FAZ A IMPORTACAO DOS DADOS DO MIAMI PARA DENTRO
  243.       DO FREEDOM CALL, A IMPORTACAO EH TOTAL, CASO EXISTA INFORMACOES
  244.       NA BASE DO FREEDOM SERAO TODAS REFEITAS APARTIR DO MIAMI */
  245.    char *path, a, teste[256], pego[256], diferenca[256], gauge[30],
  246.         telefone[20], dataon[20], dataoff[20], statusini[4], 
  247.         horaon[20], horaoff[20], linhaini[256], tempoon[40],
  248.         pegolinha[256], recfone[20], tmp[256], *database,
  249.         diaa[256], connect[256], lastfone[20], *anodis, *timedis;
  250.    long int x, y, pegon, linhan = 0, erro = 0, dx = 0;
  251.    float totalarq, gaugep;
  252.    long warning = 0;
  253.    FILE *entrada, *freedomout;
  254.  
  255.    get(App->RequestMiamiLog, MUIA_String_Contents, &path);
  256.    /* TESTA SE O DIRETORIO DA BASE DE DADOS EXISTE */
  257.    get(App->DataBaseName, MUIA_String_Contents, &database);
  258.    if(!ExisteDiretorio(database))
  259.    {
  260.       MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg18), TMsg(App->Msg17));
  261.       return NULL;
  262.    }
  263.    set(App->GaugeGeracao, MUIA_Gauge_Current, 0);
  264.  
  265.    /* LE INFORMACOES DO CONFIG TIMEDIS, ANODIS */
  266.    get(App->ExcededYear, MUIA_String_Contents, &anodis);
  267.    get(App->ExcededTime, MUIA_String_Contents, &timedis);
  268.  
  269.    /* ROTINA QUE VERIFICA SE JA EXISTE UMA BASE DE DADOS */
  270.    DiretorioArquivoFREE(database, "T:Freedom.DataDir", 1);
  271.    if(LinhasArquivo("T:Freedom.DataDir") > 0)
  272.    {
  273.        /* DATABASE ALREADY EXIST, CLEAR, CANCEL, OK */
  274.        x = MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg20), TMsg(App->Msg21));
  275.        if(x == 0) {
  276.          remove("T:Freedom.DataDir");
  277.          return NULL; }
  278.        if(x == 1)
  279.        {
  280.          DeletaArquivos("T:Freedom.DataDir");
  281.          sprintf(teste, "%s/Freedom.Out", database);
  282.          remove(teste);
  283.        }
  284.    }
  285.    remove("T:Freedom.DataDir");
  286.  
  287.    set(App->EspereGerando, MUIA_Window_Open, TRUE);
  288.    /* TESTA SE O ARQUIVO EXISTE */
  289.    if(!(entrada = fopen(path, "r")))
  290.    {
  291.       fclose(entrada);
  292.       set(App->EspereGerando,MUIA_Window_Open,FALSE);
  293.       /* MIAMI LOG FILE NOT FOUND */
  294.       MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg18), TMsg(App->Msg22));
  295.       return NULL;
  296.    }
  297.    else
  298.    {
  299.       totalarq   = LinhasArquivo(path);
  300.       sprintf(teste, "%s/Freedom.Out", database);
  301.       freedomout = fopen(teste, "a");
  302.  
  303.       /* ABRE O ARQUIVO E GERA A IMPORTACAO DOS DADOS DO MIAMI */
  304.       x = 0; y = 0; linhaini[0] = '\0'; pegon = 0; gaugep = 0;
  305.       linhan = 0;
  306.       while(a = getc(entrada), ! feof(entrada))
  307.       {
  308.          teste[x++] = a;
  309.          if (a == '\n' || a == '\0')
  310.          {
  311.            teste[--x] = '\0';
  312.            linhan++;
  313.  
  314.            /* PEGA O STATUS 
  315.            Onl -> Online, Hora Login
  316.            Act -> Active Logout, Normal Logout
  317.            Pas -> Passive Logout, Caiu a Linha
  318.            Rec -> Reconnect */
  319.            statusini[0] = teste[0];
  320.            statusini[1] = teste[1];
  321.            statusini[2] = teste[2];
  322.            statusini[3] = '\0';
  323.  
  324.            if(x > 20 && !strcmp(statusini, "Onl") || !strcmp(statusini, "Pas") || !strcmp(statusini, "Act"))
  325.            {
  326.              gaugep++;
  327.              sprintf(gauge, "%f", ((100 / totalarq) * gaugep));
  328.              set(App->GaugeGeracao, MUIA_Gauge_Current, atoi(gauge));
  329.              set(App->GaugeGeracao, MUIA_Gauge_InfoText, "%ld %%");
  330.  
  331.              strcpy(teste, AposCaracter(teste, ':', 2));
  332.  
  333.              /* ROTINA QUE TESTA SE EH LOG DO MIAMIDX */
  334.              strcpy(tmp, Corta(teste, ' ', 0));
  335.              if(PosicaoCaracter(tmp, ':', 1) > 10)
  336.                dx = 1; else dx = 0;
  337.  
  338.              if(dx == 1)
  339.              {
  340.                strcpy(dataon, Corta(tmp, ':', 0));
  341.                strcpy(horaon, HoraSegundo(AposCaracter(tmp, ':', 1)));
  342.                strcpy(connect, Corta(teste, ' ', 2));
  343.  
  344.              } else {
  345.  
  346.                strcpy(dataon, Corta(teste, ' ', 0));
  347.                strcpy(horaon, HoraSegundo(Corta(teste, ' ', 1)));
  348.                strcpy(connect, Corta(teste, ' ', 3));
  349.              }
  350.  
  351.              if(!strcmp(connect, "CUTERRO"))
  352.                strcpy(connect, "Miami");
  353.  
  354.              if(!strcmp(statusini, "Onl"))
  355.              {
  356.                if(dx == 1)
  357.                  strcpy(telefone, Corta(teste, ' ', 1));
  358.                else
  359.                  strcpy(telefone, Corta(teste, ' ', 2));
  360.  
  361.                strcpy(telefone, RetiraPontas(telefone, 1));
  362.                strcpy(telefone, Corta(DeletaCaracter(telefone, ','), ':', 0));
  363.              }
  364.  
  365.              strcpy(recfone, telefone);
  366.              if(!strcmp(telefone, "UTERR"))
  367.                strcpy(telefone, lastfone);
  368.  
  369.              sprintf(linhaini, "%s,%s,%s,%s", telefone, dataon, horaon, connect);
  370.  
  371.              strcpy(lastfone, telefone);
  372.              if (pegon == 1)
  373.              {
  374.                if ((!strcmp(pego, "Onl")) && (strcmp(statusini, "Onl")))
  375.                {
  376.                  /* FREEDOM.IN */
  377.                  strcpy(telefone, Corta(pegolinha, ',', 0));
  378.                  strcpy(dataon, Corta(pegolinha, ',', 1));
  379.                  strcpy(horaon, Corta(pegolinha, ',', 2));
  380.                  strcpy(connect, Corta(pegolinha, ',', 3));
  381.  
  382.                  /* TESTA DATA INVALIDA < CONFIG (Disconsidera) */
  383.                  if(atof(DiaJuliano(dataon)) < atof(DiaJuliano(anodis)))
  384.                    continue;
  385.  
  386.                  /* ROTINA QUE TESTA SE EH LOG DO MIAMIDX */
  387.                  if(dx == 1)
  388.                  {
  389.                    strcpy(dataoff, Corta(tmp, ':', 0));
  390.                    strcpy(horaoff, HoraSegundo(AposCaracter(tmp, ':', 1)));
  391.  
  392.                  } else {
  393.  
  394.                    strcpy(dataoff, Corta(teste, ' ', 0));
  395.                    strcpy(horaoff, HoraSegundo(Corta(teste, ' ', 1)));
  396.                  }
  397.  
  398.                  strcpy(tempoon, IntervaloHora(Corta(pegolinha, ',', 2), horaoff));
  399.                  /* TESTA SE TROCOU DE DIA A CONECCAO */
  400.                  strcpy(diferenca, Corta(DiferencaDias(Corta(pegolinha, ',', 1), dataoff), ':', 1));
  401.   
  402.                  if(atoi(diferenca) > 0)
  403.                    sprintf(tempoon, "%ld", atoi(diferenca) - atoi(tempoon));
  404.  
  405.                  /* TESTA ANO INVALIDO */
  406.                  if(atof(tempoon) > atof(HoraSegundo(timedis)))
  407.                    continue;
  408.  
  409.                  strcpy(diaa, Corta(pegolinha, ',', 1));
  410.                  strcpy(teste, AposCaracter(diaa, '.', 1));
  411.                  sprintf(diaa, "%s/Freedom.%s", database, teste);
  412.  
  413.                  sprintf(teste, "%s,%s,%s,%s,%s,%s,%s,%s\n", telefone, dataon, horaon, dataoff, horaoff, statusini, tempoon, connect);
  414.                  GravaLinha(diaa, teste, "a");
  415.                } else {
  416.                  fprintf(freedomout, "%s\n", linhaini);
  417.                  pegon = 0;
  418.                }
  419.              }
  420.              strcpy(pego, statusini);
  421.              strcpy(pegolinha, linhaini);
  422.  
  423.              linhaini[0] = '\0'; teste[0] = '\0'; x = 0;
  424.              if (pegon == 0)
  425.                pegon = 1;
  426.              else
  427.                pegon = 0;
  428.            }
  429.            else
  430.            {
  431.              if(strcmp(statusini, "Rec"))
  432.                erro++;
  433.              linhaini[0] = '\0'; teste[0] = '\0'; x = 0;
  434.            }
  435.          }
  436.       }
  437.       fclose(entrada);
  438.       fclose(freedomout);
  439.    }
  440.    /* ADICIONA AS ROTINAS DE INPUT NA BASE DO FREEDOM */
  441.    sprintf(teste, "%s/Freedom.Input", database);
  442.    if(ExisteArquivo(teste))
  443.      ConverteParaFreedom(teste);
  444.    set(App->EspereGerando,MUIA_Window_Open,FALSE);
  445.  
  446.    /* MIAMI LOG FILE CORRUPT (ONLY ACTIVE, PASSIVE...) */
  447.    if(erro > 0)
  448.    {
  449.      sprintf(teste, "%s%d", TMsg(App->Msg23), erro);
  450.      MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg18), teste);
  451.    } else {
  452.      /* ROTINA QUE MOSTRA O DISPLAY DA GERACAO */
  453.      get(App->LabelVisualGeneration, MUIA_Selected, &warning);
  454.      if(warning == 1)
  455.        MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg18), TMsg(App->Msg19));
  456.    }
  457.    return NULL;
  458. }
  459.  
  460. APTR PreparaEsseMes( struct Hook *a0, APTR a2, APTR a1 )
  461. {
  462.   /* ROTINA QUE PREPARA O ARQUIVO DE ESTATISTICAS COM SOMENTE
  463.      INFORMACOES DO MES CORRENTE */
  464.   char *horainicio, *horafim, *dia, ano[5], teste[256], teste2[256],
  465.        data1[256], data2[256], *database, freein[256],
  466.        freeout[256];
  467.   int x = 0;
  468.   long retorno = 0;
  469.  
  470.   /* TESTA SE O DIRETORIO DA BASE DE DADOS EXISTE */
  471.   get(App->DataBaseName, MUIA_String_Contents, &database);
  472.   if(!ExisteDiretorio(database))
  473.   {
  474.      MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg18), TMsg(App->Msg17));
  475.      return NULL;
  476.   }
  477.   /* CARREGA INFORMACOES DO PROVIDER SETS */
  478.   get(App->PrefsFreeHInicio, MUIA_String_Contents, &horainicio);
  479.   get(App->PrefsFreeHFim, MUIA_String_Contents, &horafim);
  480.   get(App->PrefsDiaInicial, MUIA_String_Contents, &dia);
  481.   get(App->ProviderRetornaMes, MUIA_Selected, &retorno);
  482.  
  483.   LimpaJanelaDesseMes();
  484.   set(App->JanelaGeracaoQuery, MUIA_Window_Open, TRUE);
  485.   set(App->GaugeQuery, MUIA_Gauge_Current, 5);
  486.   set(App->GaugeQuery, MUIA_Gauge_InfoText, TMsg(App->Msg26));
  487.  
  488.   strcpy(teste, DataHora(1));
  489.   strcpy(ano, Corta(teste, '.', 1));
  490.  
  491.   /* CARREGA VARIAVEIS DE PARA LEITURA DOS ARQUIVOS */
  492.   sprintf(freein, "%s/Freedom.%s", database, teste);
  493.   sprintf(freeout, "%s/Freedom.Out", database);
  494.  
  495.   /* TESTA SE CONFIGURACAO DE FREE HOURS E DAY INITIAL SAO VALIDAS */
  496.   if( ((!(strcmp(horainicio, "")) && !(strcmp(horafim, ""))) ||
  497.        (!(strcmp(horainicio, "00:00:00")) && !(strcmp(horafim, "00:00:00")))) && (atoi(dia) <= 1) )
  498.   {
  499.     FiltraCampoParaArquivoFREE(teste, freein, "t:freedom.intmp", ',', 1, '.');
  500.     FiltraCampoParaArquivoFREE(teste, freeout, "t:freedom.outtmp", ',', 1, '.');
  501.   }
  502.   else
  503.   {
  504.     /* ACERTA DAY INIT NOVO */
  505.     strcpy(teste, DataHora(1));
  506.     sprintf(data1, "%s.%s", dia, teste);
  507.     x = atoi(dia);  
  508.     x--;
  509.     if(x < 1)
  510.       x = 31;
  511.     sprintf(data2, "%d.%s", x, teste);
  512.     strcpy(data2, SomaDiminuiMes(data2, 1));
  513.  
  514.     /* ROTINA QUE RETORNA UM MES NA CONSULTA CASO A OPCAO ESTEJA ON */
  515.     if(retorno == 1)
  516.     {
  517.       strcpy(data1, SomaDiminuiMes(data1, -1));
  518.       strcpy(data2, SomaDiminuiMes(data2, -1));
  519.  
  520.       sprintf(teste2, "%s/Freedom.%s", database, AposCaracter(data1, '.', 1));
  521.       CopiaArquivo(teste2, "t:Freedom.In");
  522.       sprintf(teste2, "%s/Freedom.%s", database, AposCaracter(data2, '.', 1));
  523.       InsereArquivo(teste2, "t:Freedom.In");
  524.     }
  525.     else
  526.       CopiaArquivo(freein, "t:Freedom.In");
  527.  
  528.     SelecionaIntervaloCampo("T:Freedom.In", "T:Freedom.InTmp", "Ram:Freedom.Temp", data1, data2, horainicio, horafim);
  529.     remove("t:Freedom.In");
  530.     SelecionaIntervaloCampo(freeout, "T:Freedom.OutTmp", "Ram:Freedom.Temp", data1, data2, horainicio, horafim);
  531.   }
  532.   set(App->GaugeQuery, MUIA_Gauge_Current, 25);
  533.   /* CRIA ARQUIVO COM A DESCRICAO DA CONSULTA */
  534.   sprintf(teste, "%s %s", DescricaoMesFREE(atoi(Corta(teste, '.', 0)), 1), ano);
  535.   GravaRegistroDB("t:Freedom.Date", teste, "date", "w");
  536.   SemanaCount("t:Freedom.InTmp");
  537.   set(App->GaugeQuery, MUIA_Gauge_Current, 50);
  538.   return NULL;
  539. }
  540.  
  541. APTR CarregaEsseMes( struct Hook *a0, APTR a2, APTR a1 )
  542. {
  543.   /* ROTINA QUE CARREFA AS INFORMACOES DO ARQUIVO PREPARADO PARA 
  544.      A TELA INFORMACOES DO MES CORRENTE */
  545.   char teste[256], teste2[256], horason[30], mediafinal[30], *unit,
  546.        media[30], exc[256], maior[256], menor[256], data[30], *limit,
  547.        firstcall[30], lastcall[30], ultima[60], d1[256], d2[256],
  548.        days[256], cost[30], *moedac, *precision, senha1[256], 
  549.        senha2[256], teste3[256], a, status[30], dia[20], sem[256],
  550.        login[20], online[20], fone[30], htmlfile[256],
  551.        *regemail, *regnumber, *regname, *regorg, *regcountry,
  552.        senhatmp[256], *regnumber2, *htmldirectory, *browser;
  553.   int  totcal = 0, totout = 0, queda = 0, logoutgood = 0, excc = 0,
  554.        diferenca = 0, registro = 0, htm = 1, x = 0, gerahtml = 0,
  555.        salvahtml = 0, checkglobal = 0, global = 0;
  556.   long moeda = 0;
  557.   FILE *html, *entrada;
  558.  
  559.   LimpaJanelaDesseMes();
  560.  
  561.   totcal = LinhasArquivo("t:Freedom.inTmp");
  562.   if(totcal <= 0)
  563.   {
  564.     remove("t:freedom.intmp");
  565.     remove("t:freedom.outtmp");
  566.     remove("t:freedom.date");
  567.     set(App->JanelaGeracaoQuery, MUIA_Window_Open, FALSE);
  568.     set(App->JanelaDesseMes, MUIA_Window_Open, FALSE);
  569.     /* NO CONNECTIONS REGISTERED ABOUT THIS DATE */
  570.     MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg18), TMsg(App->Msg24));
  571.     return NULL;
  572.   }
  573.   
  574.   /* LE INFORMACOES SOBRE O HTML */
  575.   get(App->HtmlName, MUIA_String_Contents, &htmldirectory);
  576.   get(App->Browser, MUIA_String_Contents, &browser);
  577.   get(App->HtmlCheck, MUIA_Selected, &gerahtml);
  578.   get(App->CheckReports, MUIA_Selected, &salvahtml);
  579.   get(App->CheckGlobalHtml, MUIA_Selected, &checkglobal);
  580.  
  581.   /* ROTINA QUE TESTA O TIPO DE REGISTRO */
  582.   get(App->RegisterName, MUIA_String_Contents, ®name);
  583.   get(App->RegisterOrganization, MUIA_String_Contents, ®org);
  584.   get(App->RegisterEmail, MUIA_String_Contents, ®email);
  585.   get(App->RegisterCountry, MUIA_String_Contents, ®country);
  586.   get(App->RegisterKeyReal, MUIA_String_Contents, ®number2);
  587.   get(App->RegisterKey, MUIA_String_Contents, ®number);
  588.   strcpy(senha1, AsciiString(regnumber, 69));
  589.   strcpy(senha2, AsciiString(regnumber2, 96));
  590.   sprintf(senhatmp, "%s%s%s", regname, regemail, regcountry);
  591.   strcpy(senhatmp, CriptografiaSimples(senhatmp, 0));
  592.   if(!strcmp(senha1, senhatmp))
  593.     registro = 1;
  594.   if(!strcmp(senha1, senhatmp) && !strcmp(senha2, senhatmp))
  595.     registro = 2;
  596.   if(!strcmp(regnumber, ""))
  597.     registro = 0;
  598.  
  599.   /* PEGA INFORMACOES DA MOEDA CORRENTE */
  600.   get(App->ComboMoeda, MUIA_Cycle_Active, &moeda);
  601.   get(App->NomeMoeda, MUIA_String_Contents, &moedac);
  602.  
  603.   /* PEGA A PRECISAO DOS DISPLAYS DE VALORES */
  604.   get(App->ConfPrecision, MUIA_String_Contents, &precision);
  605.   /* PEGA UNIDADE DE DESCONTO */
  606.   get(App->ConfUnit, MUIA_String_Contents, &unit);
  607.  
  608.   set(App->GaugeQuery, MUIA_Gauge_Current, 55);
  609.   /* LOADING QUERY INFORMATION... */
  610.   set(App->GaugeQuery, MUIA_Gauge_InfoText, TMsg(App->Msg25));
  611.  
  612.   get(App->InputLimitTime, MUIA_String_Contents, &limit);
  613.   totout     = LinhasArquivo("t:Freedom.outTmp");
  614.   queda      = ContaVezesCampo("t:Freedom.inTmp", "Pas", ',', 5);
  615.   logoutgood = ContaVezesCampo("t:Freedom.inTmp", "Act", ',', 5);
  616.   strcpy(data, DataHora(1));
  617.   set(App->GaugeQuery, MUIA_Gauge_Current, 65);
  618.  
  619.   strcpy(media, MediaCampo("t:Freedom.inTmp", ',', 6));
  620.   strcpy(cost,  MediaCampo("t:Freedom.inTmp", ',', 8));
  621.   strcpy(mediafinal, SegundoHora(Corta(media, ':', 1)));
  622.   strcpy(horason,    SegundoHora(Corta(media, ':', 0)));
  623.  
  624.   sprintf(days, "%f", (atof(HoraSegundo(horason)) / 86400));
  625.   strcpy(ultima, PrimeiroUltimoCampo("t:freedom.inTmp", ',', 1, ':'));
  626.   /* ROTINA QUE ACERTA O CABECALHO DA GERACAO, O PERIODO */
  627.   strcpy(teste, LeRegistroDB("t:Freedom.Date", "date"));
  628.   strcpy(d1, Corta(ultima, ':', 0));
  629.   strcpy(d2, Corta(ultima, ':', 1));
  630.   sprintf(teste2, "\033c\0338%s [%s] %s", d1, teste, d2);
  631.  
  632.   /* TESTA SE DEVE SER GERADO O HTML PARA GLOBAL STATISTICS */
  633.   if(checkglobal == FALSE && gerahtml == TRUE)
  634.   {
  635.     if(!strcmp(teste, "Global Statistics")) {
  636.       set(App->BotaoHtml, MUIA_Disabled, TRUE);
  637.       global = 1;
  638.     } else {
  639.       set(App->BotaoHtml, MUIA_Disabled, FALSE);
  640.       global = 0; }
  641.   }
  642.  
  643.   set(App->LabelMesUso, MUIA_Text_Contents, teste2);
  644.   set(App->GaugeQuery, MUIA_Gauge_Current, 85);
  645.  
  646.  
  647.   /* INICIALIZA GERACAO DO HTML */
  648.   sprintf(htmlfile, "%s%s-%s.html", FiltraDir(htmldirectory, 1), d1, d2);
  649.   if(gerahtml == TRUE && global == 0)
  650.   {
  651.     if(!(html = fopen("T:Freedom.HTML", "w")))
  652.       htm = 1;
  653.     else
  654.       htm = 0;
  655.   }
  656.   if(htm == 0)
  657.   {
  658.     fprintf(html, "<HTML>\n<HEAD><TITLE>Freedom Statistics %s [%s] %s</TITLE></HEAD>\n<BODY BGCOLOR=#F8FCDC>\n",d1, teste, d2);
  659.     fprintf(html, "<H2>\n<CENTER><B>%s [%s] %s</B></CENTER>\n</H2>\n<BR><CENTER>\n<TABLE BORDER BGCOLOR=#FFFFFF>\n", d1, teste, d2);
  660.   }
  661.  
  662.   diferenca = DiferencaMes(d1, d2);
  663.   if(diferenca > 0)
  664.     sprintf(exc, "%d:00:00", (atoi(limit) * diferenca));
  665.   else
  666.     sprintf(exc, "%s:00:00", limit);
  667.  
  668.   strcpy(teste,  HoraSegundo(exc));
  669.   strcpy(teste2, HoraSegundo(horason));
  670.  
  671.   excc = (atoi(teste2) - atoi(teste));
  672.   if(excc <= 0)
  673.   { 
  674.     excc = excc * (-1);
  675.     sprintf(exc, "%d", excc);
  676.     strcpy(exc, SegundoHora(exc));
  677.     /* TIME REMAINING */
  678.     sprintf(teste, "%s \0338%s\033n", TMsg(App->Msg2), exc);
  679.     set(App->LabelMesExedentes, MUIA_Text_Contents, teste);
  680.   } else {
  681.     sprintf(exc, "%d", excc);
  682.     strcpy(exc, SegundoHora(exc));
  683.     /* TIME EXCEDED */
  684.     sprintf(teste, "%s \0338%s\033n", TMsg(App->Msg3), exc);
  685.     set(App->LabelMesExedentes, MUIA_Text_Contents, teste);
  686.   }
  687.   /* GRAVA O TIME REMAINING OU TIME EXCEDED EM HTML */
  688.   if(htm == 0)
  689.     fprintf(html, "<TR BGCOLOR=#00FFFF>\n<TD><B>%s</B></TD></TR>\n<TR><TD>%s</TD></TR>\n</TABLE>\n", TMsg(App->Msg2), exc);
  690.  
  691.   strcpy(maior, MaiorMenorCampo("t:Freedom.inTmp", ',', 6, 1));
  692.   strcpy(menor, MaiorMenorCampo("t:Freedom.inTmp", ',', 6, 0));
  693.   set(App->GaugeQuery, MUIA_Gauge_Current, 95);
  694.  
  695.   /* GRAVA CABECALHO DO COST ONLINE, AVERAGE, TOTAL */
  696.   if(htm == 0)
  697.     fprintf(html, "<TABLE BORDER BGCOLOR=#FFFFFF>\n<TR BGCOLOR=#00FFFF><TD><B>%s</B></TD>\n<TD><B>%s</B></TD>\n<TD><B>%s</B></TD></TR>\n", TMsg(App->Msg75), TMsg(App->Msg76), TMsg(App->Msg1));
  698.  
  699.   /* COST ONLINE */
  700.   strcpy(teste2, Corta(cost, ':', 0));
  701.   sprintf(teste2, "%f", (atof(teste2) - atof(unit)));
  702.   if(moeda == 0)
  703.   {
  704.     sprintf(teste, "%s \033b%s%s\033n", TMsg(App->Msg75), moedac, CasasAposCaracter(teste2, '.', atoi(precision)));
  705.     if(htm == 0)
  706.       fprintf(html, "<TR><TD>%s%s</TD>\n", moedac, CasasAposCaracter(teste2, '.', atoi(precision)));
  707.   } else {
  708.     sprintf(teste, "%s \033b%s%s\033n", TMsg(App->Msg75), CasasAposCaracter(teste2, '.', atoi(precision)), moedac);
  709.     if(htm == 0)
  710.       fprintf(html, "<TR><TD>%s%s</TD>\n", CasasAposCaracter(teste2, '.', atoi(precision)), moedac);
  711.   }
  712.   if(registro < 2)
  713.     sprintf(teste, "%s \033bREALREG\033n", TMsg(App->Msg75));
  714.   set(App->LabelCost, MUIA_Text_Contents, teste);
  715.  
  716.   /* AVERAGE COST */
  717.   if(moeda == 0)
  718.   {
  719.     sprintf(teste, "%s \033b%s%s\033n", TMsg(App->Msg76), moedac, CasasAposCaracter(Corta(cost, ':', 1), '.', atoi(precision)));
  720.     if(htm == 0)
  721.       fprintf(html, "<TD>%s%s</TD>\n", moedac, CasasAposCaracter(Corta(cost, ':', 1), '.', atoi(precision)));
  722.   } else {
  723.     sprintf(teste, "%s \033b%s%s\033n", TMsg(App->Msg76), CasasAposCaracter(Corta(cost, ':', 1), '.', atoi(precision)), moedac);
  724.     if(htm == 0)
  725.       fprintf(html, "<TD>%s%s</TD>\n", CasasAposCaracter(Corta(cost, ':', 1), '.', atoi(precision)), moedac);
  726.   }
  727.   if(registro < 2)
  728.     sprintf(teste, "%s \033bREALREG\033n", TMsg(App->Msg76));
  729.   set(App->LabelCostAverage, MUIA_Text_Contents, teste);
  730.  
  731.   /* TOTAL CALLS */
  732.   sprintf(teste, "%s \033b%d\033n", TMsg(App->Msg1), totcal);
  733.   if(htm == 0)
  734.     fprintf(html, "<TD>%d</TD></TR>\n</TABLE>\n", totcal);
  735.  
  736.   /* GRAVA CABECALHO DAS IRREGULAR, REGULAR E SHUTDOWN */
  737.   if(htm == 0)
  738.     fprintf(html, "<TABLE BORDER BGCOLOR=#FFFFFF>\n<TR BGCOLOR=#00FFFF><TD><B>%s</B></TD>\n<TD><B>%s</B></TD>\n<TD><B>%s</B></TD>\n</TR>\n", TMsg(App->Msg4), TMsg(App->Msg5), TMsg(App->Msg6));
  739.  
  740.   set(App->LabelMesNumero, MUIA_Text_Contents, teste);
  741.   /* IRREGULAR LOGOUTS */
  742.   sprintf(teste, "%s \033b%d\033n", TMsg(App->Msg4), queda);
  743.   set(App->NrQuedaLinhaMes, MUIA_Text_Contents, teste);
  744.   if(htm == 0)
  745.     fprintf(html, "<TR>\n<TD>%d</TD>\n", queda);
  746.  
  747.   /* REGULAR LOGOUTS */
  748.   sprintf(teste, "%s \033b%d\033n", TMsg(App->Msg5), logoutgood);
  749.   set(App->NrLogoutGoodMes, MUIA_Text_Contents, teste);
  750.   if(htm == 0)
  751.     fprintf(html, "<TD>%d</TD>\n", logoutgood);
  752.  
  753.   /* SHUTDOWN ONLINE */
  754.   sprintf(teste, "%s \033b%d\033n", TMsg(App->Msg6), totout);
  755.   set(App->NrDownResetMes, MUIA_Text_Contents, teste);
  756.   if(htm == 0)
  757.     fprintf(html, "<TD>%d</TD></TR>\n</TABLE>\n", totout);
  758.  
  759.   /* GRAVA CABECALHO TOTAL ONLINE, DAYS, AVERAGE ONLINE */
  760.   if(htm == 0)
  761.     fprintf(html, "<TABLE BORDER BGCOLOR=#FFFFFF>\n<TR BGCOLOR=#5F9F9F><TD><B>%s</B></TD>\n<TD><B>%s</B></TD>\n<TD><B>%s</B></TD>\n</TR>\n", TMsg(App->Msg7), TMsg(App->Msg95), TMsg(App->Msg9));
  762.  
  763.   /* TOTAL ONLINE & DAYS */
  764.   sprintf(teste, "%s \0338%s\033n (%s %s)", TMsg(App->Msg7), horason, CasasAposCaracter(days, '.', 1), TMsg(App->Msg8));
  765.   set(App->LabelMesUsadas, MUIA_Text_Contents, teste);
  766.   if(htm == 0)
  767.     fprintf(html, "<TD>%s</TD>\n<TD>%s</TD>\n", horason, CasasAposCaracter(days, '.', 1));
  768.  
  769.   /* AVERAGE ONLINE */
  770.   sprintf(teste, "%s \033b%s\033n", TMsg(App->Msg9), mediafinal);
  771.   set(App->LabelMesMedia, MUIA_Text_Contents, teste);
  772.   if(htm == 0)
  773.     fprintf(html, "<TD>%s</TD>\n</TR>\n</TABLE>\n", mediafinal);
  774.  
  775.   /* GRAVA CABECALHO LONGEST DATE, PHONE, CALL */
  776.   if(htm == 0)
  777.     fprintf(html, "<TABLE BORDER BGCOLOR=#FFFFFF>\n<TR BGCOLOR=#00FFFF><TD><B>%s</B></TD>\n<TD><B>%s</B></TD>\n<TD><B>%s</B></TD>\n</TR>\n", TMsg(App->Msg11), TMsg(App->Msg10), TMsg(App->Msg96));
  778.  
  779.   /* LONGEST DATE */
  780.   sprintf(teste, "%s \033b%s\033n", TMsg(App->Msg11), Corta(maior, ',', 1));
  781.   set(App->LabelMesData, MUIA_Text_Contents, teste);
  782.   if(htm == 0)
  783.     fprintf(html, "<TD>%s</TD>\n", Corta(maior, ',', 1));
  784.  
  785.   /* LONGEST CALL */
  786.   strcpy(teste2, Corta(maior, ',', 0));
  787.   sprintf(teste, "%s \0338%s\033n (%s)", TMsg(App->Msg10), SegundoHora(Corta(maior, ',', 6)), teste2);
  788.   set(App->LabelMesMaior, MUIA_Text_Contents, teste);
  789.   if(htm == 0)
  790.     fprintf(html, "<TD>%s</TD>\n<TD>%s</TD>\n</TR>\n</TABLE>\n", SegundoHora(Corta(maior, ',', 6)), teste2);
  791.  
  792.   /* GRAVA CABECALHO SHORTEST DATE, PHONE, CALL */
  793.   if(htm == 0)
  794.     fprintf(html, "<TABLE BORDER BGCOLOR=#FFFFFF>\n<TR BGCOLOR=#00FFFF><TD><B>%s</B></TD>\n<TD><B>%s</B></TD>\n<TD><B>%s</B></TD>\n</TR>\n", TMsg(App->Msg12), TMsg(App->Msg13), TMsg(App->Msg96));
  795.  
  796.   /* SHORTEST DATE */
  797.   sprintf(teste, "%s \033b%s\033n", TMsg(App->Msg12), Corta(menor, ',', 1));
  798.   set(App->LabelMesLow, MUIA_Text_Contents, teste);
  799.   if(htm == 0)
  800.     fprintf(html, "<TD>%s</TD>\n", Corta(menor, ',', 1));
  801.  
  802.   /* SHORTEST CALL */
  803.   strcpy(teste2, Corta(menor, ',', 0));
  804.   sprintf(teste, "%s \033b%s\033n (%s)", TMsg(App->Msg13), SegundoHora(Corta(menor, ',', 6)), teste2);
  805.   set(App->LabelMesMenor, MUIA_Text_Contents, teste);
  806.   if(htm == 0)
  807.     fprintf(html, "<TD>%s</TD>\n<TD>%s</TD>\n</TR>\n</TABLE>\n", SegundoHora(Corta(menor, ',', 6)), teste2);
  808.  
  809.   strcpy(teste2, PrimeiroUltimoCampo("t:Freedom.InTmp", ',', 6, '@'));
  810.   strcpy(teste, SegundoHora(Corta(teste2, '@', 1)));
  811.  
  812.   /* GRAVA CABECALHO FIRST CALL, LAST CALL */
  813.   if(htm == 0)
  814.     fprintf(html, "<TABLE BORDER BGCOLOR=#FFFFFF>\n<TR BGCOLOR=#00FFFF>\n<TD><B>%s</B></TD>\n<TD><B>%s</B></TD>\n</TR>\n", TMsg(App->Msg14), TMsg(App->Msg15));
  815.  
  816.   /* LAST CALL */
  817.   sprintf(lastcall, "%s \033b%s\033n", TMsg(App->Msg14), teste);
  818.   set(App->LabelUltimaLigacao, MUIA_Text_Contents, lastcall);
  819.   if(htm == 0)
  820.     fprintf(html, "<TD>%s</TD>\n", teste);
  821.   strcpy(teste, SegundoHora(Corta(teste2, '@', 0)));
  822.  
  823.   /* FIRST CALL */
  824.   sprintf(firstcall, "%s \033b%s\033n", TMsg(App->Msg15), teste);
  825.   set(App->LabelPrimeiraLigacao, MUIA_Text_Contents, firstcall);
  826.   if(htm == 0)
  827.     fprintf(html, "<TD>%s</TD>\n</TR>\n</TABLE>\n<BR><HR>\n", teste);
  828.   set(App->GaugeQuery, MUIA_Gauge_Current, 100);
  829.  
  830.   /* GERA HTML BASEADO NOS DADOS SEMANAIS */
  831.   if(htm == 0)
  832.   {
  833.     fprintf(html, "<H2><B>%s</B></H2>\n<BR>\n<TABLE BORDER BGCOLOR=#FFFFFF>\n<TR BGCOLOR=#00FFFF>\n<TD></TD>\n<TD><B>%s</B></TD>\n<TD><B>%s</B></TD>\n<TD><B>%</B></TD>\n<TD><B>%s</B></TD>\n</TR>\n", TMsg(App->Msg98), TMsg(App->Msg97), TMsg(App->Msg92), TMsg(App->Msg93));
  834.  
  835.     /* GRAVA SEGUNDA */
  836.     strcpy(teste, LeRegistroDB("T:Freedom.Week", "2"));
  837.     strcpy(teste2, CasasAposCaracter(Corta(teste, '@', 3), '.', atoi(precision)));
  838.     if(moeda == 0) { sprintf(teste3, "%s%s", moedac, teste2); } else { sprintf(teste3, "%s%s", teste2, moedac); }
  839.     if(registro < 2)
  840.       strcpy(teste3, "REALREG");
  841.     fprintf(html, "<TR>\n<TD><B>%s</B></TD>\n<TD>%s</TD>\n<TD>%s</TD>\n<TD>%s</TD>\n<TD><DIV ALIGN=RIGHT>%s</DIV></TD>\n", TMsg(App->MsgSegunda), Corta(teste, '@', 0), SegundoHora(Corta(teste, '@', 2)), CasasAposCaracter(Corta(teste, '@', 1), '.', 1), teste3);
  842.  
  843.     /* GRAVA TERCA */
  844.     strcpy(teste, LeRegistroDB("T:Freedom.Week", "3"));
  845.     strcpy(teste2, CasasAposCaracter(Corta(teste, '@', 3), '.', atoi(precision)));
  846.     if(moeda == 0) { sprintf(teste3, "%s%s", moedac, teste2); } else { sprintf(teste3, "%s%s", teste2, moedac); }
  847.     if(registro < 2)
  848.       strcpy(teste3, "REALREG");
  849.     fprintf(html, "<TR>\n<TD><B>%s</B></TD>\n<TD>%s</TD>\n<TD>%s</TD>\n<TD>%s</TD>\n<TD><DIV ALIGN=RIGHT>%s</DIV></TD>\n", TMsg(App->MsgTerca), Corta(teste, '@', 0), SegundoHora(Corta(teste, '@', 2)), CasasAposCaracter(Corta(teste, '@', 1), '.', 1), teste3);
  850.  
  851.  
  852.     /* GRAVA QUARTA */
  853.     strcpy(teste, LeRegistroDB("T:Freedom.Week", "4"));
  854.     strcpy(teste2, CasasAposCaracter(Corta(teste, '@', 3), '.', atoi(precision)));
  855.     if(moeda == 0) { sprintf(teste3, "%s%s", moedac, teste2); } else { sprintf(teste3, "%s%s", teste2, moedac); }
  856.     if(registro < 2)
  857.       strcpy(teste3, "REALREG");
  858.     fprintf(html, "<TR>\n<TD><B>%s</B></TD>\n<TD>%s</TD>\n<TD>%s</TD>\n<TD>%s</TD>\n<TD><DIV ALIGN=RIGHT>%s</DIV></TD>\n", TMsg(App->MsgQuarta), Corta(teste, '@', 0), SegundoHora(Corta(teste, '@', 2)), CasasAposCaracter(Corta(teste, '@', 1), '.', 1), teste3);
  859.  
  860.     /* GRAVA QUINTA */
  861.     strcpy(teste, LeRegistroDB("T:Freedom.Week", "5"));
  862.     strcpy(teste2, CasasAposCaracter(Corta(teste, '@', 3), '.', atoi(precision)));
  863.     if(moeda == 0) { sprintf(teste3, "%s%s", moedac, teste2); } else { sprintf(teste3, "%s%s", teste2, moedac); }
  864.     if(registro < 2)
  865.       strcpy(teste3, "REALREG");
  866.     fprintf(html, "<TR>\n<TD><B>%s</B></TD>\n<TD>%s</TD>\n<TD>%s</TD>\n<TD>%s</TD><TD><DIV ALIGN=RIGHT>%s</DIV></TD>\n", TMsg(App->MsgQuinta), Corta(teste, '@', 0), SegundoHora(Corta(teste, '@', 2)), CasasAposCaracter(Corta(teste, '@', 1), '.', 1), teste3);
  867.  
  868.     /* GRAVA SEXTA */
  869.     strcpy(teste, LeRegistroDB("T:Freedom.Week", "6"));
  870.     strcpy(teste2, CasasAposCaracter(Corta(teste, '@', 3), '.', atoi(precision)));
  871.     if(moeda == 0) { sprintf(teste3, "%s%s", moedac, teste2); } else { sprintf(teste3, "%s%s", teste2, moedac); }
  872.     if(registro < 2)
  873.       strcpy(teste3, "REALREG");
  874.     fprintf(html, "<TR>\n<TD><B>%s</B></TD>\n<TD>%s</TD>\n<TD>%s</TD>\n<TD>%s</TD>\n<TD><DIV ALIGN=RIGHT>%s</DIV></TD>\n", TMsg(App->MsgSexta), Corta(teste, '@', 0), SegundoHora(Corta(teste, '@', 2)), CasasAposCaracter(Corta(teste, '@', 1), '.', 1), teste3);
  875.  
  876.     /* GRAVA SABADO */
  877.     strcpy(teste, LeRegistroDB("T:Freedom.Week", "0"));
  878.     strcpy(teste2, CasasAposCaracter(Corta(teste, '@', 3), '.', atoi(precision)));
  879.     if(moeda == 0) { sprintf(teste3, "%s%s", moedac, teste2); } else { sprintf(teste3, "%s%s", teste2, moedac); }
  880.     if(registro < 2)
  881.       strcpy(teste3, "REALREG");
  882.     fprintf(html, "<TR>\n<TD><B>%s</B></TD>\n<TD>%s</TD>\n<TD>%s</TD>\n<TD>%s</TD>\n<TD><DIV ALIGN=RIGHT>%s</DIV></TD>\n", TMsg(App->MsgSabado), Corta(teste, '@', 0), SegundoHora(Corta(teste, '@', 2)), CasasAposCaracter(Corta(teste, '@', 1), '.', 1), teste3);
  883.  
  884.     /* GRAVA DOMINGO */
  885.     strcpy(teste, LeRegistroDB("T:Freedom.Week", "1"));
  886.     strcpy(teste2, CasasAposCaracter(Corta(teste, '@', 3), '.', atoi(precision)));
  887.     if(moeda == 0) { sprintf(teste3, "%s%s", moedac, teste2); } else { sprintf(teste3, "%s%s", teste2, moedac); }
  888.     if(registro < 2)
  889.       strcpy(teste3, "REALREG");
  890.     fprintf(html, "<TR>\n<TD><B>%s</B></TD>\n<TD>%s</TD>\n<TD>%s</TD>\n<TD>%s</TD>\n<TD><DIV ALIGN=RIGHT>%s</DIV></TD>\n", TMsg(App->MsgDomingo), Corta(teste, '@', 0), SegundoHora(Corta(teste, '@', 2)), CasasAposCaracter(Corta(teste, '@', 1), '.', 1), teste3);
  891.  
  892.     /* GRAVA TOTAL */
  893.     strcpy(teste, LeRegistroDB("T:Freedom.Week", "7"));
  894.     strcpy(teste2, CasasAposCaracter(Corta(teste, '@', 2), '.', atoi(precision)));
  895.     if(moeda == 0) { sprintf(teste3, "%s%s", moedac, teste2); } else { sprintf(teste3, "%s%s", teste2, moedac); }
  896.     if(registro < 2)
  897.       strcpy(teste3, "REALREG");
  898.     fprintf(html, "<TR>\n<TD></TD>\n<TD><B>%s</B></TD>\n<TD><B>%s</B></TD>\n<TD><B>100</B></TD>\n<TD><B><DIV ALIGN=RIGHT>%s</DIV></B></TD>\n</TR>\n</TABLE>\n", Corta(teste, '@', 0), SegundoHora(Corta(teste, '@', 1)), teste3);
  899.   }
  900.   /* GERA HTML BASEADO NOS CPS */
  901.   if(htm == 0)
  902.   {
  903.     fprintf(html, "<BR><HR>\n<B><H2>%s</B></H2><BR>\n<TABLE BORDER BGCOLOR=#FFFFFF>\n<TR BGCOLOR=#00FFFF>\n<TD></TD>\n<TD><B>%s</B></TD>\n</TR>\n", TMsg(App->Msg99), TMsg(App->Msg97));
  904.  
  905.     /* 300 CPS */
  906.     x = atoi(LeRegistroDB("T:Freedom.Rates", "300"));
  907.     if(x > 0)
  908.       fprintf(html, "<TR>\n<TD><B>300</B></TD>\n<TD><DIV ALIGN=RIGHT>%d</DIV></TD>\n</TR>\n", x);
  909.  
  910.     /* 2400 CPS */
  911.     x = atoi(LeRegistroDB("T:Freedom.Rates", "2400"));
  912.     if(x > 0)
  913.       fprintf(html, "<TR>\n<TD><B>2400</B></TD>\n<TD><DIV ALIGN=RIGHT>%d</DIV></TD>\n</TR>\n", x);
  914.  
  915.     /* 9600 CPS */
  916.     x = atoi(LeRegistroDB("T:Freedom.Rates", "9600"));
  917.     if(x > 0)
  918.       fprintf(html, "<TR>\n<TD><B>9600</B></TD>\n<TD><DIV ALIGN=RIGHT>%d</DIV></TD>\n</TR>\n", x);
  919.  
  920.     /* 14400 CPS */
  921.     x = atoi(LeRegistroDB("T:Freedom.Rates", "14400"));
  922.     if(x > 0)
  923.       fprintf(html, "<TR>\n<TD><B>14400</B></TD>\n<TD><DIV ALIGN=RIGHT>%d</DIV></TD>\n</TR>\n", x);
  924.  
  925.     /* 16800 CPS */
  926.     x = atoi(LeRegistroDB("T:Freedom.Rates", "16800"));
  927.     if(x > 0)
  928.       fprintf(html, "<TR>\n<TD><B>16800</B></TD>\n<TD><DIV ALIGN=RIGHT>%d</DIV></TD>\n</TR>\n", x);
  929.  
  930.     /* 19200 CPS */
  931.     x = atoi(LeRegistroDB("T:Freedom.Rates", "19200"));
  932.     if(x > 0)
  933.       fprintf(html, "<TR>\n<TD><B>19200</B></TD>\n<TD><DIV ALIGN=RIGHT>%d</DIV></TD>\n</TR>\n", x);
  934.  
  935.     /* 21600 CPS */
  936.     x = atoi(LeRegistroDB("T:Freedom.Rates", "21600"));
  937.     if(x > 0)
  938.       fprintf(html, "<TR>\n<TD><B>21600</B></TD>\n<TD><DIV ALIGN=RIGHT>%d</DIV></TD>\n</TR>\n", x);
  939.  
  940.     /* 24000 CPS */
  941.     x = atoi(LeRegistroDB("T:Freedom.Rates", "24000"));
  942.     if(x > 0)
  943.       fprintf(html, "<TR>\n<TD><B>24000</B></TD>\n<TD><DIV ALIGN=RIGHT>%d</DIV></TD>\n</TR>\n", x);
  944.  
  945.     /* 26400 CPS */
  946.     x = atoi(LeRegistroDB("T:Freedom.Rates", "26400"));
  947.     if(x > 0)
  948.       fprintf(html, "<TR>\n<TD><B>26400</B></TD>\n<TD><DIV ALIGN=RIGHT>%d</DIV></TD>\n</TR>\n", x);
  949.  
  950.     /* 28800 CPS */
  951.     x = atoi(LeRegistroDB("T:Freedom.Rates", "28800"));
  952.     if(x > 0)
  953.       fprintf(html, "<TR>\n<TD><B>28800</B></TD>\n<TD><DIV ALIGN=RIGHT>%d</DIV></TD>\n</TR>\n", x);
  954.  
  955.     /* 30666 CPS */
  956.     x = atoi(LeRegistroDB("T:Freedom.Rates", "30666"));
  957.     if(x > 0)
  958.       fprintf(html, "<TR>\n<TD><B>30666</B></TD>\n<TD><DIV ALIGN=RIGHT>%d</DIV></TD>\n</TR>\n", x);
  959.  
  960.     /* 31200 CPS */
  961.     x = atoi(LeRegistroDB("T:Freedom.Rates", "31200"));
  962.     if(x > 0)
  963.       fprintf(html, "<TR>\n<TD><B>31200</B></TD>\n<TD><DIV ALIGN=RIGHT>%d</DIV></TD>\n</TR>\n", x);
  964.  
  965.     /* 31250 CPS */
  966.     x = atoi(LeRegistroDB("T:Freedom.Rates", "31250"));
  967.     if(x > 0)
  968.       fprintf(html, "<TR>\n<TD><B>31250</B></TD>\n<TD><DIV ALIGN=RIGHT>%d</DIV></TD>\n</TR>\n", x);
  969.  
  970.     /* 32000 CPS */
  971.     x = atoi(LeRegistroDB("T:Freedom.Rates", "32000"));
  972.     if(x > 0)
  973.       fprintf(html, "<TR>\n<TD><B>32000</B></TD>\n<TD><DIV ALIGN=RIGHT>%d</DIV></TD>\n</TR>\n", x);
  974.  
  975.     /* 33333 CPS */
  976.     x = atoi(LeRegistroDB("T:Freedom.Rates", "33333"));
  977.     if(x > 0)
  978.       fprintf(html, "<TR>\n<TD><B>33333</B></TD>\n<TD><DIV ALIGN=RIGHT>%d</DIV></TD>\n</TR>\n", x);
  979.  
  980.     /* 34666 CPS */
  981.     x = atoi(LeRegistroDB("T:Freedom.Rates", "34666"));
  982.     if(x > 0)
  983.       fprintf(html, "<TR>\n<TD><B>34666</B></TD>\n<TD><DIV ALIGN=RIGHT>%d</DIV></TD>\n</TR>\n", x);
  984.  
  985.     /* 33600 CPS */
  986.     x = atoi(LeRegistroDB("T:Freedom.Rates", "33600"));
  987.     if(x > 0)
  988.       fprintf(html, "<TR>\n<TD><B>33600</B></TD>\n<TD><DIV ALIGN=RIGHT>%d</DIV></TD>\n</TR>\n", x);
  989.  
  990.     /* 38400 CPS */
  991.     x = atoi(LeRegistroDB("T:Freedom.Rates", "38400"));
  992.     if(x > 0)
  993.       fprintf(html, "<TR>\n<TD><B>38400</B></TD>\n<TD><DIV ALIGN=RIGHT>%d</DIV></TD>\n</TR>\n", x);
  994.  
  995.     /* 45333 CPS */
  996.     x = atoi(LeRegistroDB("T:Freedom.Rates", "45333"));
  997.     if(x > 0)
  998.       fprintf(html, "<TR>\n<TD><B>45333</B></TD>\n<TD><DIV ALIGN=RIGHT>%d</DIV></TD>\n</TR>\n", x);
  999.  
  1000.     /* 46666 CPS */
  1001.     x = atoi(LeRegistroDB("T:Freedom.Rates", "46666"));
  1002.     if(x > 0)
  1003.       fprintf(html, "<TR>\n<TD><B>46666</B></TD>\n<TD><DIV ALIGN=RIGHT>%d</DIV></TD>\n</TR>\n", x);
  1004.  
  1005.     /* 48000 CPS */
  1006.     x = atoi(LeRegistroDB("T:Freedom.Rates", "48000"));
  1007.     if(x > 0)
  1008.       fprintf(html, "<TR>\n<TD><B>48000</B></TD>\n<TD><DIV ALIGN=RIGHT>%d</DIV></TD>\n</TR>\n", x);
  1009.  
  1010.     /* 49333 CPS */
  1011.     x = atoi(LeRegistroDB("T:Freedom.Rates", "49333"));
  1012.     if(x > 0)
  1013.       fprintf(html, "<TR>\n<TD><B>49333</B></TD>\n<TD><DIV ALIGN=RIGHT>%d</DIV></TD>\n</TR>\n", x);
  1014.  
  1015.     /* 50666 CPS */
  1016.     x = atoi(LeRegistroDB("T:Freedom.Rates", "50666"));
  1017.     if(x > 0)
  1018.       fprintf(html, "<TR>\n<TD><B>50666</B></TD>\n<TD><DIV ALIGN=RIGHT>%d</DIV></TD>\n</TR>\n", x);
  1019.  
  1020.     /* 52000 CPS */
  1021.     x = atoi(LeRegistroDB("T:Freedom.Rates", "52000"));
  1022.     if(x > 0)
  1023.       fprintf(html, "<TR>\n<TD><B>52000</B></TD>\n<TD><DIV ALIGN=RIGHT>%d</DIV></TD>\n</TR>\n", x);
  1024.  
  1025.     /* 53333 CPS */
  1026.     x = atoi(LeRegistroDB("T:Freedom.Rates", "53333"));
  1027.     if(x > 0)
  1028.       fprintf(html, "<TR>\n<TD><B>53333</B></TD>\n<TD><DIV ALIGN=RIGHT>%d</DIV></TD>\n</TR>\n", x);
  1029.  
  1030.     /* 54666 CPS */
  1031.     x = atoi(LeRegistroDB("T:Freedom.Rates", "54666"));
  1032.     if(x > 0)
  1033.       fprintf(html, "<TR>\n<TD><B>54666</B></TD>\n<TD><DIV ALIGN=RIGHT>%d</DIV></TD>\n</TR>\n", x);
  1034.  
  1035.     /* 57600 CPS */
  1036.     x = atoi(LeRegistroDB("T:Freedom.Rates", "57600"));
  1037.     if(x > 0)
  1038.       fprintf(html, "<TR>\n<TD><B>57600</B></TD>\n<TD><DIV ALIGN=RIGHT>%d</DIV></TD>\n</TR>\n", x);
  1039.  
  1040.     /* 64000 CPS */
  1041.     x = atoi(LeRegistroDB("T:Freedom.Rates", "64000"));
  1042.     if(x > 0)
  1043.       fprintf(html, "<TR>\n<TD><B>64000</B></TD>\n<TD><DIV ALIGN=RIGHT>%d</DIV></TD>\n</TR>\n", x);
  1044.  
  1045.     /* 76800 CPS */
  1046.     x = atoi(LeRegistroDB("T:Freedom.Rates", "76800"));
  1047.     if(x > 0)
  1048.       fprintf(html, "<TR>\n<TD><B>76800</B></TD>\n<TD><DIV ALIGN=RIGHT>%d</DIV></TD>\n</TR>\n", x);
  1049.  
  1050.     /* 115200 CPS */
  1051.     x = atoi(LeRegistroDB("T:Freedom.Rates", "115200"));
  1052.     if(x > 0)
  1053.       fprintf(html, "<TR>\n<TD><B>115200</B></TD>\n<TD><DIV ALIGN=RIGHT>%d</DIV></TD>\n</TR>\n", x);
  1054.  
  1055.     /* 230400 CPS */
  1056.     x = atoi(LeRegistroDB("T:Freedom.Rates", "230400"));
  1057.     if(x > 0)
  1058.       fprintf(html, "<TR>\n<TD><B>230400</B></TD>\n<TD><DIV ALIGN=RIGHT>%d</DIV></TD>\n</TR>\n", x);
  1059.  
  1060.     fprintf(html, "</TABLE>\n");
  1061.   }
  1062.  
  1063.   /* GERA HTML DAS LIGACOES ANALITICAMENTE */
  1064.   if(htm == 0)
  1065.   {
  1066.     if(entrada = fopen("T:Freedom.InTmp", "r"))
  1067.     {
  1068.       fprintf(html, "<BR><HR>\n<B><H2>%s</B></H2><BR>\n<TABLE BORDER BGCOLOR=#FFFFFF>\n<TR BGCOLOR=#00FFFF>\n<TD><B>%s</B></TD>\n<TD><B>%s</B></TD>\n<TD><B>%s</B></TD>\n<TD><B>%s</B></TD>\n<TD><B>%s</B></TD>\n<TD><B>%s</B></TD></TR>\n", TMsg(App->Msg104), TMsg(App->Msg100), TMsg(App->Msg101), TMsg(App->Msg92), TMsg(App->Msg102), TMsg(App->Msg93), TMsg(App->Msg103));
  1069.       x = 0;
  1070.       while(a = getc(entrada), ! feof(entrada))
  1071.       {
  1072.         teste[x++] = a;
  1073.         if(a == '\n')
  1074.         {
  1075.           teste[--x] = '\0';
  1076.  
  1077.           if(!(strcmp(Corta(teste, ',', 5), "Act"))) {
  1078.             /* REGULAR */
  1079.             strcpy(status, TMsg(App->Msg54));
  1080.           } else {
  1081.             /* IRREGULAR */
  1082.             strcpy(status, TMsg(App->Msg55)); }
  1083.  
  1084.           strcpy(dia,    Corta(teste, ',', 1));
  1085.           strcpy(sem,    DiaSemanaFREE(dia, 1));
  1086.           strcpy(login,  Corta(teste, ',', 2));
  1087.           strcpy(online, Corta(teste, ',', 6));
  1088.           strcpy(fone,   Corta(teste, ',', 0));
  1089.  
  1090.           /* LE O VALOR DA LIGACAO */
  1091.           strcpy(cost, Corta(teste, ',', 8));
  1092.           strcpy(teste2, CasasAposCaracter(cost, '.', atoi(precision)));
  1093.           if(moeda == 0)
  1094.             sprintf(cost, "%s%s", moedac, teste2);
  1095.           else
  1096.             sprintf(cost, "%s%s", teste2, moedac);
  1097.           if(registro < 2)
  1098.             strcpy(cost, "REALREG");
  1099.  
  1100.           strcpy(login,  SegundoHora(login));
  1101.           strcpy(online, SegundoHora(online));
  1102.  
  1103.           /* GRAVA CONECCOES NO HTML */
  1104.           fprintf(html, "<TR>\n<TD><B>%s</B></TD><TD>%s</TD><TD><B>%s</B></TD><TD>%s</TD><TD><B>%s</B></TD><TD>%s (%s)</TD>\n</TR>\n", dia, login, online, fone, cost, status, sem);
  1105.           teste[0] = '\0'; x = 0;
  1106.         }
  1107.       }
  1108.       fclose(entrada);
  1109.     }
  1110.   }
  1111.  
  1112.   /* FINALIZA O HTML */
  1113.   if(htm == 0)
  1114.   {
  1115.     fprintf(html, "</TABLE>\n</BODY>\n</HTML>\n");
  1116.     fclose(html);
  1117.  
  1118.     /* VERIFICA OPCAO DE SALVAR HTML NA BASE DE DADOS */
  1119.     if(salvahtml == TRUE)
  1120.       CopiaArquivo("T:Freedom.HTML", htmlfile);
  1121.   }
  1122.   remove("t:freedom.outtmp");
  1123.  
  1124.   /* FECHA A JANELA DE DISPLAY DE GERACAO */
  1125.   set(App->JanelaGeracaoQuery, MUIA_Window_Open, FALSE);
  1126.   /* ABRE A JANELA COM AS ESTATISTICAS */
  1127.   set(App->JanelaDesseMes, MUIA_Window_Open, TRUE);
  1128.   return NULL;
  1129. }
  1130.  
  1131. APTR SalvaConfiguracao( struct Hook *a0, APTR a2, APTR a1 )
  1132. {
  1133.   /* ROTINA QUE SALVA A CONFIGURACAO DO FREEDOM CALL */
  1134.   char *path, *limit, *regname, *regcity, *unit,
  1135.        *regcountry, *regorganiz, *regemail, *regnumber, *regnumberreal,
  1136.        *freeinicio, *freefim, *diainicio, *database, *precision,
  1137.        *phoneignore, *categorydir, *categorydefault, *pricedefault,
  1138.        *providerbill, *extrahour, *excededtime, *excededyear,
  1139.        *htmlname, *browser;
  1140.   long warning = 0, startup = 0, phonecheck = 0, menu = 0,
  1141.        returnmonth = 0, htmlcheck = 0, checkreports = 0,
  1142.        checkglobalhtml = 0;
  1143.  
  1144.   FILE *saida;
  1145.   if(!(saida = fopen("Freedom:Freedom.Config", "w")))
  1146.   {
  1147.     fclose(saida);
  1148.     /* PROBLEMA NO ACESSO AO FREEDOM:FREEDOM.CONFIG */
  1149.     MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg18), TMsg(App->Msg31));
  1150.     return NULL;
  1151.   }
  1152.  
  1153.   get(App->RequestMiamiLog, MUIA_String_Contents, &path);
  1154.   get(App->InputLimitTime, MUIA_String_Contents, &limit);
  1155.   get(App->LabelVisualGeneration, MUIA_Selected, &warning);
  1156.   get(App->LabelGenerationStartup, MUIA_Selected, &startup);
  1157.   get(App->ProviderRetornaMes, MUIA_Selected, &returnmonth);
  1158.   get(App->RegisterName, MUIA_String_Contents, ®name);
  1159.   get(App->RegisterOrganization, MUIA_String_Contents, ®organiz);
  1160.   get(App->RegisterEmail, MUIA_String_Contents, ®email);
  1161.   get(App->RegisterKey, MUIA_String_Contents, ®number);
  1162.   get(App->RegisterKeyReal, MUIA_String_Contents, ®numberreal);
  1163.   get(App->RegisterCountry, MUIA_String_Contents, ®country);
  1164.   get(App->RegisterCity, MUIA_String_Contents, ®city);
  1165.   get(App->PrefsFreeHInicio, MUIA_String_Contents, &freeinicio);
  1166.   get(App->PrefsFreeHFim, MUIA_String_Contents, &freefim);
  1167.   get(App->PrefsDiaInicial, MUIA_String_Contents, &diainicio);
  1168.   get(App->DataBaseName, MUIA_String_Contents, &database);
  1169.   get(App->GrupoFoneInput, MUIA_String_Contents, &phoneignore);
  1170.   get(App->GrupoFoneInputCheck, MUIA_Selected, &phonecheck);
  1171.   get(App->PrefsComboMenu, MUIA_Cycle_Active, &menu);
  1172.   get(App->TextDefault, MUIA_Text_Contents, &categorydefault);
  1173.   get(App->CategValorDefault, MUIA_String_Contents, &pricedefault);
  1174.   get(App->CategDiretorio, MUIA_String_Contents, &categorydir);
  1175.   get(App->ConfPrecision, MUIA_String_Contents, &precision);
  1176.   get(App->HoraExtra, MUIA_String_Contents, &extrahour);
  1177.   get(App->ContaProvedor, MUIA_String_Contents, &providerbill);
  1178.   get(App->ConfUnit, MUIA_String_Contents, &unit);
  1179.   get(App->ExcededTime, MUIA_String_Contents, &excededtime);
  1180.   get(App->ExcededYear, MUIA_String_Contents, &excededyear);
  1181.   get(App->HtmlCheck, MUIA_Selected, &htmlcheck);
  1182.   get(App->HtmlName, MUIA_String_Contents, &htmlname);
  1183.   get(App->Browser, MUIA_String_Contents, &browser);
  1184.   get(App->CheckReports, MUIA_Selected, &checkreports);
  1185.   get(App->CheckGlobalHtml, MUIA_Selected, &checkglobalhtml);
  1186.  
  1187.   fprintf(saida, "**>path:%s\n", path);
  1188.   fprintf(saida, "**>limit:%s\n", limit);
  1189.   fprintf(saida, "**>warning:%d\n", warning);
  1190.   fprintf(saida, "**>startup:%d\n", startup);
  1191.   fprintf(saida, "**>regname:%s\n", regname);
  1192.   fprintf(saida, "**>regorganiz:%s\n", regorganiz);
  1193.   fprintf(saida, "**>regemail:%s\n", regemail);
  1194.   fprintf(saida, "**>regnumber:%s\n", regnumber);
  1195.   fprintf(saida, "**>regcountry:%s\n", regcountry);
  1196.   fprintf(saida, "**>regcity:%s\n", regcity);
  1197.   fprintf(saida, "**>freeinit:%s\n", freeinicio);
  1198.   fprintf(saida, "**>freeend:%s\n", freefim);
  1199.   fprintf(saida, "**>dayinit:%s\n", diainicio);
  1200.   fprintf(saida, "**>databasename:%s\n", database);
  1201.   fprintf(saida, "**>phoneignore:%s\n", phoneignore);
  1202.   fprintf(saida, "**>phonecheck:%d\n", phonecheck);
  1203.   fprintf(saida, "**>menu:%d\n", menu);
  1204.   fprintf(saida, "**>categorydefault:%s\n", categorydefault);
  1205.   fprintf(saida, "**>pricedefault:%s\n", pricedefault);
  1206.   fprintf(saida, "**>categorydir:%s\n", categorydir);
  1207.   fprintf(saida, "**>returnmonth:%d\n", returnmonth);
  1208.   fprintf(saida, "**>precision:%s\n", precision);
  1209.   fprintf(saida, "**>regnumberreal:%s\n", regnumberreal);
  1210.   fprintf(saida, "**>extrahour:%s\n", extrahour);
  1211.   fprintf(saida, "**>providerbill:%s\n", providerbill);
  1212.   fprintf(saida, "**>unitdiscount:%s\n", unit);
  1213.   fprintf(saida, "**>excededtime:%s\n", excededtime);
  1214.   fprintf(saida, "**>excededyear:%s\n", excededyear);
  1215.   fprintf(saida, "**>htmlcheck:%d\n", htmlcheck);
  1216.   fprintf(saida, "**>htmlname:%s\n", htmlname);
  1217.   fprintf(saida, "**>browser:%s\n", browser);
  1218.   fprintf(saida, "**>checkreports:%d\n", checkreports);
  1219.   fprintf(saida, "**>checkglobalhtml:%d\n", checkglobalhtml);
  1220.  
  1221.   fclose(saida);
  1222.   return NULL;
  1223. }
  1224.  
  1225. APTR CarregaConfiguracao( struct Hook *a0, APTR a2, APTR a1 )
  1226. {
  1227.   /* ROTINA DE CARREGAMENTO DA CONFIGURACAO, AS INFORMACOES SAO LIDAS
  1228.   DO FREEDOM.CONFIG E LARGADA NOS FORMS DE CONFIGURACAO DE ONDE SERAO
  1229.   LIDAS PELO PROGRAMA */
  1230.   char teste[256], *database, a, regnumberreal[500], unit[10],
  1231.        path[256], limit[10], warning[2], startup[2], regname[256],
  1232.        regorganiz[256], regemail[256], regnumber[500], regcountry[256],
  1233.        regcity[256], freeinit[15], freeend[15], dayinit[15],
  1234.        databasename[256], phoneignore[256], phonecheck[2], menu[2],
  1235.        categorydefault[256], pricedefault[10], categorydir[256],
  1236.        returnmonth[2], precision[10], extrahour[10], providerbill[10],
  1237.        excededtime[30], excededyear[30], htmlcheck[2], htmlname[256],
  1238.        browser[256], checkreports[2], checkglobalhtml[2];
  1239.  
  1240.   int x = 0, y = 0;
  1241.   FILE *entrada;
  1242.  
  1243.   /* ZERA VARIAVEIS */
  1244.   path[0]            = '\0';
  1245.   limit[0]           = '\0';
  1246.   warning[0]         = '\0';
  1247.   startup[0]         = '\0';
  1248.   regname[0]         = '\0';
  1249.   regorganiz[0]      = '\0';
  1250.   regemail[0]        = '\0';
  1251.   regnumber[0]       = '\0';
  1252.   regcountry[0]      = '\0';
  1253.   regcity[0]         = '\0';
  1254.   freeinit[0]        = '\0';
  1255.   freeend[0]         = '\0';
  1256.   dayinit[0]         = '\0';
  1257.   databasename[0]    = '\0';
  1258.   phoneignore[0]     = '\0';
  1259.   phonecheck[0]      = '\0';
  1260.   menu[0]            = '\0';
  1261.   categorydefault[0] = '\0';
  1262.   pricedefault[0]    = '\0';
  1263.   categorydir[0]     = '\0';
  1264.   returnmonth[0]     = '\0';
  1265.   precision[0]       = '\0';
  1266.   regnumberreal[0]   = '\0';
  1267.   extrahour[0]       = '\0';
  1268.   providerbill[0]    = '\0';
  1269.   unit[0]            = '\0';
  1270.   excededtime[0]     = '\0';
  1271.   excededyear[0]     = '\0';
  1272.   htmlcheck[0]       = '\0';
  1273.   htmlname[0]        = '\0';
  1274.   browser[0]         = '\0';
  1275.   checkreports[0]    = '\0';
  1276.   checkglobalhtml[0] = '\0';
  1277.  
  1278.   get(App->DataBaseName, MUIA_String_Contents, &database);
  1279.   if(!(ExisteDiretorio("Freedom:")))
  1280.   {
  1281.     /* FREEDOM NEEDS ASSIGN */
  1282.     MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg18), TMsg(App->Msg28));
  1283.     DoMethod(App->App, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
  1284.   }
  1285.   /* ROTINA PARA CARREGAR A CONFIGURACAO */
  1286.   if(!(entrada = fopen("Freedom:Freedom.Config", "r")))
  1287.     return NULL;
  1288.  
  1289.   x = 0; y = 0;
  1290.   while(a = getc(entrada), ! feof(entrada))
  1291.   {
  1292.     teste[x++] = a;
  1293.     if(a == '\n')
  1294.     {
  1295.       teste[--x] = '\0'; y++;
  1296.       switch(y)
  1297.       {
  1298.         case  1: strcpy(path, AposCaracter(teste, ':', 1)); break;
  1299.         case  2: strcpy(limit, AposCaracter(teste, ':', 1)); break;
  1300.         case  3: strcpy(warning, AposCaracter(teste, ':', 1)); break;
  1301.         case  4: strcpy(startup, AposCaracter(teste, ':', 1)); break;
  1302.         case  5: strcpy(regname, AposCaracter(teste, ':', 1)); break;
  1303.         case  6: strcpy(regorganiz, AposCaracter(teste, ':', 1)); break;
  1304.         case  7: strcpy(regemail, AposCaracter(teste, ':', 1)); break;
  1305.         case  8: strcpy(regnumber, AposCaracter(teste, ':', 1)); break;
  1306.         case  9: strcpy(regcountry, AposCaracter(teste, ':', 1)); break;
  1307.         case 10: strcpy(regcity, AposCaracter(teste, ':', 1)); break;
  1308.         case 11: strcpy(freeinit, AposCaracter(teste, ':', 1)); break;
  1309.         case 12: strcpy(freeend, AposCaracter(teste, ':', 1)); break;
  1310.         case 13: strcpy(dayinit, AposCaracter(teste, ':', 1)); break;
  1311.         case 14: strcpy(databasename, AposCaracter(teste, ':', 1)); break;
  1312.         case 15: strcpy(phoneignore, AposCaracter(teste, ':', 1)); break;
  1313.         case 16: strcpy(phonecheck, AposCaracter(teste, ':', 1)); break;
  1314.         case 17: strcpy(menu, AposCaracter(teste, ':', 1)); break;
  1315.         case 18: strcpy(categorydefault, AposCaracter(teste, ':', 1)); break;
  1316.         case 19: strcpy(pricedefault, AposCaracter(teste, ':', 1)); break;
  1317.         case 20: strcpy(categorydir, AposCaracter(teste, ':', 1)); break;
  1318.         case 21: strcpy(returnmonth, AposCaracter(teste, ':', 1)); break;
  1319.         case 22: strcpy(precision, AposCaracter(teste, ':', 1)); break;
  1320.         case 23: strcpy(regnumberreal, AposCaracter(teste, ':', 1)); break;
  1321.         case 24: strcpy(extrahour, AposCaracter(teste, ':', 1)); break;
  1322.         case 25: strcpy(providerbill, AposCaracter(teste, ':', 1)); break;
  1323.         case 26: strcpy(unit, AposCaracter(teste, ':', 1)); break;
  1324.         case 27: strcpy(excededtime, AposCaracter(teste, ':', 1)); break;
  1325.         case 28: strcpy(excededyear, AposCaracter(teste, ':', 1)); break;
  1326.         case 29: strcpy(htmlcheck, AposCaracter(teste, ':', 1)); break;
  1327.         case 30: strcpy(htmlname, AposCaracter(teste, ':', 1)); break;
  1328.         case 31: strcpy(browser, AposCaracter(teste, ':', 1)); break;
  1329.         case 32: strcpy(checkreports, AposCaracter(teste, ':', 1)); break;
  1330.         case 33: strcpy(checkglobalhtml, AposCaracter(teste, ':', 1)); break;
  1331.       }
  1332.       teste[0] = '\0'; x = 0;
  1333.     }
  1334.   }
  1335.   fclose(entrada);
  1336.  
  1337.   set(App->RequestMiamiLog, MUIA_String_Contents, path);
  1338.   set(App->InputLimitTime, MUIA_String_Contents, limit);
  1339.  
  1340.   /* CARREGA CAMPOS NUMERICOS DE CHECK BOX */
  1341.   if(atoi(warning) == 1)
  1342.     set(App->LabelVisualGeneration, MUIA_Selected, TRUE);
  1343.   else
  1344.     set(App->LabelVisualGeneration, MUIA_Selected, FALSE);
  1345.   if(atoi(startup) == 1)
  1346.     set(App->LabelGenerationStartup, MUIA_Selected, TRUE);
  1347.   else
  1348.     set(App->LabelGenerationStartup, MUIA_Selected, FALSE);
  1349.   if(atoi(phonecheck) == 1)
  1350.     set(App->GrupoFoneInputCheck, MUIA_Selected, TRUE);
  1351.   else
  1352.     set(App->GrupoFoneInputCheck, MUIA_Selected, FALSE);
  1353.   if(atoi(returnmonth) == 1)
  1354.     set(App->ProviderRetornaMes, MUIA_Selected, TRUE);
  1355.   else
  1356.     set(App->ProviderRetornaMes, MUIA_Selected, FALSE);
  1357.   if(atoi(htmlcheck) == 1)
  1358.     set(App->HtmlCheck, MUIA_Selected, TRUE);
  1359.   else
  1360.     set(App->HtmlCheck, MUIA_Selected, FALSE);
  1361.   if(atoi(checkreports) == 1)
  1362.     set(App->CheckReports, MUIA_Selected, TRUE);
  1363.   else
  1364.     set(App->CheckReports, MUIA_Selected, FALSE);
  1365.  
  1366.   if(atoi(checkglobalhtml) == 1)
  1367.     set(App->CheckGlobalHtml, MUIA_Selected, TRUE);
  1368.   else
  1369.     set(App->CheckGlobalHtml, MUIA_Selected, FALSE);
  1370.  
  1371.   set(App->HtmlName, MUIA_String_Contents, htmlname);
  1372.   set(App->Browser, MUIA_String_Contents, browser);
  1373.   set(App->ExcededTime, MUIA_String_Contents, excededtime);
  1374.   set(App->ExcededYear, MUIA_String_Contents, excededyear);
  1375.   set(App->HoraExtra, MUIA_String_Contents, extrahour);
  1376.   set(App->ContaProvedor, MUIA_String_Contents, providerbill);
  1377.   set(App->PrefsComboMenu, MUIA_Cycle_Active, atof(menu));
  1378.   set(App->RegisterName, MUIA_String_Contents, regname);
  1379.   set(App->RegisterOrganization, MUIA_String_Contents, regorganiz);
  1380.   set(App->RegisterEmail, MUIA_String_Contents, regemail);
  1381.   set(App->RegisterKey, MUIA_String_Contents, regnumber);
  1382.   set(App->RegisterKeyReal, MUIA_String_Contents, regnumberreal);
  1383.   set(App->RegisterCountry, MUIA_String_Contents, regcountry);
  1384.   set(App->RegisterCity, MUIA_String_Contents, regcity);
  1385.   set(App->GrupoFoneInput, MUIA_String_Contents, phoneignore);
  1386.   set(App->CategValorDefault, MUIA_String_Contents, pricedefault);
  1387.   set(App->TextDefault, MUIA_Text_Contents, categorydefault);
  1388.   set(App->PrefsFreeHInicio, MUIA_String_Contents, freeinit);
  1389.   set(App->PrefsFreeHFim, MUIA_String_Contents, freeend);
  1390.   set(App->PrefsDiaInicial, MUIA_String_Contents, dayinit);
  1391.   set(App->DataBaseName, MUIA_String_Contents, databasename);
  1392.   set(App->CategDiretorio, MUIA_String_Contents, categorydir);
  1393.   set(App->ConfPrecision, MUIA_String_Contents, precision);
  1394.   set(App->ConfUnit, MUIA_String_Contents, unit);
  1395.  
  1396.   /* CARREGA A CATEGORIA DEFAULT */
  1397.   CarregaListaLimites(categorydefault);
  1398.   CarregaPilhaCategorias(categorydefault);
  1399.  
  1400.   /* ACERTA VALORES DEFAULTS CASO SEJAM INVALIDOS */
  1401.   if(!(strcmp(precision, "")))
  1402.     set(App->ConfPrecision, MUIA_String_Contents, "2");
  1403.   if(!(strcmp(categorydir, "")))
  1404.     set(App->CategDiretorio, MUIA_String_Contents, "Freedom:Categories");
  1405.   if(!(strcmp(freeinit, "")))
  1406.     set(App->PrefsFreeHInicio, MUIA_String_Contents, "00:00:00");
  1407.   if(!(strcmp(freeend, "")))
  1408.     set(App->PrefsFreeHFim, MUIA_String_Contents, "00:00:00");
  1409.   if(!(strcmp(dayinit, "")))
  1410.     set(App->PrefsDiaInicial, MUIA_String_Contents, "1");
  1411.   if(!(strcmp(databasename, "")))
  1412.     set(App->DataBaseName, MUIA_String_Contents, "Freedom:FDataBase");
  1413.  
  1414.   /* VERIFICA A JANELA PRINCIPAL CERTA A ABRIR (STAND, GRAPHIC) */
  1415.   if(!strcmp(menu, "0")) {
  1416.     set(App->JanelaPrincipal, MUIA_Window_Open, FALSE);
  1417.     set(App->JanelaPrincipal2, MUIA_Window_Open, TRUE);
  1418.   } else {
  1419.     set(App->JanelaPrincipal2, MUIA_Window_Open, FALSE);
  1420.     set(App->JanelaPrincipal, MUIA_Window_Open, TRUE); }
  1421.  
  1422.   /* CARREGA A LISTA PRINCIPAL DAS CATEGORIAS */
  1423.   CarregaListaCategorias();
  1424.   return NULL;
  1425. }
  1426.  
  1427. APTR TestaRegistro( struct Hook *a0, APTR a2, APTR a1 )
  1428. {
  1429.   char senha1[256], senha2[256], senhatmp[256], *regnumber2,
  1430.        *regemail, *regnumber, *regname, *regorg, *regcountry;
  1431.   int registro = 0;
  1432.  
  1433.   /* ROTINA QUE TESTA O TIPO DE REGISTRO */
  1434.   get(App->RegisterName, MUIA_String_Contents, ®name);
  1435.   get(App->RegisterOrganization, MUIA_String_Contents, ®org);
  1436.   get(App->RegisterEmail, MUIA_String_Contents, ®email);
  1437.   get(App->RegisterCountry, MUIA_String_Contents, ®country);
  1438.   get(App->RegisterKeyReal, MUIA_String_Contents, ®number2);
  1439.   get(App->RegisterKey, MUIA_String_Contents, ®number);
  1440.   strcpy(senha1, AsciiString(regnumber, 69));
  1441.   strcpy(senha2, AsciiString(regnumber2, 96));
  1442.   sprintf(senhatmp, "%s%s%s", regname, regemail, regcountry);
  1443.   strcpy(senhatmp, CriptografiaSimples(senhatmp, 0));
  1444.   if(!strcmp(senha1, senhatmp))
  1445.     registro = 1;
  1446.   if(!strcmp(senha1, senhatmp) && !strcmp(senha2, senhatmp))
  1447.     registro = 2;
  1448.   if(!strcmp(regnumber, ""))
  1449.     registro = 0;
  1450.  
  1451.   /* TESTA SE O PROGRAMA EH REGISTRADO OU NAO */
  1452.   if(registro == 0)
  1453.   {
  1454.     MsgRegistro();
  1455.     return NULL;
  1456.   }
  1457.   set(App->JanelaSelecionaMes, MUIA_Window_Open, TRUE);
  1458.   return NULL;
  1459. }
  1460.  
  1461. APTR PreparaOutroMes( struct Hook *a0, APTR a2, APTR a1 )
  1462. {
  1463.   /* ROTINA QUE PREPARA O ARQUIVO DE ESTATISTICAS COM OUTRO MES, 
  1464.   DIA OU ATE MESMO UM DETERMINADO ANO */
  1465.   char teste[256], mesdes[5], diades[5], *dia, *mes, *ano, *select,
  1466.        mesdes2[20], *diax, *horainicio, *horafim, data1[256], 
  1467.        data2[256], *database, freein[256], freeout[256], xx[10],
  1468.        arquivo1[256], arquivo2[256];
  1469.   int x = 0;
  1470.   long combo = 0, retorno = 0;
  1471.  
  1472.   LimpaJanelaDesseMes();
  1473.   /* TESTA SE O DIRETORIO DA BASE DE DADOS EXISTE */
  1474.   get(App->DataBaseName, MUIA_String_Contents, &database);
  1475.   if(!ExisteDiretorio(database))
  1476.   {
  1477.      MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg18), TMsg(App->Msg17));
  1478.      return NULL;
  1479.   }
  1480.  
  1481.   /* PEGA O NUMERO DA POSICAO DO COMBO DE DIA, MES, ANO */
  1482.   get(App->ComboSelect, MUIA_Cycle_Active, &combo);
  1483.  
  1484.   set(App->JanelaGeracaoQuery, MUIA_Window_Open, TRUE);
  1485.   set(App->GaugeQuery, MUIA_Gauge_Current, 5);
  1486.   set(App->GaugeQuery, MUIA_Gauge_InfoText, TMsg(App->Msg26));
  1487.  
  1488.   get(App->TextDia, MUIA_String_Contents, &dia);
  1489.   get(App->ComboMes, MUIA_Text_Contents, &mes);
  1490.   get(App->TextAno, MUIA_String_Contents, &ano);
  1491.   get(App->ComboSelect, MUIA_Text_Contents, &select);
  1492.   get(App->PrefsFreeHInicio, MUIA_String_Contents, &horainicio);
  1493.   get(App->PrefsFreeHFim, MUIA_String_Contents, &horafim);
  1494.   get(App->PrefsDiaInicial, MUIA_String_Contents, &diax);
  1495.   get(App->ProviderRetornaMes, MUIA_Selected, &retorno);
  1496.  
  1497.   sprintf(mesdes, Corta(mes, ' ', 0));
  1498.   sprintf(mesdes2, Corta(mes, ' ', 1));
  1499.  
  1500.   /* CARREGA VARIAVEIS DE PARA LEITURA DOS ARQUIVOS */
  1501.   sprintf(freeout, "%s/Freedom.Out", database);
  1502.  
  1503.   set(App->GaugeQuery, MUIA_Gauge_Current, 15);
  1504.   /* ACERTA ESTATISTICA POR DIA */
  1505.   if(combo == 1)
  1506.   {
  1507.     if(strlen(dia) < 2)
  1508.       sprintf(diades, "0%s", dia);
  1509.     else
  1510.       strcpy(diades, dia);
  1511.     sprintf(teste, "%s.%s.%s", diades, mesdes, ano);
  1512.     sprintf(freein, "%s/Freedom.%s.%s", database, mesdes, ano);
  1513.  
  1514.     if( ((!(strcmp(horainicio, "")) && !(strcmp(horafim, ""))) ||
  1515.          (!(strcmp(horainicio, "00:00:00")) && !(strcmp(horafim, "00:00:00")))) && (atoi(diax) <= 1) )
  1516.     {
  1517.       FiltraCampoParaArquivoFREE(teste, freein, "t:freedom.intmp", ',', 1, '.');
  1518.       FiltraCampoParaArquivoFREE(teste, freeout, "t:freedom.outtmp", ',', 1, '.');
  1519.     }
  1520.     else
  1521.     {
  1522.       SelecionaIntervaloCampo(freein, "T:Freedom.InTmp", "Ram:Freedom.Temp", teste, teste, horainicio, horafim);
  1523.       SelecionaIntervaloCampo(freeout, "T:Freedom.OutTmp", "Ram:Freedom.Temp", teste, teste, horainicio, horafim);
  1524.     }
  1525.     sprintf(teste, "%s, %s %s", diades, mesdes2, ano);
  1526.     GravaRegistroDB("t:Freedom.Date", teste, "date", "w");
  1527.     SemanaCount("t:Freedom.InTmp");
  1528.     return NULL;
  1529.   }
  1530.   set(App->GaugeQuery, MUIA_Gauge_Current, 35);
  1531.  
  1532.   /* ACERTA ESTATISTICA POR MES */
  1533.   if(combo == 0)
  1534.   {
  1535.     sprintf(teste, "%s.%s", mesdes, ano);
  1536.     sprintf(freein, "%s/Freedom.%s.%s", database, mesdes, ano);
  1537.  
  1538.     if( ((!(strcmp(horainicio, "")) && !(strcmp(horafim, ""))) ||
  1539.          (!(strcmp(horainicio, "00:00:00")) && !(strcmp(horafim, "00:00:00")))) && (atoi(diax) <= 1) )
  1540.     {
  1541.       FiltraCampoParaArquivoFREE(teste, freein, "t:freedom.intmp", ',', 1, '.');
  1542.       FiltraCampoParaArquivoFREE(teste, freeout, "t:freedom.outtmp", ',', 1, '.');
  1543.     }
  1544.     else
  1545.     {
  1546.       sprintf(data1, "%s.%s", diax, teste);
  1547.       x = atoi(diax);  
  1548.       x--;
  1549.       if(x < 1)
  1550.         x = 31;
  1551.       sprintf(data2, "%d.%s", x, teste);
  1552.  
  1553.       if(atoi(diax) > 1)
  1554.       {
  1555.         strcpy(data2, ArrumaDataHora(SomaDiminuiMes(data2, 1), '.'));
  1556.         /* RETORNA UM MES CASO SEJA NECESSARIO */
  1557.         if(retorno == 1)
  1558.         {
  1559.           strcpy(data1, SomaDiminuiMes(data1, -1));
  1560.           strcpy(data2, SomaDiminuiMes(data2, -1));
  1561.         }
  1562.         /* PREPARA O ARQUIVO DE LEITURA */
  1563.         sprintf(arquivo1, "%s/Freedom.%s", database, AposCaracter(data1, '.', 1));
  1564.         sprintf(arquivo2, "%s/Freedom.%s", database, AposCaracter(data2, '.', 1));
  1565.         CopiaArquivo(arquivo1, "T:Freedom.InTmp");
  1566.         InsereArquivo(arquivo2, "T:Freedom.InTmp");
  1567.         strcpy(freein, "T:Freedom.InTmp");
  1568.       }
  1569.       SelecionaIntervaloCampo(freein, "T:Freedom.InTmp", "Ram:Freedom.Temp", data1, data2, horainicio, horafim);
  1570.       SelecionaIntervaloCampo(freeout, "T:Freedom.OutTmp", "Ram:Freedom.Temp", data1, data2, horainicio, horafim);
  1571.     }
  1572.     sprintf(teste, "%s %s", mesdes2, ano);
  1573.     GravaRegistroDB("t:Freedom.Date", teste, "date", "w");
  1574.     SemanaCount("t:Freedom.InTmp");
  1575.     return NULL;
  1576.   } 
  1577.   set(App->GaugeQuery, MUIA_Gauge_Current, 35);
  1578.  
  1579.   /* ACERTA ESTATISTICA POR ANO */
  1580.   if(combo == 2)
  1581.   {
  1582.     /* PREPARA ARQUIVO ANUAL PARA CONSULTA */
  1583.     for(x = 1; x < 13; x++)
  1584.     {
  1585.       if(x < 10)
  1586.         sprintf(xx, "0%d", x);
  1587.       else
  1588.         sprintf(xx, "%d", x);
  1589.       sprintf(teste, "%s/Freedom.%s.%s", database, xx, ano); 
  1590.       InsereArquivo(teste, "t:Freedom.Year");
  1591.     }
  1592.     sprintf(teste, "%s", ano);
  1593.  
  1594.     if( ((!(strcmp(horainicio, "")) && !(strcmp(horafim, ""))) ||
  1595.          (!(strcmp(horainicio, "00:00:00")) && !(strcmp(horafim, "00:00:00")))) && (atoi(diax) <= 1) )
  1596.     {
  1597.       CopiaArquivo("T:Freedom.Year", "t:Freedom.InTmp");
  1598.       FiltraCampoParaArquivoFREE(teste, freeout, "t:freedom.outtmp", ',', 1, '.');
  1599.     }
  1600.     else
  1601.     {
  1602.       sprintf(data1, "01.01.%s", teste);
  1603.       sprintf(data2, "31.12.%s", teste);
  1604.       SelecionaIntervaloCampo("t:Freedom.Year", "T:Freedom.InTmp", "Ram:Freedom.Temp", data1, data2, horainicio, horafim);
  1605.       SelecionaIntervaloCampo(freeout, "T:Freedom.OutTmp", "Ram:Freedom.Temp", data1, data2, horainicio, horafim);
  1606.     }
  1607.     set(App->GaugeQuery, MUIA_Gauge_Current, 35);
  1608.     remove("t:Freedom.Year");
  1609.     sprintf(teste, "%s", ano);
  1610.     GravaRegistroDB("t:Freedom.Date", teste, "date", "w");
  1611.     SemanaCount("t:Freedom.InTmp");
  1612.     set(App->GaugeQuery, MUIA_Gauge_Current, 50);
  1613.     return NULL;
  1614.   } 
  1615.   return NULL;
  1616. }
  1617.  
  1618. APTR DiminuiDia( struct Hook *a0, APTR a2, APTR a1 )
  1619. {
  1620.   /* ROTINA QUE DIMINUI DIA NO EDIT DA SELECAO DE MES */
  1621.   char teste[100], *dia;
  1622.   get(App->TextDia, MUIA_String_Contents, &dia);
  1623.   if(atoi(dia) == 1)
  1624.     strcpy(dia, "31");
  1625.   else
  1626.   {
  1627.     sprintf(teste, "%d", (atoi(dia) - 1));
  1628.     strcpy(dia, teste);
  1629.   }
  1630.   MUI_Redraw(App->TextDia, MADF_DRAWOBJECT);
  1631.   return NULL;
  1632. }
  1633.  
  1634. APTR AumentaDia( struct Hook *a0, APTR a2, APTR a1 )
  1635. {
  1636.   /* ROTINA QUE AUMENTA DIA NO EDIT DA SELECAO DE MES */
  1637.   char teste[100], *dia;
  1638.   get(App->TextDia, MUIA_String_Contents, &dia);
  1639.   if(atoi(dia) == 31)
  1640.     strcpy(dia, "1");
  1641.   else
  1642.   {
  1643.     sprintf(teste, "%d", (atoi(dia) + 1));
  1644.     strcpy(dia, teste);
  1645.   }
  1646.   MUI_Redraw(App->TextDia, MADF_DRAWOBJECT);
  1647.   return NULL;
  1648. }
  1649.  
  1650. APTR DiminuiAno( struct Hook *a0, APTR a2, APTR a1 )
  1651. {
  1652.   /* ROTINA QUE DIMINUI ANO NO EDIT DA SELECAO DE MES */
  1653.   char teste[100], *ano;
  1654.   get(App->TextAno, MUIA_String_Contents, &ano);
  1655.   if(atoi(ano) == 1)
  1656.     strcpy(ano, "1");
  1657.   else
  1658.   {
  1659.     sprintf(teste, "%d", (atoi(ano) - 1));
  1660.     strcpy(ano, teste);
  1661.   }
  1662.   MUI_Redraw(App->TextAno, MADF_DRAWOBJECT);
  1663.   return NULL;
  1664. }
  1665.  
  1666. APTR AumentaAno( struct Hook *a0, APTR a2, APTR a1 )
  1667. {
  1668.   /* ROTINA QUE AUMENTA ANO NO EDIT DA SELECAO DE MES */
  1669.   char teste[100], *ano;
  1670.   get(App->TextAno, MUIA_String_Contents, &ano);
  1671.   sprintf(teste, "%d", (atoi(ano) + 1));
  1672.   strcpy(ano, teste);
  1673.   MUI_Redraw(App->TextAno, MADF_DRAWOBJECT);
  1674.   return NULL;
  1675. }
  1676.  
  1677. APTR DataAtual( struct Hook *a0, APTR a2, APTR a1 )
  1678. {
  1679.   /* CARREGA DATA ATUAL PARA A JANELA DE SELECAO DE MES */
  1680.   char *database, *dia, *ano, teste[256], teste2[256];
  1681.   int tmp;
  1682.   get(App->TextDia, MUIA_String_Contents, &dia);
  1683.   get(App->TextAno, MUIA_String_Contents, &ano);
  1684.   get(App->DataBaseName, MUIA_String_Contents, &database);
  1685.   strcpy(teste, DataHora(0));
  1686.  
  1687.   tmp = atoi(Corta(teste, '.', 0));
  1688.   sprintf(dia, "%d", tmp);
  1689.   tmp = atoi(Corta(teste, '.', 2));
  1690.   sprintf(ano, "%d", tmp);
  1691.   tmp = atoi(Corta(teste, '.', 1));
  1692.  
  1693.   /* ATUALIZA A SELECAO DE DIA, MES, ANO */
  1694.   tmp--;
  1695.   set(App->ComboMes, MUIA_Cycle_Active, tmp);
  1696.   set(App->ComboMes2, MUIA_Cycle_Active, tmp);
  1697.  
  1698.   set(App->TextDia, MUIA_String_Contents, dia);
  1699.   MUI_Redraw(App->TextDia, MADF_DRAWOBJECT);
  1700.  
  1701.   set(App->TextAno, MUIA_String_Contents, ano);
  1702.   MUI_Redraw(App->TextAno, MADF_DRAWOBJECT);
  1703.  
  1704.   set(App->TextAno2, MUIA_String_Contents, ano);
  1705.   MUI_Redraw(App->TextAno2, MADF_DRAWOBJECT);
  1706.  
  1707.   set(App->InputPeriodo1, MUIA_String_Contents, teste);
  1708.   set(App->InputPeriodo2, MUIA_String_Contents, teste);
  1709.   set(App->LabelInputDateLogin, MUIA_String_Contents, Corta(teste, ':', 0));
  1710.   /* CARREGA ULTIMO TELEFONE NO INPUT MANUAL */
  1711.   sprintf(teste2, "%s/Freedom.%s", database, DataHora(1));
  1712.   strcpy(teste, UltimaLinha(teste2));
  1713.   if(!strcmp(teste, "ERRO"))
  1714.     strcpy(teste, "");
  1715.   set(App->LabelInputPhone, MUIA_String_Contents, Corta(teste, ',', 0));
  1716.  
  1717.   /* CARREGA INFORMACOES DA SELECAO DE ESTATISTICA ANUAL */
  1718.   set(App->CAnualText, MUIA_String_Contents, Corta(DataHora(3), '.', 0));
  1719.   set(App->CAnualMes1, MUIA_Cycle_Active, 0);
  1720.   set(App->CAnualMes2, MUIA_Cycle_Active, 11);
  1721.  
  1722.   /* CARREGA A DATA DE HOJE NA BARRA DA JANELA GRAFICA */
  1723.   CarregaBarraStatus();
  1724.  
  1725.   return NULL;
  1726. }
  1727.  
  1728. APTR AcertaAbout( struct Hook *a0, APTR a2, APTR a1 )
  1729. {
  1730.   /* ATUALIZA INFORMACOES JANELA ABOUT, SOBRE O TIPO DE REGISTRO */
  1731.   char reg[256], org[256], teste[256], senha1[256], senha2[256],
  1732.        senhatmp[256], *regnumber2,
  1733.        *regname, *regorg, *regcountry, *regemail, *regnumber;
  1734.   int registro = 0;
  1735.  
  1736.   get(App->RegisterName, MUIA_String_Contents, ®name);
  1737.   get(App->RegisterOrganization, MUIA_String_Contents, ®org);
  1738.   get(App->RegisterCountry, MUIA_String_Contents, ®country);
  1739.   get(App->RegisterEmail, MUIA_String_Contents, ®email);
  1740.   get(App->RegisterKeyReal, MUIA_String_Contents, ®number2);
  1741.   get(App->RegisterKey, MUIA_String_Contents, ®number);
  1742.  
  1743.   if(!strcmp(TrimSur(regorg, 0), ""))
  1744.     sprintf(org, "(%s)", regcountry);
  1745.   else
  1746.     sprintf(org, "(%s - %s)", regcountry, regorg);
  1747.  
  1748.   /* ROTINA QUE TESTA O TIPO DE REGISTRO */
  1749.   strcpy(senha1, AsciiString(regnumber, 69));
  1750.   strcpy(senha2, AsciiString(regnumber2, 96));
  1751.   sprintf(senhatmp, "%s%s%s", regname, regemail, regcountry);
  1752.   strcpy(senhatmp, CriptografiaSimples(senhatmp, 0));
  1753.   if(!strcmp(senha1, senhatmp))
  1754.     registro = 1;
  1755.   if(!strcmp(senha1, senhatmp) && !strcmp(senha2, senhatmp))
  1756.     registro = 2;
  1757.   if(!strcmp(regnumber, ""))
  1758.     registro = 0;
  1759.  
  1760.   if(registro == 0)
  1761.     strcpy(reg, "\033bUNREGISTERED\033n\nRegister is a free e-mail!");
  1762.   if(registro == 1)
  1763.       sprintf(reg, "\033bNOPAY REGISTERED\033n\n%s\n%s", regname, org);
  1764.   if(registro == 2)
  1765.       sprintf(reg, "\033bREAL REGISTERED\033n\n%s\n%s", regname, org);
  1766.   sprintf(teste, "\033c\0338\033b\nFreedom Call\nVersion 1.12 [28.05.1999]\033n\nBy Cristian Robert Gallas\n\nAmiga Open Source (SuRRouND 99)\n\nEmail for bug reports: surround@iname.com\n [members.tripod.com/surround_br] \n\nThis version is:\n%s\n", reg);
  1767.   set(App->TextAbout, MUIA_Text_Contents, teste);
  1768.   return NULL;
  1769. }
  1770.  
  1771. APTR GerarImportacaoRegistro( struct Hook *a0, APTR a2, APTR a1 )
  1772. {
  1773.   /* ROTINA DE IMPORTACAO DO ARQUIVO DE REGISTRO */
  1774.   char reg1[500], reg2[500], *path;
  1775.   get(App->DirImportaRegistro, MUIA_String_Contents, &path);
  1776.  
  1777.   if(!(ExisteArquivo(path)))
  1778.   {
  1779.     /* FILE FOR IMPORTING NOT FOUND */
  1780.     MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg18), TMsg(App->Msg35));
  1781.     return NULL;
  1782.   }
  1783.   strcpy(reg1, LeRegistroDB(path, "KeyRegister"));
  1784.   strcpy(reg2, LeRegistroDB(path, "KeyRegisterReal"));
  1785.   if(!(strcmp(reg1, "")))
  1786.   {
  1787.     /* THIS FILE DON`T HAVE REGISTRATION */
  1788.     MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg18), TMsg(App->Msg36));
  1789.     return NULL;
  1790.   }
  1791.   set(App->RegisterKey, MUIA_String_Contents, reg1);
  1792.   set(App->RegisterKeyReal, MUIA_String_Contents, reg2);
  1793.   
  1794.   return NULL;
  1795. }
  1796.  
  1797. APTR AplicacaoHide( struct Hook *a0, APTR a2, APTR a1 )
  1798.   /* MINIMIZA A APLICACAO, COLOCA ELA EM ICONIFIED */
  1799.   set(App->App, MUIA_Application_Iconified, TRUE);
  1800.   return NULL;
  1801. }
  1802.  
  1803. APTR HelpMain( struct Hook *a0, APTR a2, APTR a1 )
  1804. {
  1805.   if(!(ExisteArquivo("Freedom:Docs/Freedom.Guide")))
  1806.   {
  1807.     /* FREEDOM:FREEDOM.GUIDE NOT FOUND, PLEASE COPY */
  1808.     MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg18), TMsg(App->Msg37));
  1809.     return NULL;
  1810.   }
  1811.   DoMethod(App->App, MUIM_Application_ShowHelp, 0, "Freedom:Docs/Freedom.Guide", "Main", 1);
  1812.   return NULL;
  1813. }
  1814.  
  1815. APTR HelpUsage( struct Hook *a0, APTR a2, APTR a1 )
  1816. {
  1817.   if(!(ExisteArquivo("Freedom:Docs/Freedom.Guide")))
  1818.   {
  1819.     MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg18), TMsg(App->Msg37));
  1820.     return NULL;
  1821.   }
  1822.   DoMethod(App->App, MUIM_Application_ShowHelp, 0, "Freedom:Docs/Freedom.Guide", "Usage", 1);
  1823.   return NULL;
  1824. }
  1825.  
  1826. APTR HelpHistory( struct Hook *a0, APTR a2, APTR a1 )
  1827. {
  1828.   if(!(ExisteArquivo("Freedom:Docs/Freedom.Guide")))
  1829.   {
  1830.     MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg18), TMsg(App->Msg37));
  1831.     return NULL;
  1832.   }
  1833.   DoMethod(App->App, MUIM_Application_ShowHelp, 0, "Freedom:Docs/Freedom.Guide", "History", 1);
  1834.   return NULL;
  1835. }
  1836.  
  1837. APTR AboutMUI( struct Hook *a0, APTR a2, APTR a1 )
  1838. {
  1839.   DoMethod(App->App, MUIM_Application_AboutMUI, App->JanelaPrincipal);
  1840.   return NULL;
  1841. }
  1842.  
  1843. APTR LimpaSaida( struct Hook *a0, APTR a2, APTR a1 )
  1844.   /* LIMPA ARQUIVOS TEMPORARIOS APOS A FINALIZACAO DO PROGRAMA */
  1845.   remove("t:freedom.intmp");
  1846.   remove("t:freedom.outtmp");
  1847.   remove("t:freedom.date");
  1848.   remove("t:freedom.week");
  1849.   remove("t:freedom.rates");
  1850.   remove("t:freedom.html");
  1851.   return NULL;
  1852. }
  1853.  
  1854. APTR CarregaSemana( struct Hook *a0, APTR a2, APTR a1 )
  1855. {
  1856.   char dom[50], seg[50], ter[50], qua[50], qui[50], sex[50],
  1857.        sab[50], tot[50], teste[256], teste2[256], *moedac,
  1858.        *precision, senha1[256], senha2[256], senhatmp[256], *regnumber2,
  1859.        *regemail, *regnumber, *regname, *regorg, *regcountry;
  1860.   int registro = 0;
  1861.   long moeda = 0;
  1862.  
  1863.   /* LIMPA OS REGISTROS */
  1864.   set(App->ValorDomingo, MUIA_Text_Contents, "0");
  1865.   set(App->ValorSegunda, MUIA_Text_Contents, "0");
  1866.   set(App->ValorTerca, MUIA_Text_Contents, "0");
  1867.   set(App->ValorQuarta, MUIA_Text_Contents, "0");
  1868.   set(App->ValorQuinta, MUIA_Text_Contents, "0");
  1869.   set(App->ValorSexta, MUIA_Text_Contents, "0");
  1870.   set(App->ValorSabado, MUIA_Text_Contents, "0");
  1871.   set(App->PercentualDomingo, MUIA_Text_Contents, "0");
  1872.   set(App->PercentualSegunda, MUIA_Text_Contents, "0");
  1873.   set(App->PercentualTerca, MUIA_Text_Contents, "0");
  1874.   set(App->PercentualQuarta, MUIA_Text_Contents, "0");
  1875.   set(App->PercentualQuinta, MUIA_Text_Contents, "0");
  1876.   set(App->PercentualSexta, MUIA_Text_Contents, "0");
  1877.   set(App->PercentualSabado, MUIA_Text_Contents, "0");
  1878.   set(App->ValorTotal, MUIA_Text_Contents, "0");
  1879.   set(App->PercentualTotal, MUIA_Text_Contents, "0");
  1880.   set(App->WeekLabelTop, MUIA_Text_Contents, "");
  1881.   set(App->TimeTotal, MUIA_Text_Contents, "0");
  1882.   set(App->TimeDomingo, MUIA_Text_Contents, "0");
  1883.   set(App->TimeSegunda, MUIA_Text_Contents, "0");
  1884.   set(App->TimeTerca, MUIA_Text_Contents, "0");
  1885.   set(App->TimeQuarta, MUIA_Text_Contents, "0");
  1886.   set(App->TimeQuinta, MUIA_Text_Contents, "0");
  1887.   set(App->TimeSexta, MUIA_Text_Contents, "0");
  1888.   set(App->TimeSabado, MUIA_Text_Contents, "0");
  1889.   set(App->CustoTotal, MUIA_Text_Contents, "0");
  1890.   set(App->CustoDomingo, MUIA_Text_Contents, "0");
  1891.   set(App->CustoSegunda, MUIA_Text_Contents, "0");
  1892.   set(App->CustoTerca, MUIA_Text_Contents, "0");
  1893.   set(App->CustoQuarta, MUIA_Text_Contents, "0");
  1894.   set(App->CustoQuinta, MUIA_Text_Contents, "0");
  1895.   set(App->CustoSexta, MUIA_Text_Contents, "0");
  1896.   set(App->CustoSabado, MUIA_Text_Contents, "0");
  1897.  
  1898.   /* PEGA INFORMACOES DA MOEDA CORRENTE */
  1899.   get(App->ComboMoeda, MUIA_Cycle_Active, &moeda);
  1900.   get(App->NomeMoeda, MUIA_String_Contents, &moedac);
  1901.  
  1902.   /* PEGA A PRECISAO DOS DISPLAYS DE VALORES */
  1903.   get(App->ConfPrecision, MUIA_String_Contents, &precision);
  1904.  
  1905.   /* ROTINA QUE TESTA O TIPO DE REGISTRO */
  1906.   get(App->RegisterName, MUIA_String_Contents, ®name);
  1907.   get(App->RegisterOrganization, MUIA_String_Contents, ®org);
  1908.   get(App->RegisterEmail, MUIA_String_Contents, ®email);
  1909.   get(App->RegisterCountry, MUIA_String_Contents, ®country);
  1910.   get(App->RegisterKeyReal, MUIA_String_Contents, ®number2);
  1911.   get(App->RegisterKey, MUIA_String_Contents, ®number);
  1912.   strcpy(senha1, AsciiString(regnumber, 69));
  1913.   strcpy(senha2, AsciiString(regnumber2, 96));
  1914.   sprintf(senhatmp, "%s%s%s", regname, regemail, regcountry);
  1915.   strcpy(senhatmp, CriptografiaSimples(senhatmp, 0));
  1916.   if(!strcmp(senha1, senhatmp))
  1917.     registro = 1;
  1918.   if(!strcmp(senha1, senhatmp) && !strcmp(senha2, senhatmp))
  1919.     registro = 2;
  1920.   if(!strcmp(regnumber, ""))
  1921.     registro = 0;
  1922.  
  1923.   /* DOMINGO */
  1924.   strcpy(dom, LeRegistroDB("t:Freedom.Week", "1"));
  1925.   set(App->ValorDomingo, MUIA_Text_Contents, Corta(dom, '@', 0));
  1926.   set(App->PercentualDomingo, MUIA_Text_Contents, CasasAposCaracter(Corta(dom, '@', 1), '.', 1));
  1927.   set(App->TimeDomingo, MUIA_Text_Contents, SegundoHora(Corta(dom, '@', 2)));
  1928.   strcpy(teste2, CasasAposCaracter(Corta(dom, '@', 3), '.', atoi(precision)));
  1929.   if(moeda == 0)
  1930.     sprintf(teste, "%s%s", moedac, teste2);
  1931.   else
  1932.     sprintf(teste, "%s%s", teste2, moedac);
  1933.   if(registro < 2)
  1934.     strcpy(teste, "REALREG");
  1935.   set(App->CustoDomingo, MUIA_Text_Contents, teste);
  1936.  
  1937.   /* SEGUNDA */
  1938.   strcpy(seg, LeRegistroDB("t:Freedom.Week", "2"));
  1939.   set(App->ValorSegunda, MUIA_Text_Contents, Corta(seg, '@', 0));
  1940.   set(App->PercentualSegunda, MUIA_Text_Contents, CasasAposCaracter(Corta(seg, '@', 1), '.', 1));
  1941.   set(App->TimeSegunda, MUIA_Text_Contents, SegundoHora(Corta(seg, '@', 2)));
  1942.   strcpy(teste2, CasasAposCaracter(Corta(seg, '@', 3), '.', atoi(precision)));
  1943.   if(moeda == 0)
  1944.     sprintf(teste, "%s%s", moedac, teste2);
  1945.   else
  1946.     sprintf(teste, "%s%s", teste2, moedac);
  1947.   if(registro < 2)
  1948.     strcpy(teste, "REALREG");
  1949.   set(App->CustoSegunda, MUIA_Text_Contents, teste);
  1950.  
  1951.   /* TERCA */
  1952.   strcpy(ter, LeRegistroDB("t:Freedom.Week", "3"));
  1953.   set(App->ValorTerca, MUIA_Text_Contents, Corta(ter, '@', 0));
  1954.   set(App->PercentualTerca, MUIA_Text_Contents, CasasAposCaracter(Corta(ter, '@', 1), '.', 1));
  1955.   set(App->TimeTerca, MUIA_Text_Contents, SegundoHora(Corta(ter, '@', 2)));
  1956.   strcpy(teste2, CasasAposCaracter(Corta(ter, '@', 3), '.', atoi(precision)));
  1957.   if(moeda == 0)
  1958.     sprintf(teste, "%s%s", moedac, teste2);
  1959.   else
  1960.     sprintf(teste, "%s%s", teste2, moedac);
  1961.   if(registro < 2)
  1962.     strcpy(teste, "REALREG");
  1963.   set(App->CustoTerca, MUIA_Text_Contents, teste);
  1964.  
  1965.   /* QUARTA */
  1966.   strcpy(qua, LeRegistroDB("t:Freedom.Week", "4"));
  1967.   set(App->ValorQuarta, MUIA_Text_Contents, Corta(qua, '@', 0));
  1968.   set(App->PercentualQuarta, MUIA_Text_Contents, CasasAposCaracter(Corta(qua, '@', 1), '.', 1));
  1969.   set(App->TimeQuarta, MUIA_Text_Contents, SegundoHora(Corta(qua, '@', 2)));
  1970.   strcpy(teste2, CasasAposCaracter(Corta(qua, '@', 3), '.', atoi(precision)));
  1971.   if(moeda == 0)
  1972.     sprintf(teste, "%s%s", moedac, teste2);
  1973.   else
  1974.     sprintf(teste, "%s%s", teste2, moedac);
  1975.   if(registro < 2)
  1976.     strcpy(teste, "REALREG");
  1977.   set(App->CustoQuarta, MUIA_Text_Contents, teste);
  1978.  
  1979.   /* QUINTA */
  1980.   strcpy(qui, LeRegistroDB("t:Freedom.Week", "5"));
  1981.   set(App->ValorQuinta, MUIA_Text_Contents, Corta(qui, '@', 0));
  1982.   set(App->PercentualQuinta, MUIA_Text_Contents, CasasAposCaracter(Corta(qui, '@', 1), '.', 1));
  1983.   set(App->TimeQuinta, MUIA_Text_Contents, SegundoHora(Corta(qui, '@', 2)));
  1984.   strcpy(teste2, CasasAposCaracter(Corta(qui, '@', 3), '.', atoi(precision)));
  1985.   if(moeda == 0)
  1986.     sprintf(teste, "%s%s", moedac, teste2);
  1987.   else
  1988.     sprintf(teste, "%s%s", teste2, moedac);
  1989.   if(registro < 2)
  1990.     strcpy(teste, "REALREG");
  1991.   set(App->CustoQuinta, MUIA_Text_Contents, teste);
  1992.  
  1993.   /* SEXTA */
  1994.   strcpy(sex, LeRegistroDB("t:Freedom.Week", "6"));
  1995.   set(App->ValorSexta, MUIA_Text_Contents, Corta(sex, '@', 0));
  1996.   set(App->PercentualSexta, MUIA_Text_Contents, CasasAposCaracter(Corta(sex, '@', 1), '.', 1));
  1997.   set(App->TimeSexta, MUIA_Text_Contents, SegundoHora(Corta(sex, '@', 2)));
  1998.   strcpy(teste2, CasasAposCaracter(Corta(sex, '@', 3), '.', atoi(precision)));
  1999.   if(moeda == 0)
  2000.     sprintf(teste, "%s%s", moedac, teste2);
  2001.   else
  2002.     sprintf(teste, "%s%s", teste2, moedac);
  2003.   if(registro < 2)
  2004.     strcpy(teste, "REALREG");
  2005.   set(App->CustoSexta, MUIA_Text_Contents, teste);
  2006.  
  2007.   /* SABADO */
  2008.   strcpy(sab, LeRegistroDB("t:Freedom.Week", "0"));
  2009.   set(App->ValorSabado, MUIA_Text_Contents, Corta(sab, '@', 0));
  2010.   set(App->PercentualSabado, MUIA_Text_Contents, CasasAposCaracter(Corta(sab, '@', 1), '.', 1));
  2011.   set(App->TimeSabado, MUIA_Text_Contents, SegundoHora(Corta(sab, '@', 2)));
  2012.   strcpy(teste2, CasasAposCaracter(Corta(sab, '@', 3), '.', atoi(precision)));
  2013.   if(moeda == 0)
  2014.     sprintf(teste, "%s%s", moedac, teste2);
  2015.   else
  2016.     sprintf(teste, "%s%s", teste2, moedac);
  2017.   if(registro < 2)
  2018.     strcpy(teste, "REALREG");
  2019.   set(App->CustoSabado, MUIA_Text_Contents, teste);
  2020.  
  2021.   /* TOTAL */
  2022.   strcpy(tot, LeRegistroDB("t:Freedom.Week", "7"));
  2023.   set(App->ValorTotal, MUIA_Text_Contents, Corta(tot, '@', 0));
  2024.   set(App->TimeTotal, MUIA_Text_Contents, SegundoHora(Corta(tot, '@', 1)));
  2025.   set(App->PercentualTotal, MUIA_Text_Contents, "100");
  2026.   strcpy(teste2, CasasAposCaracter(Corta(tot, '@', 2), '.', atoi(precision)));
  2027.   if(moeda == 0)
  2028.     sprintf(teste, "%s%s", moedac, teste2);
  2029.   else
  2030.     sprintf(teste, "%s%s", teste2, moedac);
  2031.   if(registro < 2)
  2032.     strcpy(teste, "REALREG");
  2033.   set(App->CustoTotal, MUIA_Text_Contents, teste);
  2034.  
  2035.   strcpy(teste, LeRegistroDB("t:Freedom.Date", "date"));
  2036.   sprintf(teste2, "%s", teste);
  2037.   set(App->WeekLabelTop, MUIA_Text_Contents, teste2);
  2038.   return NULL;
  2039. }
  2040.  
  2041. APTR CarregaUltimasCinco( struct Hook *a0, APTR a2, APTR a1 )
  2042. {
  2043.   /* ESTA ROTINA CARREGA OS DADOS NA JANELA DAS ULTIMAS
  2044.      CINCO LIGACOES */
  2045.   char l1[256], l2[256], l3[256], l4[256], l5[256], horaon[30], dataon[30],
  2046.        *database, teste[256], data1[256], status1[30], *precision,
  2047.        status2[30], categoria[256], *categorydir, *categoryname, campo[256],
  2048.        data[256], login[256], tempo[256], *moedac, cost[30], diferenca[256],
  2049.        senha1[256], senha2[256], senhatmp[256], *regnumber2, 
  2050.        *regemail, *regnumber, *regname, *regorg, *regcountry,
  2051.        tempoon[30], telefone[30], connect[256];
  2052.   int x = 0, registro = 0;
  2053.   long moeda = 0;
  2054.  
  2055.   /* TESTA SE O DIRETORIO DA BASE DE DADOS EXISTE */
  2056.   get(App->DataBaseName, MUIA_String_Contents, &database);
  2057.   if(!ExisteDiretorio(database))
  2058.   {
  2059.      set(App->JanelaCincoLigacoes, MUIA_Window_Open, FALSE);
  2060.      MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg18), TMsg(App->Msg17));
  2061.      return NULL;
  2062.   }
  2063.  
  2064.   /* ROTINA QUE TESTA O TIPO DE REGISTRO */
  2065.   get(App->RegisterName, MUIA_String_Contents, ®name);
  2066.   get(App->RegisterOrganization, MUIA_String_Contents, ®org);
  2067.   get(App->RegisterEmail, MUIA_String_Contents, ®email);
  2068.   get(App->RegisterCountry, MUIA_String_Contents, ®country);
  2069.   get(App->RegisterKeyReal, MUIA_String_Contents, ®number2);
  2070.   get(App->RegisterKey, MUIA_String_Contents, ®number);
  2071.   strcpy(senha1, AsciiString(regnumber, 69));
  2072.   strcpy(senha2, AsciiString(regnumber2, 96));
  2073.   sprintf(senhatmp, "%s%s%s", regname, regemail, regcountry);
  2074.   strcpy(senhatmp, CriptografiaSimples(senhatmp, 0));
  2075.   if(!strcmp(senha1, senhatmp))
  2076.     registro = 1;
  2077.   if(!strcmp(senha1, senhatmp) && !strcmp(senha2, senhatmp))
  2078.     registro = 2;
  2079.   if(!strcmp(regnumber, ""))
  2080.     registro = 0;
  2081.  
  2082.   /* Rotina que limpa os campos antes da atribuicao */
  2083.   set(App->FirstData, MUIA_Text_Contents, "0");
  2084.   set(App->FirstLoginTime, MUIA_Text_Contents, "0");
  2085.   set(App->FirstTimeOnline, MUIA_Text_Contents, "0");
  2086.   set(App->FirstPhone, MUIA_Text_Contents, "0");
  2087.   set(App->FirstStatus, MUIA_Text_Contents, "");
  2088.   set(App->SecondData, MUIA_Text_Contents, "0");
  2089.   set(App->SecondLoginTime, MUIA_Text_Contents, "0");
  2090.   set(App->SecondTimeOnline, MUIA_Text_Contents, "0");
  2091.   set(App->SecondPhone, MUIA_Text_Contents, "0");
  2092.   set(App->SecondStatus, MUIA_Text_Contents, "");
  2093.   set(App->ThirdData, MUIA_Text_Contents, "0");
  2094.   set(App->ThirdLoginTime, MUIA_Text_Contents, "0");
  2095.   set(App->ThirdTimeOnline, MUIA_Text_Contents, "0");
  2096.   set(App->ThirdPhone, MUIA_Text_Contents, "0");
  2097.   set(App->ThirdStatus, MUIA_Text_Contents, "");
  2098.   set(App->FourthData, MUIA_Text_Contents, "0");
  2099.   set(App->FourthLoginTime, MUIA_Text_Contents, "0");
  2100.   set(App->FourthTimeOnline, MUIA_Text_Contents, "0");
  2101.   set(App->FourthPhone, MUIA_Text_Contents, "0");
  2102.   set(App->FourthStatus, MUIA_Text_Contents, "");
  2103.   set(App->LastData, MUIA_Text_Contents, "0");
  2104.   set(App->LastLoginTime, MUIA_Text_Contents, "0");
  2105.   set(App->LastTimeOnline, MUIA_Text_Contents, "0");
  2106.   set(App->LastPhone, MUIA_Text_Contents, "0");
  2107.   set(App->LastStatus, MUIA_Text_Contents, "");
  2108.   set(App->FirstCost, MUIA_Text_Contents, "0");
  2109.   set(App->SecondCost, MUIA_Text_Contents, "0");
  2110.   set(App->ThirdCost, MUIA_Text_Contents, "0");
  2111.   set(App->FourthCost, MUIA_Text_Contents, "0");
  2112.   set(App->LastCost, MUIA_Text_Contents, "0");
  2113.   set(App->UpdateCall, MUIA_Text_Contents, "");
  2114.  
  2115.   strcpy(status1, TMsg(App->Msg54));
  2116.   strcpy(status2, TMsg(App->Msg55));
  2117.  
  2118.   strcpy(data1, DataHora(0));
  2119.   /* PREPARA O ARQUIVO A SER LIDO */
  2120.   for(x = 0; x < 25; x++)
  2121.   {
  2122.     sprintf(teste, "%s/Freedom.%s", database, AposCaracter(data1, '.', 1));
  2123.     if(ExisteArquivo(teste))
  2124.       break;
  2125.     strcpy(data1, ArrumaDataHora(SomaDiminuiMes(data1, -1), '.'));
  2126.   }
  2127.   if(x == 25)
  2128.   {
  2129.     set(App->JanelaCincoLigacoes, MUIA_Window_Open, FALSE);
  2130.     /* FREEDOM LAST CALLS NOT FOUND */
  2131.     MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg18), TMsg(App->Msg39));
  2132.     return NULL;
  2133.   }
  2134.   sprintf(teste, "%s/Freedom.%s", database, AposCaracter(data1, '.', 1));
  2135.   FinalArquivo(teste, "t:Freedom.Five", 5);
  2136.  
  2137.   /* SO LIBERA CONSULTA SE EXISTE 5 ULTIMAS LIGACOES */
  2138.   if(LinhasArquivo("T:Freedom.Five") < 5)
  2139.   {
  2140.     remove("t:Freedom.Five");
  2141.     set(App->JanelaCincoLigacoes, MUIA_Window_Open, FALSE);
  2142.     MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg18), TMsg(App->Msg56));
  2143.     return NULL;
  2144.   }
  2145.   /* PEGA INFORMACOES DA MOEDA CORRENTE */
  2146.   get(App->ComboMoeda, MUIA_Cycle_Active, &moeda);
  2147.   get(App->NomeMoeda, MUIA_String_Contents, &moedac);
  2148.  
  2149.   /* PEGA A PRECISAO DOS DISPLAYS DE VALORES */
  2150.   get(App->ConfPrecision, MUIA_String_Contents, &precision);
  2151.  
  2152.   get(App->CategDiretorio, MUIA_String_Contents, &categorydir);
  2153.   get(App->TextDefault, MUIA_Text_Contents, &categoryname);
  2154.   sprintf(categoria, "%s/%s", categorydir, categoryname);
  2155.  
  2156.   strcpy(l1, LinhaNumero("t:Freedom.Five", 1));
  2157.   strcpy(l2, LinhaNumero("t:Freedom.Five", 2));
  2158.   strcpy(l3, LinhaNumero("t:Freedom.Five", 3));
  2159.   strcpy(l4, LinhaNumero("t:Freedom.Five", 4));
  2160.   strcpy(l5, LinhaNumero("t:Freedom.Five", 5));
  2161.   
  2162.   /* PRIMEIRA LIGACAO */
  2163.   strcpy(data, Corta(l1, ',', 1));
  2164.   strcpy(login, Corta(l1, ',', 2));
  2165.   strcpy(tempo, Corta(l1, ',', 6));
  2166.   set(App->FirstData, MUIA_Text_Contents, data);
  2167.   set(App->FirstLoginTime, MUIA_Text_Contents, SegundoHora(login));
  2168.   set(App->FirstTimeOnline, MUIA_Text_Contents, SegundoHora(tempo));
  2169.   strcpy(teste, CalculaPrecoFREE(categoria, atoi(login), atoi(Corta(l1, ',', 4)), atoi(DiaSemanaFREE(data, 2))));
  2170.   strcpy(teste, CasasAposCaracter(teste, '.', atoi(precision)));
  2171.   if(moeda == 0)
  2172.     sprintf(cost, "%s%s", moedac, teste);
  2173.   else
  2174.     sprintf(cost, "%s%s", teste, moedac);
  2175.   set(App->FirstCost, MUIA_Text_Contents, cost);
  2176.  
  2177.   set(App->FirstPhone, MUIA_Text_Contents, Corta(l1, ',', 0));
  2178.   if(!(strcmp(Corta(l1, ',', 5), "Act")))
  2179.     set(App->FirstStatus, MUIA_Text_Contents, status1);
  2180.   else
  2181.     set(App->FirstStatus, MUIA_Text_Contents, status2);
  2182.  
  2183.   /* SEGUNDA LIGACAO */
  2184.   strcpy(data, Corta(l2, ',', 1));
  2185.   strcpy(login, Corta(l2, ',', 2));
  2186.   strcpy(tempo, Corta(l2, ',', 6));
  2187.   set(App->SecondData, MUIA_Text_Contents, data);
  2188.   set(App->SecondLoginTime, MUIA_Text_Contents, SegundoHora(login));
  2189.   set(App->SecondTimeOnline, MUIA_Text_Contents, SegundoHora(tempo));
  2190.   strcpy(teste, CalculaPrecoFREE(categoria, atoi(login), atoi(Corta(l2, ',', 4)), atoi(DiaSemanaFREE(data, 2))));
  2191.   strcpy(teste, CasasAposCaracter(teste, '.', atoi(precision)));
  2192.   if(moeda == 0)
  2193.     sprintf(cost, "%s%s", moedac, teste);
  2194.   else
  2195.     sprintf(cost, "%s%s", teste, moedac);
  2196.   set(App->SecondCost, MUIA_Text_Contents, cost);
  2197.   set(App->SecondPhone, MUIA_Text_Contents, Corta(l2, ',', 0));
  2198.   if(!(strcmp(Corta(l2, ',', 5), "Act")))
  2199.     set(App->SecondStatus, MUIA_Text_Contents, status1);
  2200.   else
  2201.     set(App->SecondStatus, MUIA_Text_Contents, status2);
  2202.  
  2203.   /* TERCEIRA LIGACAO */
  2204.   strcpy(data, Corta(l3, ',', 1));
  2205.   strcpy(login, Corta(l3, ',', 2));
  2206.   strcpy(tempo, Corta(l3, ',', 6));
  2207.   set(App->ThirdData, MUIA_Text_Contents, data);
  2208.   set(App->ThirdLoginTime, MUIA_Text_Contents, SegundoHora(login));
  2209.   set(App->ThirdTimeOnline, MUIA_Text_Contents, SegundoHora(tempo));
  2210.   strcpy(teste, CalculaPrecoFREE(categoria, atoi(login), atoi(Corta(l3, ',', 4)), atoi(DiaSemanaFREE(data, 2))));
  2211.   strcpy(teste, CasasAposCaracter(teste, '.', atoi(precision)));
  2212.   if(moeda == 0)
  2213.     sprintf(cost, "%s%s", moedac, teste);
  2214.   else
  2215.     sprintf(cost, "%s%s", teste, moedac);
  2216.   set(App->ThirdCost, MUIA_Text_Contents, cost);
  2217.   set(App->ThirdPhone, MUIA_Text_Contents, Corta(l3, ',', 0));
  2218.   if(!(strcmp(Corta(l3, ',', 5), "Act")))
  2219.     set(App->ThirdStatus, MUIA_Text_Contents, status1);
  2220.   else
  2221.     set(App->ThirdStatus, MUIA_Text_Contents, status2);
  2222.  
  2223.   /* QUARTA LIGACAO */
  2224.   strcpy(data, Corta(l4, ',', 1));
  2225.   strcpy(login, Corta(l4, ',', 2));
  2226.   strcpy(tempo, Corta(l4, ',', 6));
  2227.   set(App->FourthData, MUIA_Text_Contents, data);
  2228.   set(App->FourthLoginTime, MUIA_Text_Contents, SegundoHora(login));
  2229.   set(App->FourthTimeOnline, MUIA_Text_Contents, SegundoHora(tempo));
  2230.   strcpy(teste, CalculaPrecoFREE(categoria, atoi(login), atoi(Corta(l4, ',', 4)), atoi(DiaSemanaFREE(data, 2))));
  2231.   strcpy(teste, CasasAposCaracter(teste, '.', atoi(precision)));
  2232.   if(moeda == 0)
  2233.     sprintf(cost, "%s%s", moedac, teste);
  2234.   else
  2235.     sprintf(cost, "%s%s", teste, moedac);
  2236.   set(App->FourthCost, MUIA_Text_Contents, cost);
  2237.   set(App->FourthPhone, MUIA_Text_Contents, Corta(l4, ',', 0));
  2238.   if(!(strcmp(Corta(l4, ',', 5), "Act")))
  2239.     set(App->FourthStatus, MUIA_Text_Contents, status1);
  2240.   else
  2241.     set(App->FourthStatus, MUIA_Text_Contents, status2);
  2242.  
  2243.   /* ULTIMA LIGACAO */
  2244.   strcpy(data, Corta(l5, ',', 1));
  2245.   strcpy(login, Corta(l5, ',', 2));
  2246.   strcpy(tempo, Corta(l5, ',', 6));
  2247.   set(App->LastData, MUIA_Text_Contents, data);
  2248.   set(App->LastLoginTime, MUIA_Text_Contents, SegundoHora(login));
  2249.   set(App->LastTimeOnline, MUIA_Text_Contents, SegundoHora(tempo));
  2250.   strcpy(teste, CalculaPrecoFREE(categoria, atoi(login), atoi(Corta(l5, ',', 4)), atoi(DiaSemanaFREE(data, 2))));
  2251.   strcpy(teste, CasasAposCaracter(teste, '.', atoi(precision)));
  2252.   if(moeda == 0)
  2253.     sprintf(cost, "%s%s", moedac, teste);
  2254.   else
  2255.     sprintf(cost, "%s%s", teste, moedac);
  2256.   set(App->LastCost, MUIA_Text_Contents, cost);
  2257.   set(App->LastPhone, MUIA_Text_Contents, Corta(l5, ',', 0));
  2258.   if(!(strcmp(Corta(l5, ',', 5), "Act")))
  2259.     set(App->LastStatus, MUIA_Text_Contents, status1);
  2260.   else
  2261.     set(App->LastStatus, MUIA_Text_Contents, status2);
  2262.  
  2263.   remove("t:Freedom.Five");
  2264.  
  2265.   /* ROTINA QUE CARREGA O STATUS DA LIGACAO ATUAL */
  2266.   if(!Conectado()) {
  2267.     /* NOT CONNECTED... */
  2268.     set(App->UpdateCall, MUIA_Text_Contents, TMsg(App->Msg89));
  2269.     return NULL; }
  2270.  
  2271.   if(!ExisteArquivo("S:Freedom.Miami.Temp")) {
  2272.     /* FREEEVENTMIAMI LOG NOT FOUND */
  2273.     set(App->UpdateCall, MUIA_Text_Contents, TMsg(App->Msg90));
  2274.     return NULL; }
  2275.  
  2276.   strcpy(campo, LeRegistroDB("s:Freedom.Miami.Temp", "1"));
  2277.   strcpy(horaon, Corta(campo, ',', 2));
  2278.   strcpy(dataon, Corta(campo, ',', 1));
  2279.   strcpy(telefone, Corta(campo, ',', 0));
  2280.   strcpy(connect, Corta(campo, ',', 3));
  2281.   if(!strcmp(connect, "CUTERRO"))
  2282.     strcpy(connect, "");
  2283.  
  2284.   /* CONNECT */
  2285.   sprintf(teste, "%s [\033b%s %s\033n]", TMsg(App->Msg91), dataon, SegundoHora(horaon));
  2286.   strcpy(tempoon, IntervaloHora(horaon, HoraSegundo(DataHora(5))));
  2287.  
  2288.   /* VERIFICA SE PASSOU DA MEIA NOITE A LIGACAO ATUAL */
  2289.   strcpy(diferenca, Corta(DiferencaDias(dataon, DataHora(0)), ':', 1));
  2290.   if(atoi(diferenca) > 0)
  2291.     sprintf(tempoon, "%ld", atoi(diferenca) - atoi(tempoon));
  2292.  
  2293.   /* CALCULA O CUSTO DA LIGACAO */
  2294.   strcpy(l1, CalculaPrecoFREE(categoria, atoi(horaon), atoi(HoraSegundo(DataHora(5))), atoi(DiaSemanaFREE(DataHora(0), 2))));
  2295.   strcpy(l1, CasasAposCaracter(l1, '.', atoi(precision)));
  2296.   if(moeda == 0)
  2297.     sprintf(cost, "%s%s", moedac, l1);
  2298.   else
  2299.     sprintf(cost, "%s%s", l1, moedac);
  2300.   if(registro < 2)
  2301.     strcpy(cost, "REALREG");
  2302.  
  2303.   /* ONLINE, COST */
  2304.   sprintf(teste, "%s, %s [\033b%s\033n], %s [\033b%s\033n]\n \0338[%s] %s\033n", teste, TMsg(App->Msg92), SegundoHora(tempoon), TMsg(App->Msg93), cost, telefone, connect);
  2305.   set(App->UpdateCall, MUIA_Text_Contents, teste);
  2306.   MUI_Redraw(App->UpdateCall, MADF_DRAWOBJECT);
  2307.   return NULL;
  2308. }
  2309.  
  2310. APTR TestaRegistro2( struct Hook *a0, APTR a2, APTR a1 )
  2311. {
  2312.   /* ROTINA QUE TESTA SE O PROGRAMA ESTA REGISTRADO OU NAO,
  2313.      PARA CARREGAMENTO DA JANELA "MANUAL CALL INPUTATION" */
  2314.   char teste[500], nopay[20], senha[500],
  2315.        *regemail, *regnumber, *regname, *regcountry;
  2316.   get(App->RegisterKey, MUIA_String_Contents, ®number);
  2317.   get(App->RegisterName, MUIA_String_Contents, ®name);
  2318.   get(App->RegisterEmail, MUIA_String_Contents, ®email);
  2319.   get(App->RegisterCountry, MUIA_String_Contents, ®country);
  2320.  
  2321.   sprintf(teste, "%s%s%s", regname, regemail, regcountry);
  2322.   strcpy(teste, CriptografiaSimples(teste, 0));
  2323.  
  2324.   strcpy(nopay, Corta(AsciiString(regnumber, 69), 'Ã¥', 1));
  2325.   strcpy(senha, AsciiString(regnumber, 69));
  2326.   strcpy(senha, Corta(senha, 'Ã¥', 0));
  2327.  
  2328.   if(strcmp(teste, senha) || !strcmp(regnumber, ""))
  2329.   {
  2330.     MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg18), TMsg(App->Msg60));
  2331.     return NULL;
  2332.   }
  2333.   set(App->JanelaDeInputManual, MUIA_Window_Open, TRUE);
  2334.   return NULL;
  2335. }
  2336.  
  2337. APTR SalvaNovoInput( struct Hook *a0, APTR a2, APTR a1 )
  2338. {
  2339.   /* ESTA FUNCAO PREPARA, CALCULA E TESTA TODOS OS DADOS PARA
  2340.      ENVIAR PARA A JANELA DE CONFIRMACAO E GRAVACAO DO INPUT
  2341.      MANUAL. */
  2342.   char *phone, *datelogin, *hourlogin, *timeonline, *select,
  2343.        hor1[3], hor2[3], min1[3], min2[3], seg1[3], seg2[3],
  2344.        dia[3], mes[3], ano[5], teste[256];
  2345.  
  2346.   /* TESTA SE O CAMPO DE TELEFONE ESTA EM BRANCO */
  2347.   get(App->LabelInputPhone, MUIA_String_Contents, &phone);
  2348.   if(!(strcmp(phone, "")))
  2349.   {
  2350.     /* PHONE NUMBER IS INVALID */
  2351.     MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg18), TMsg(App->Msg40));
  2352.     return NULL;
  2353.   }
  2354.  
  2355.   get(App->LabelInputDateLogin, MUIA_String_Contents, &datelogin);
  2356.   get(App->LabelInputHourLogin, MUIA_String_Contents, &hourlogin);
  2357.   get(App->LabelInputTimeOnline, MUIA_String_Contents, &timeonline);
  2358.  
  2359.   /* SEPARA EM VARIAVEIS HORA, MINUTO, SEGUNDO, DIA, MES, ANO */
  2360.   strcpy(hor1, Copia2(hourlogin, 1, 2));
  2361.   strcpy(hor2, Copia2(timeonline, 1, 2));
  2362.   strcpy(min1, Copia2(hourlogin, 4, 2));
  2363.   strcpy(min2, Copia2(timeonline, 4, 2));
  2364.   strcpy(seg1, Copia2(hourlogin, 7, 2));
  2365.   strcpy(seg2, Copia2(timeonline, 7, 2));
  2366.   strcpy(dia, Copia2(datelogin, 1, 2));
  2367.   strcpy(mes, Copia2(datelogin, 4, 2));
  2368.   strcpy(ano, Copia2(datelogin, 7, 4));
  2369.  
  2370.   /* INICIA OS TESTES DE VALIDADE DE HORA E DATA */
  2371.   if((strlen(hourlogin) != 8) ||
  2372.      (strlen(timeonline) != 8))
  2373.   {
  2374.     /* FORMAT TIME IS INVALID */
  2375.     MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg18), TMsg(App->Msg41));
  2376.     return NULL;
  2377.   }
  2378.   if((atoi(hor1) < 0 || atoi(hor1) > 23) ||
  2379.      (atoi(hor2) < 0))
  2380.   {
  2381.     /* HOUR IS INVALID */
  2382.     MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg18), TMsg(App->Msg42));
  2383.     return NULL;
  2384.   }
  2385.   if((atoi(min1) < 0 || atoi(min1) > 60) ||
  2386.      (atoi(min2) < 0 || atoi(min2) > 60))
  2387.   {
  2388.     /* MINUTES IS INVALID */
  2389.     MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg18), TMsg(App->Msg43));
  2390.     return NULL;
  2391.   }
  2392.   if((atoi(seg1) < 0 || atoi(seg1) > 60) ||
  2393.      (atoi(seg2) < 0 || atoi(seg2) > 60))
  2394.   {
  2395.     /* SECONDS IS INVALID */
  2396.     MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg18), TMsg(App->Msg44));
  2397.     return NULL;
  2398.   }
  2399.  
  2400.   if(!TestaData(datelogin))
  2401.   {
  2402.     /* DATE IS INVALID */
  2403.     MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg18), TMsg(App->Msg45));
  2404.     return NULL;
  2405.   }
  2406.   if(!(strcmp(timeonline, "00:00:00")))
  2407.   {
  2408.     /* TIME ONLINE IS NULL */
  2409.     MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg18), TMsg(App->Msg46));
  2410.     return NULL;
  2411.   }
  2412.  
  2413.   set(App->JanelaDeInputManual, MUIA_Window_Open, FALSE);
  2414.   set(App->JanelaInputSalvaValores, MUIA_Window_Open, TRUE);
  2415.   strcpy(teste, Online(datelogin, hourlogin, timeonline));
  2416.  
  2417.   set(App->Input2Phone, MUIA_Text_Contents, phone);
  2418.   set(App->Input2DateLogin, MUIA_Text_Contents, JulianoDia(Corta(teste, '@', 0)));
  2419.   set(App->Input2DateLogout, MUIA_Text_Contents, JulianoDia(Corta(teste, '@', 1)));
  2420.   set(App->Input2TimeLogin, MUIA_Text_Contents, SegundoHora(Corta(teste, '@', 2)));
  2421.   set(App->Input2TimeLogout, MUIA_Text_Contents, SegundoHora(Corta(teste, '@', 3)));
  2422.   set(App->Input2TimeOnline, MUIA_Text_Contents, SegundoHora(Corta(teste, '@', 4)));
  2423.  
  2424.   get(App->ComboStatusInput, MUIA_Text_Contents, &select);
  2425.   set(App->Input2Status, MUIA_Text_Contents, select);
  2426.   return NULL;
  2427. }
  2428.  
  2429. APTR SalvaInputManual( struct Hook *a0, APTR a2, APTR a1 )
  2430. {
  2431.   /* ESTA FUNCAO SALVA OS DADOS DA JANELA DE INPUT MANUAL */
  2432.   char *phone, *datelogin, *datelogout, *timelogin, *timeonline,
  2433.        *select, *timelogout, status[10], h1[256], h2[256],
  2434.        h3[256], teste[256], *database, teste2[256];
  2435.   long combo;
  2436.  
  2437.   /* TESTA SE O DIRETORIO DA BASE DE DADOS EXISTE */
  2438.   get(App->DataBaseName, MUIA_String_Contents, &database);
  2439.   if(!ExisteDiretorio(database))
  2440.   {
  2441.      MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg18), TMsg(App->Msg17));
  2442.      return NULL;
  2443.   }
  2444.   get(App->Input2Phone, MUIA_Text_Contents, &phone);
  2445.   get(App->Input2DateLogin, MUIA_Text_Contents, &datelogin);
  2446.   get(App->Input2DateLogout, MUIA_Text_Contents, &datelogout);
  2447.   get(App->Input2TimeLogin, MUIA_Text_Contents, &timelogin);
  2448.   get(App->Input2TimeOnline, MUIA_Text_Contents, &timeonline);
  2449.   get(App->Input2TimeLogout, MUIA_Text_Contents, &timelogout);
  2450.   get(App->ComboStatusInput, MUIA_Text_Contents, &select);
  2451.  
  2452.   /* PEGA O NUMERO DA POSICAO DO COMBO DE DIA, MES, ANO */
  2453.   get(App->ComboStatusInput, MUIA_Cycle_Active, &combo);
  2454.  
  2455.   if(combo == 0)
  2456.     strcpy(status, "Act");
  2457.   else
  2458.     strcpy(status, "Pas");
  2459.  
  2460.   strcpy(h1, HoraSegundo(timelogin));
  2461.   strcpy(h2, HoraSegundo(timelogout));
  2462.   strcpy(h3, HoraSegundo(timeonline));
  2463.  
  2464.   sprintf(teste, "%s,%s,%s,%s,%s,%s,%s,Input\n", phone, datelogin, h1, datelogout, h2, status, h3);
  2465.   sprintf(teste2, "%s/Freedom.%s", database, AposCaracter(datelogin, '.', 1));
  2466.   GravaLinha(teste2, teste, "a");
  2467.   sprintf(teste2, "%s/Freedom.Input", database);
  2468.   GravaLinha(teste2, teste, "a");
  2469.  
  2470.   /* NEW CALL ADDED IN FREEDOM DATABASE */
  2471.   MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg18), TMsg(App->Msg47));
  2472.   return NULL;
  2473. }
  2474.  
  2475. APTR PreparaOutroMesTodas( struct Hook *a0, APTR a2, APTR a1 )
  2476. {
  2477.   /* ESTA FUNCAO PREPARA O ARQUIVO DE LEITURA PARA AS INFORMACOES
  2478.      DA JANELA ALL CALLS. PARA CONSULTAS DE ESSE E OUTRO MES. */
  2479.   char teste2[256], saida[256], a, teste[256], status[30], gauge[30],
  2480.        dia[20], login[20], online[20], fone[30], cost[30], *moedac,
  2481.        *precision, senha1[256], senha2[256], senhatmp[256], *regnumber2,
  2482.        *regemail, *regnumber, *regname, *regorg, *regcountry, sem[256];
  2483.   float totalarq = 0, gaugep = 0, registro = 0;
  2484.   long moeda = 0;
  2485.   int x = 0;
  2486.   FILE *entrada, *saidaarq;
  2487.  
  2488.   set(App->GaugeTodasLigacoes, MUIA_Gauge_InfoText, TMsg(App->Msg25));
  2489.   DoMethod(App->ListTodasLigacoes, MUIM_List_Clear);
  2490.   totalarq   = LinhasArquivo("T:Freedom.InTmp");
  2491.  
  2492.   if((!(entrada = fopen("T:Freedom.InTmp", "r"))) ||
  2493.      (!(saidaarq= fopen("T:Freedom.InAll", "w"))))
  2494.   {
  2495.     /* FREEDOM TEMPORARY FILE NOT FOUND */
  2496.     MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg18), TMsg(App->Msg48));
  2497.     return NULL;
  2498.   }
  2499.   /* PEGA INFORMACOES DA MOEDA CORRENTE */
  2500.   get(App->ComboMoeda, MUIA_Cycle_Active, &moeda);
  2501.   get(App->NomeMoeda, MUIA_String_Contents, &moedac);
  2502.  
  2503.   /* PEGA A PRECISAO DOS DISPLAYS DE VALORES */
  2504.   get(App->ConfPrecision, MUIA_String_Contents, &precision);
  2505.  
  2506.   /* ROTINA QUE TESTA O TIPO DE REGISTRO */
  2507.   get(App->RegisterName, MUIA_String_Contents, ®name);
  2508.   get(App->RegisterOrganization, MUIA_String_Contents, ®org);
  2509.   get(App->RegisterEmail, MUIA_String_Contents, ®email);
  2510.   get(App->RegisterCountry, MUIA_String_Contents, ®country);
  2511.   get(App->RegisterKeyReal, MUIA_String_Contents, ®number2);
  2512.   get(App->RegisterKey, MUIA_String_Contents, ®number);
  2513.   strcpy(senha1, AsciiString(regnumber, 69));
  2514.   strcpy(senha2, AsciiString(regnumber2, 96));
  2515.   sprintf(senhatmp, "%s%s%s", regname, regemail, regcountry);
  2516.   strcpy(senhatmp, CriptografiaSimples(senhatmp, 0));
  2517.   if(!strcmp(senha1, senhatmp))
  2518.     registro = 1;
  2519.   if(!strcmp(senha1, senhatmp) && !strcmp(senha2, senhatmp))
  2520.     registro = 2;
  2521.   if(!strcmp(regnumber, ""))
  2522.     registro = 0;
  2523.  
  2524.   x = 0; gaugep = 0;
  2525.   while(a = getc(entrada), ! feof(entrada))
  2526.   {
  2527.     teste[x++] = a;
  2528.     if(a == '\n')
  2529.     {
  2530.       teste[--x] = '\0';
  2531.  
  2532.       if(!(strcmp(Corta(teste, ',', 5), "Act"))) {
  2533.         /* REGULAR */
  2534.         strcpy(status, TMsg(App->Msg54));
  2535.       } else {
  2536.         /* IRREGULAR */
  2537.         strcpy(status, TMsg(App->Msg55)); }
  2538.  
  2539.       strcpy(dia,    Corta(teste, ',', 1));
  2540.       strcpy(sem,    DiaSemanaFREE(dia, 1));
  2541.       strcpy(login,  Corta(teste, ',', 2));
  2542.       strcpy(online, Corta(teste, ',', 6));
  2543.       strcpy(fone,   EspacoString(Corta(teste, ',', 0), 12, 1));
  2544.  
  2545.       /* LE O VALOR DA LIGACAO */
  2546.       strcpy(cost, Corta(teste, ',', 8));
  2547.       strcpy(teste2, CasasAposCaracter(cost, '.', atoi(precision)));
  2548.       if(moeda == 0)
  2549.         sprintf(cost, "%s%s", moedac, teste2);
  2550.       else
  2551.         sprintf(cost, "%s%s", teste2, moedac);
  2552.       if(registro < 2)
  2553.         strcpy(cost, "REALREG");
  2554.  
  2555.       strcpy(login,  SegundoHora(login));
  2556.       strcpy(online, SegundoHora(online));
  2557.  
  2558.       /* ACERTA OS TAMANHOS DOS CAMPOS */
  2559.       strcpy(dia,    EspacoString(dia, 12, 1));
  2560.       strcpy(login,  EspacoString(login, 10, 1));
  2561.       strcpy(online, EspacoString(online, 10, 1));
  2562.       strcpy(cost,   EspacoString(cost, 12, 1));
  2563.  
  2564.       /* GERA O ARQUIVO DE SAIDA */
  2565.       sprintf(saida, "\033b%s\033n%s\033b%s\033n%s\033b%s\033n\0338 %s (%s)\033n\n", dia, login, online, fone, cost, status, sem);
  2566.       fprintf(saidaarq, "%s", saida);
  2567.  
  2568.       teste[0] = '\0'; x = 0;
  2569.       gaugep++;
  2570.       sprintf(gauge, "%f", ((100 / totalarq) * gaugep));
  2571.       set(App->GaugeTodasLigacoes, MUIA_Gauge_Current, atoi(gauge));
  2572.     }
  2573.   }
  2574.   fclose(entrada);
  2575.   fclose(saidaarq);
  2576.  
  2577.   /* CARREGA DO ARQUIVO PARA A LISTA */
  2578.   CarregaLista(App->ListTodasLigacoes, "T:Freedom.InAll");
  2579.   remove("T:Freedom.InAll");
  2580.   /* LOADED */
  2581.   set(App->GaugeTodasLigacoes, MUIA_Gauge_InfoText, TMsg(App->Msg78));
  2582.  
  2583.   return NULL;
  2584. }
  2585.  
  2586. APTR TestaConfiguracao( struct Hook *a0, APTR a2, APTR a1 )
  2587. {
  2588.   /* ESTA FUNCAO TESTA A VALIDADE DOS CAMPOS NA JANELA DE
  2589.      CONFIGURACAO. EVENTO DOS BOTOES DE SAVE, USE, E CLOSE REQUEST */
  2590.   char teste[256],
  2591.        *mes, *hora1, *hora2, *database, *categorydir, *precision;
  2592.   int x = 0;
  2593.   long menu = 0;
  2594.  
  2595.   get(App->PrefsDiaInicial, MUIA_String_Contents, &mes);
  2596.   get(App->PrefsFreeHInicio, MUIA_String_Contents, &hora1);
  2597.   get(App->PrefsFreeHFim, MUIA_String_Contents, &hora2);
  2598.   get(App->DataBaseName, MUIA_String_Contents, &database);
  2599.   get(App->CategDiretorio, MUIA_String_Contents, &categorydir);
  2600.   get(App->PrefsComboMenu, MUIA_Cycle_Active, &menu);
  2601.  
  2602.   /* VERIFICA A JANELA PRINCIPAL CERTA A ABRIR (STAND, GRAPHIC) */
  2603.   if(menu == 0) {
  2604.     set(App->JanelaPrincipal, MUIA_Window_Open, FALSE);
  2605.     set(App->JanelaPrincipal2, MUIA_Window_Open, TRUE);
  2606.   } else {
  2607.     set(App->JanelaPrincipal2, MUIA_Window_Open, FALSE);
  2608.     set(App->JanelaPrincipal, MUIA_Window_Open, TRUE);
  2609.   }
  2610.  
  2611.   /* TESTA SE O LOGO EXISTE */
  2612.   if(!ExisteArquivo("Freedom:Images/Freelogo.iff"))
  2613.   {
  2614.     /* FREEDOM:IMAGES/FREELOGO.IFF NOT FOUND */
  2615.     MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg18), TMsg(App->Msg58));
  2616.   }
  2617.   /* TESTA SE EXISTE TODOS OS BOTOES DO MENU PRINCIPAL */
  2618.   if(!ExisteArquivo("Freedom:Images/About.iff") ||
  2619.      !ExisteArquivo("Freedom:Images/Global.iff") ||
  2620.      !ExisteArquivo("Freedom:Images/LastC.iff") ||
  2621.      !ExisteArquivo("Freedom:Images/Other.iff") ||
  2622.      !ExisteArquivo("Freedom:Images/Prefs.iff") ||
  2623.      !ExisteArquivo("Freedom:Images/Costs.iff") ||
  2624.      !ExisteArquivo("Freedom:Images/Anual.iff") ||
  2625.      !ExisteArquivo("Freedom:Images/This.iff"))
  2626.   {
  2627.     /* FREEDOM IMAGE BUTTONS NOT FOUND */
  2628.     MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg18), TMsg(App->Msg59));
  2629.   }
  2630.  
  2631.   /* TESTA DIRETORIO DA BASE DE DADOS */
  2632.   set(App->DataBaseName, MUIA_String_Contents, FiltraDir(database, 0));
  2633.   if(!strcmp(UltimoCaracter(database), ":"))
  2634.   {
  2635.     set(App->DataBaseName, MUIA_String_Contents, "Freedom:FDataBase");
  2636.     /* FREEDOM DATABASE DIR IS WRONG, NOT POSSIBLE DEVICE */
  2637.     MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg18), TMsg(App->Msg50));
  2638.   }  
  2639.   /* VERIFICA SE O DIRETORIO DA BASE EXISTE */
  2640.   if(!ExisteDiretorio(database))
  2641.   {
  2642.     /* FREEDOM DATABASE NOT FOUND, CREATED? */
  2643.     sprintf(teste, "\033c%s\n\0338[%s]", TMsg(App->Msg30), database);
  2644.     /* CREATE DIRECTORY, CANCEL */
  2645.     x = MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg33), teste);
  2646.     if(x == 1)
  2647.     {
  2648.       mkdir(database);
  2649.       /* FREEDOM DATABASE CREATED */
  2650.       sprintf(teste, "\033c%s \0338[%s]", TMsg(App->Msg27), database);
  2651.       MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg18), teste);
  2652.     }
  2653.   }
  2654.  
  2655.   /* FAZ CONSISTENCIA DO TAMANHO DO CAMPO HORA */
  2656.   if(!TestaHora(hora1) ||
  2657.      !TestaHora(hora2))
  2658.   {
  2659.     /* FORMAT TIME IS INVALID */
  2660.     MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg18), TMsg(App->Msg41));
  2661.     set(App->PrefsFreeHInicio, MUIA_String_Contents, "00:00:00");
  2662.     set(App->PrefsFreeHFim, MUIA_String_Contents, "00:00:00");
  2663.     return NULL;
  2664.   }
  2665.   if(atoi(mes) < 1 || atoi(mes) > 31)
  2666.   {
  2667.     /* INITIAL DAY IS INVALID */
  2668.     MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg18), TMsg(App->Msg49));
  2669.     set(App->PrefsDiaInicial, MUIA_String_Contents, "1");
  2670.   }
  2671.  
  2672.   /* TESTA DIRETORIO DAS CATEGORIAS */
  2673.   set(App->CategDiretorio, MUIA_String_Contents, FiltraDir(categorydir, 0));
  2674.   if(!strcmp(UltimoCaracter(categorydir), ":"))
  2675.   {
  2676.     set(App->CategDiretorio, MUIA_String_Contents, "Freedom:Categories");
  2677.     /* FREEDOM CATEGORIES DIR IS WRONG, NOT POSSIBLE DEVICE */
  2678.     MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg18), TMsg(App->Msg71));
  2679.   }  
  2680.   /* VERIFICA SE O DIRETORIO DAS CATEGORIAS EXISTE */
  2681.   if(!ExisteDiretorio(categorydir))
  2682.   {
  2683.     /* FREEDOM CATEGORIE NOT FOUND, CREATE? */
  2684.     sprintf(teste, "\033c%s\n\0338[%s]", TMsg(App->Msg66), categorydir);
  2685.     /* CREATE DIRECTORY, CANCEL */
  2686.     x = MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg33), teste);
  2687.     if(x == 1)
  2688.     {
  2689.       mkdir(categorydir);
  2690.       /* FREEDOM CATEGORIE DIRECTORY CREATED */
  2691.       sprintf(teste, "\033c%s \0338[%s]", TMsg(App->Msg67), categorydir);
  2692.       MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg18), teste);
  2693.     }
  2694.   }
  2695.   /* TESTA A VALIDADE DOS CAMPOS DE REGISTRO, SE INVALIDOS LIMPA A CHAVE
  2696.      PARA DIFICULTAR O CRACKER DO PROGRAMA */
  2697.   if(TestaPedidoRegistro() == 1)
  2698.   {
  2699.     set(App->RegisterKey, MUIA_String_Contents, "");
  2700.     /* REGISTER INFORMATION INVALID! */
  2701.     MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg18), TMsg(App->Msg38));
  2702.   }
  2703.  
  2704.   /* TESTA O CAMPO DE PRECISAO DE VALORES */
  2705.   get(App->ConfPrecision, MUIA_String_Contents, &precision);
  2706.   if(atoi(precision) < 0)
  2707.     set(App->ConfPrecision, MUIA_String_Contents, "0");
  2708.   if(atoi(precision) > 10)
  2709.     set(App->ConfPrecision, MUIA_String_Contents, "10");
  2710.  
  2711.   return NULL;
  2712. }
  2713.  
  2714. APTR CarregaPeriodo( struct Hook *a0, APTR a2, APTR a1 )
  2715. {
  2716.   /* ESTA FUNCAO GERA OS ARQUIVOS PARA A SELECAO POR PERIODO */
  2717.   char *data1, *data2, *horainicio, *horafim, teste[256],
  2718.        *database, freeout[256], data12[256];
  2719.   int x = 0;
  2720.   FILE *saida;
  2721.  
  2722.   LimpaJanelaDesseMes();
  2723.  
  2724.   /* TESTA SE O DIRETORIO DA BASE DE DADOS EXISTE */
  2725.   get(App->DataBaseName, MUIA_String_Contents, &database);
  2726.   if(!ExisteDiretorio(database))
  2727.   {
  2728.      set(App->JanelaDesseMes,MUIA_Window_Open,FALSE);
  2729.      MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg18), TMsg(App->Msg17));
  2730.      return NULL;
  2731.   }
  2732.   set(App->JanelaGeracaoQuery, MUIA_Window_Open, TRUE);
  2733.   set(App->GaugeQuery, MUIA_Gauge_Current, 5);
  2734.   set(App->GaugeQuery, MUIA_Gauge_InfoText, TMsg(App->Msg26));
  2735.  
  2736.   get(App->InputPeriodo1, MUIA_String_Contents, &data1);
  2737.   get(App->InputPeriodo2, MUIA_String_Contents, &data2);
  2738.   get(App->PrefsFreeHInicio, MUIA_String_Contents, &horainicio);
  2739.   get(App->PrefsFreeHFim, MUIA_String_Contents, &horafim);
  2740.  
  2741.   /* FAZ CONSISTENCIA DO FORMATO DA DATA */
  2742.   if(!TestaData(data1) ||
  2743.      !TestaData(data2))
  2744.   {
  2745.     /* DATE IS INVALID! VERIFIED FIELDS [DD.MM.YYYY] */
  2746.     MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg18), TMsg(App->Msg51));
  2747.     return NULL;
  2748.   }
  2749.  
  2750.   /* CASO OS CAMPOS DE HORA INICIAL E FINAL ESTEJAM EM BRANCO
  2751.      ATRIBUI 00:00:00 A ELES */
  2752.   if(!(strcmp(horainicio, "")))
  2753.     strcpy(horainicio, "00:00:00");
  2754.   if(!(strcmp(horafim, "")))
  2755.     strcpy(horafim, "00:00:00");
  2756.  
  2757.   /* CRIA LISTA DE ARQUIVOS A CONSULTAR */
  2758.   if(!(saida = fopen("T:Freedom.DataDir", "w")))
  2759.   {
  2760.      set(App->JanelaDesseMes,MUIA_Window_Open,FALSE);
  2761.      /* PROBLEM ON CREATION T:FREEDOM.DATADIR */
  2762.      MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg18), TMsg(App->Msg53));
  2763.      return NULL;
  2764.   }
  2765.   fprintf(saida, "%s/Freedom.%s\n", database, AposCaracter(data1, '.', 1));
  2766.   set(App->GaugeQuery, MUIA_Gauge_Current, 15);
  2767.  
  2768.   sprintf(freeout, "%s/Freedom.Out", database);
  2769.   strcpy(data12, data1); x = 0;
  2770.   while(x == 0)
  2771.   {
  2772.     strcpy(teste, ArrumaDataHora(SomaDiminuiMes(data12, 1), '.'));
  2773.     if(atoi(DiaJuliano(teste)) <= atoi(DiaJuliano(data2)))
  2774.     {
  2775.       fprintf(saida, "%s/Freedom.%s\n", database, AposCaracter(teste, '.', 1));
  2776.       strcpy(data12, teste);
  2777.     } else
  2778.       x = 1;
  2779.   }
  2780.   fclose(saida);
  2781.  
  2782.   /* PREPARA O ARQUIVO PARA A CONSULTA GLOBAL */
  2783.   UnirArquivos("T:Freedom.InTmpP", "T:Freedom.DataDir");
  2784.   remove("T:Freedom.DataDir");
  2785.   set(App->GaugeQuery, MUIA_Gauge_Current, 25);
  2786.  
  2787.   SelecionaIntervaloCampo("T:Freedom.InTmpP", "T:Freedom.InTmp", "Ram:Freedom.Temp", data1, data2, horainicio, horafim);
  2788.   SelecionaIntervaloCampo(freeout, "T:Freedom.OutTmp", "Ram:Freedom.Temp", data1, data2, horainicio, horafim);
  2789.   remove("T:Freedom.InTmpP");
  2790.   set(App->GaugeQuery, MUIA_Gauge_Current, 35);
  2791.  
  2792.   SemanaCount("t:Freedom.InTmp");
  2793.   sprintf(teste, "%s - %s", data1, data2);
  2794.   GravaRegistroDB("t:Freedom.Date", teste, "date", "w");
  2795.   set(App->GaugeQuery, MUIA_Gauge_Current, 50);
  2796.   return NULL;
  2797. }
  2798.  
  2799. APTR CriaBaseDados( struct Hook *a0, APTR a2, APTR a1 )
  2800. {
  2801.   char *database, teste[256];
  2802.   get(App->DataBaseName, MUIA_String_Contents, &database);
  2803.  
  2804.   mkdir(database);
  2805.  
  2806.   sprintf(teste, "\033c%s \0338[%s]", TMsg(App->Msg27), database);
  2807.   MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg18), teste);
  2808.   return NULL;
  2809. }
  2810.  
  2811. APTR PreparaGlobal( struct Hook *a0, APTR a2, APTR a1 )
  2812. {
  2813.   /* ESTA ROTINA PREPARA OS ARQUIVOS PARA A CONSULTA GLOBAL */
  2814.   char *database, freeout[256];
  2815.   /* TESTA SE O DIRETORIO DA BASE DE DADOS EXISTE */
  2816.   get(App->DataBaseName, MUIA_String_Contents, &database);
  2817.   if(!ExisteDiretorio(database))
  2818.   {
  2819.      set(App->JanelaDesseMes,MUIA_Window_Open,FALSE);
  2820.      MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg18), TMsg(App->Msg17));
  2821.      return NULL;
  2822.   }
  2823.  
  2824.   LimpaJanelaDesseMes();
  2825.   set(App->JanelaGeracaoQuery, MUIA_Window_Open, TRUE);
  2826.   set(App->GaugeQuery, MUIA_Gauge_Current, 5);
  2827.   set(App->GaugeQuery, MUIA_Gauge_InfoText, TMsg(App->Msg26));
  2828.  
  2829.   /* PREPARA O ARQUIVO PARA A CONSULTA GLOBAL */
  2830.   DiretorioArquivoFREE(database, "T:Freedom.DataDir", 1);
  2831.   UnirArquivosFREE("T:Freedom.InTmp", "T:Freedom.DataDir");
  2832.   VerificaFoneArquivo("T:Freedom.InTmp", "T:Freedom.Temp");
  2833.   remove("T:Freedom.DataDir");
  2834.   /* GLOBAL STATISTICS */
  2835.   GravaRegistroDB("t:Freedom.Date", TMsg(App->Msg52), "date", "w");
  2836.   set(App->GaugeQuery, MUIA_Gauge_Current, 25);
  2837.   sprintf(freeout, "%s/Freedom.Out", database);
  2838.   CopiaArquivo(freeout, "t:Freedom.OutTmp");
  2839.   SemanaCount("t:Freedom.InTmp");
  2840.   set(App->GaugeQuery, MUIA_Gauge_Current, 50);
  2841.   return NULL;
  2842. }
  2843.  
  2844. APTR AnualDiminuiAno( struct Hook *a0, APTR a2, APTR a1 )
  2845. {
  2846.   /* ROTINA QUE DIMINUI ANO NA CONSULTA ANUAL */
  2847.   char teste[100], *ano;
  2848.   get(App->CAnualText, MUIA_String_Contents, &ano);
  2849.   if(atoi(ano) == 1)
  2850.     strcpy(ano, "1");
  2851.   else
  2852.   {
  2853.     sprintf(teste, "%d", (atoi(ano) - 1));
  2854.     strcpy(ano, teste);
  2855.   }
  2856.   MUI_Redraw(App->CAnualText, MADF_DRAWOBJECT);
  2857.   return NULL;
  2858. }
  2859.  
  2860. APTR AnualAumentaAno( struct Hook *a0, APTR a2, APTR a1 )
  2861. {
  2862.   /* ROTINA QUE AUMENTA ANO NA CONSULTA ANUAL */
  2863.   char teste[100], *ano;
  2864.   get(App->CAnualText, MUIA_String_Contents, &ano);
  2865.   sprintf(teste, "%d", (atoi(ano) + 1));
  2866.   strcpy(ano, teste);
  2867.   MUI_Redraw(App->CAnualText, MADF_DRAWOBJECT);
  2868.   return NULL;
  2869. }
  2870.  
  2871. APTR TestaRegistroAnual( struct Hook *a0, APTR a2, APTR a1 )
  2872. {
  2873.   char senha1[256], senha2[256], senhatmp[256], *regnumber2, 
  2874.        *regemail, *regnumber, *regname, *regorg, *regcountry;
  2875.   int registro = 0;
  2876.  
  2877.   /* ROTINA QUE TESTA O TIPO DE REGISTRO */
  2878.   get(App->RegisterName, MUIA_String_Contents, ®name);
  2879.   get(App->RegisterOrganization, MUIA_String_Contents, ®org);
  2880.   get(App->RegisterEmail, MUIA_String_Contents, ®email);
  2881.   get(App->RegisterCountry, MUIA_String_Contents, ®country);
  2882.   get(App->RegisterKey, MUIA_String_Contents, ®number);
  2883.   get(App->RegisterKeyReal, MUIA_String_Contents, ®number2);
  2884.  
  2885.   strcpy(senha1, AsciiString(regnumber, 69));
  2886.   strcpy(senha2, AsciiString(regnumber2, 96));
  2887.  
  2888.   sprintf(senhatmp, "%s%s%s", regname, regemail, regcountry);
  2889.   strcpy(senhatmp, CriptografiaSimples(senhatmp, 0));
  2890.  
  2891.   if(!strcmp(senha1, senhatmp))
  2892.     registro = 1;
  2893.   if(!strcmp(senha1, senhatmp) && !strcmp(senha2, senhatmp))
  2894.     registro = 2;
  2895.   if(!strcmp(regnumber, ""))
  2896.     registro = 0;
  2897.  
  2898.   if(registro == 0)
  2899.   {
  2900.     /* VERSION NOT REGISTER, PLEASE REGISTER */
  2901.     MsgRegistro();
  2902.     return NULL;
  2903.   }
  2904.   set(App->JanelaConsultaAnual, MUIA_Window_Open, TRUE);
  2905.   return NULL;
  2906. }
  2907.  
  2908. APTR ConsultaAnual( struct Hook *a0, APTR a2, APTR a1 )
  2909. {
  2910.   char *database, teste[256], *ano, xx[10], a, tmp[256], *regnumber2,
  2911.        mes[256], ligacoes[256], online[256], regular[20], senhatmp[256],
  2912.        irregular[20], media[256], gauge[30], mesnumero[3], cost[30],
  2913.        costtmp[30], *moedac, *precision, senha1[256], senha2[256], 
  2914.        *regemail, *regnumber, *regname, *regorg, *regcountry;
  2915.   int x = 0, xmes1 = 0, xmes2 = 0, totalarq = 0, registro = 0;
  2916.   float gaugep = 0;
  2917.   long mes1 = 0, mes2 = 0, moeda = 0;
  2918.   FILE *entrada, *arq;
  2919.  
  2920.   get(App->CAnualMes1, MUIA_Cycle_Active, &mes1);
  2921.   get(App->CAnualMes2, MUIA_Cycle_Active, &mes2);
  2922.   xmes1 = mes1 + 1;
  2923.   xmes2 = mes2 + 1;
  2924.   if(xmes1 > xmes2)
  2925.   {
  2926.     /* PERIOD SELECTED INVALID! LOOK FIELDS */
  2927.     MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg18), TMsg(App->Msg61));
  2928.     set(App->JanelaConsultaAnual, MUIA_Window_Open, TRUE);
  2929.     return NULL;
  2930.   }
  2931.   set(App->JanelaConsultaAnualLista, MUIA_Window_Open, TRUE);
  2932.   DoMethod(App->ListConsultaAnual, MUIM_List_Clear);
  2933.  
  2934.   set(App->CAnualGauge, MUIA_Gauge_Current, 0);
  2935.   set(App->CAnualGauge, MUIA_Gauge_InfoText, TMsg(App->Msg26));
  2936.   get(App->DataBaseName, MUIA_String_Contents, &database);
  2937.   get(App->CAnualText, MUIA_String_Contents, &ano);
  2938.   /* ROTINA QUE PREPARA O ARQUIVO PARA CRIACAO DOS MESES */
  2939.   for(x = 1; x < 13; x++)
  2940.   {
  2941.     if(x < 10)
  2942.       sprintf(xx, "0%d", x);
  2943.     else
  2944.       sprintf(xx, "%d", x);
  2945.     sprintf(teste, "%s/Freedom.%s.%s", database, xx, ano); 
  2946.     if(x >= xmes1 && x <= xmes2)
  2947.       InsereArquivoFREE(teste, "t:Freedom.YearTemp");
  2948.     set(App->CAnualGauge, MUIA_Gauge_Current, (x * 7));
  2949.   }
  2950.   ConsultaAnualFREE("t:Freedom.YearTemp", "t:Freedom.YearC");
  2951.   totalarq = LinhasArquivo("t:Freedom.YearC");
  2952.   remove("t:Freedom.YearTemp");
  2953.   set(App->CAnualGauge, MUIA_Gauge_Current, 100);
  2954.  
  2955.   if(totalarq <= 0)
  2956.   {
  2957.     /* NAO EXISTE INFORMACOES PARA ESSA CONSULTA */
  2958.     set(App->JanelaConsultaAnualLista, MUIA_Window_Open, FALSE);
  2959.     MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg18), TMsg(App->Msg24));
  2960.     return NULL;
  2961.   }
  2962.  
  2963.   /* CARREGA FREEDOM.YEARC PARA A LISTA */
  2964.   if((!(entrada  = fopen("T:Freedom.YearC", "r"))) ||
  2965.      (!(arq      = fopen("T:Freedom.ListTmp", "w"))))
  2966.   {
  2967.     /* ERROR ON OPEN A INTERNAL TEMPORARY FILE */
  2968.     set(App->JanelaConsultaAnualLista, MUIA_Window_Open, FALSE);
  2969.     MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg18), TMsg(App->Msg62));
  2970.     return NULL;
  2971.   }
  2972.   /* PEGA INFORMACOES DA MOEDA CORRENTE */
  2973.   get(App->ComboMoeda, MUIA_Cycle_Active, &moeda);
  2974.   get(App->NomeMoeda, MUIA_String_Contents, &moedac);
  2975.  
  2976.   /* PEGA A PRECISAO DOS DISPLAYS DE VALORES */
  2977.   get(App->ConfPrecision, MUIA_String_Contents, &precision);
  2978.  
  2979.   /* ROTINA QUE TESTA O TIPO DE REGISTRO */
  2980.   get(App->RegisterName, MUIA_String_Contents, ®name);
  2981.   get(App->RegisterOrganization, MUIA_String_Contents, ®org);
  2982.   get(App->RegisterEmail, MUIA_String_Contents, ®email);
  2983.   get(App->RegisterCountry, MUIA_String_Contents, ®country);
  2984.   get(App->RegisterKeyReal, MUIA_String_Contents, ®number2);
  2985.   get(App->RegisterKey, MUIA_String_Contents, ®number);
  2986.   strcpy(senha1, AsciiString(regnumber, 69));
  2987.   strcpy(senha2, AsciiString(regnumber2, 96));
  2988.   sprintf(senhatmp, "%s%s%s", regname, regemail, regcountry);
  2989.   strcpy(senhatmp, CriptografiaSimples(senhatmp, 0));
  2990.   if(!strcmp(senha1, senhatmp))
  2991.     registro = 1;
  2992.   if(!strcmp(senha1, senhatmp) && !strcmp(senha2, senhatmp))
  2993.     registro = 2;
  2994.   if(!strcmp(regnumber, ""))
  2995.     registro = 0;
  2996.  
  2997.   set(App->CAnualGauge, MUIA_Gauge_Current, 0);
  2998.   x = 0; gaugep = 0;
  2999.   while(a = getc(entrada), ! feof(entrada))
  3000.   {
  3001.     teste[x++] = a;
  3002.     if(a == '\n')
  3003.     {
  3004.       teste[--x] = '\0';
  3005.       strcpy(mes,       Corta(teste, ',', 0));
  3006.       if(atoi(mes) < 10)
  3007.         sprintf(tmp, "0%s.%s", mes, ano);
  3008.       else
  3009.         sprintf(tmp, "%s.%s", mes, ano);
  3010.       strcpy(mesnumero, EspacoString(tmp, 9, 1));
  3011.  
  3012.       strcpy(mes,       DescricaoMesFREE(atoi(mes), 1));
  3013.       strcpy(mes,       EspacoString(mes, 9, 1));
  3014.       strcpy(ligacoes,  EspacoString(Corta(teste, ',', 1), 5, 1));
  3015.       strcpy(online,    EspacoString(SegundoHora(Corta(teste, ',', 2)), 10, 1));
  3016.       strcpy(irregular, EspacoString(Corta(teste, ',', 3), 5, 1));
  3017.       strcpy(regular,   EspacoString(Corta(teste, ',', 4), 5, 1));
  3018.       strcpy(media,     EspacoString(SegundoHora(Corta(teste, ',', 5)), 10, 1));
  3019.       strcpy(costtmp,   CasasAposCaracter(Corta(teste, ',', 6), '.', atoi(precision)));
  3020.       if(moeda == 0)
  3021.         sprintf(cost, "%s%s", moedac, costtmp);
  3022.       else
  3023.         sprintf(cost, "%s%s", costtmp, moedac);
  3024.       if(registro < 2)
  3025.         strcpy(cost, "REALREG");
  3026.       strcpy(cost,      EspacoString(cost, 12, 1));
  3027.  
  3028.       fprintf(arq, "\033b%s\033n%s\033b%s\033n%s%s%s\033b%s\033n\0338 %s\n", mesnumero, ligacoes, online, media, regular, irregular, cost, mes);
  3029.  
  3030.       /* ROTINA QUE ACERTA GAUGE */
  3031.       gaugep++;
  3032.       sprintf(gauge, "%f", ((100 / totalarq) * gaugep));
  3033.       set(App->CAnualGauge, MUIA_Gauge_Current, atoi(gauge));
  3034.       set(App->CAnualGauge, MUIA_Gauge_InfoText, "%ld %%");
  3035.       teste[0] = '\0'; x = 0;
  3036.     }
  3037.   }
  3038.   fclose(entrada);
  3039.   fclose(arq);
  3040.   set(App->CAnualGauge, MUIA_Gauge_Current, 100);
  3041.   remove("t:Freedom.YearC");
  3042.   
  3043.   /* CARREGA DO ARQUIVO PARA A LISTA */
  3044.   CarregaLista(App->ListConsultaAnual, "T:Freedom.ListTmp");
  3045.   remove("T:Freedom.ListTmp");
  3046.  
  3047.   /* LOADED */
  3048.   set(App->CAnualGauge, MUIA_Gauge_InfoText, TMsg(App->Msg78));
  3049.  
  3050.   return NULL;
  3051. }
  3052.  
  3053. APTR RemoveLimite( struct Hook *a0, APTR a2, APTR a1 )
  3054. {
  3055.   long pos = 0;
  3056.   get(App->LimitesLista, MUIA_List_Active, &pos);
  3057.   DoMethod(App->LimitesLista, MUIM_List_Remove, pos);
  3058.   return NULL;
  3059. }
  3060.  
  3061. APTR LimpaLimites( struct Hook *a0, APTR a2, APTR a1 )
  3062. {
  3063.   int x;
  3064.   /* ACCEPT OR CANCEL */
  3065.   /* YOU LIKE CLEAR ALL LIMITS IN THIS LIST */
  3066.   x = MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg64), TMsg(App->Msg65));
  3067.   if(x == 1)
  3068.     DoMethod(App->LimitesLista, MUIM_List_Clear);
  3069.   return NULL;
  3070. }
  3071.  
  3072. APTR AdicionaLimite( struct Hook *a0, APTR a2, APTR a1 )
  3073. {
  3074.   /* ROTINA QUE ADICIONA UM LIMITE NOVO A LISTA */
  3075.   static struct buffer {
  3076.     char lista[256];
  3077.   };
  3078.   static struct buffer listaarray[50];
  3079.  
  3080.   char *horaini, *horafim, *custo, *combotext;
  3081.   long pos = 0, menu = 0;
  3082.  
  3083.   /* TESTA SE NAO EXPIROU O MAXIMO DE LIMITES 100 */
  3084.   get(App->LimitesLista, MUIA_List_Entries, &pos);
  3085.   if(pos >= 50)
  3086.   {
  3087.     /* LIST OF IGNORE PHONES FINISH! MAXIMUN 100 LIMITS */
  3088.     MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg18), TMsg(App->Msg63));
  3089.     return NULL;
  3090.   }
  3091.  
  3092.   get(App->LimitesHInicio, MUIA_String_Contents, &horaini);
  3093.   get(App->LimitesHFinal, MUIA_String_Contents, &horafim);
  3094.   get(App->LimiteCusto, MUIA_String_Contents, &custo);
  3095.   strcpy(custo, SubstituiCaracter(custo, ',', '.'));
  3096.   get(App->ComboCost, MUIA_Cycle_Active, &menu);
  3097.   get(App->ComboCost, MUIA_Text_Contents, &combotext);
  3098.  
  3099.   /* FAZ CONSISTENCIA DO TAMANHO DO CAMPO HORA */
  3100.   if(!TestaHora(horaini) ||
  3101.      !TestaHora(horafim))
  3102.   {
  3103.     /* FORMAT TIME IS INVALID */
  3104.     MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg18), TMsg(App->Msg41));
  3105.     return NULL;
  3106.   }
  3107.  
  3108.   sprintf(listaarray[pos].lista, "%s %s %s %d %s", horaini, horafim, custo, menu, combotext);
  3109.   if(menu < 6)
  3110.     DoMethod(App->LimitesLista, MUIM_List_InsertSingle, &listaarray[pos].lista[0], MUIV_List_Insert_Bottom);
  3111.   else
  3112.     DoMethod(App->LimitesLista, MUIM_List_InsertSingle, &listaarray[pos].lista[0], -1, MUIV_List_Insert_Bottom);
  3113.  
  3114.   return NULL;
  3115. }
  3116.  
  3117. APTR DoubleClickLimites( struct Hook *a0, APTR a2, APTR a1 )
  3118. {
  3119.   /* ROTINA QUE CARREGA DO LIST E JOGA NOS TEXTS */
  3120.   char *linha;
  3121.   DoMethod(App->LimitesLista, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, &linha);
  3122.   set(App->LimitesHInicio, MUIA_String_Contents, Corta(linha, ' ', 0));
  3123.   set(App->LimitesHFinal, MUIA_String_Contents, Corta(linha, ' ', 1));
  3124.   set(App->LimiteCusto, MUIA_String_Contents, Corta(linha, ' ', 2));
  3125.   set(App->ComboCost, MUIA_Cycle_Active, atoi(Corta(linha, ' ', 3)));
  3126.   return NULL;
  3127. }
  3128.  
  3129. APTR SalvaCategoria( struct Hook *a0, APTR a2, APTR a1 )
  3130. {
  3131.   char *categorydir, teste[256], *categoryname, *lista, *money;
  3132.   int x = 0;
  3133.   long pos = 0, moneycombo = 0;
  3134.   FILE *saida;
  3135.  
  3136.   get(App->CategDiretorio, MUIA_String_Contents, &categorydir);
  3137.   get(App->NomeCategoria, MUIA_String_Contents, &categoryname);
  3138.   get(App->NomeMoeda, MUIA_String_Contents, &money);
  3139.  
  3140.   /* VERIFICA SE O DIRETORIO DAS CATEGORIAS EXISTE */
  3141.   if(!ExisteDiretorio(categorydir))
  3142.   {
  3143.     /* FREEDOM CATEGORIE NOT FOUND, CREATE? */
  3144.     sprintf(teste, "\033c%s\n\0338[%s]", TMsg(App->Msg66), categorydir);
  3145.     /* CREATE DIRECTORY, CANCEL */
  3146.     x = MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg33), teste);
  3147.     if(x == 1)
  3148.     {
  3149.       mkdir(categorydir);
  3150.     }
  3151.     else
  3152.       return NULL;
  3153.   }
  3154.   if(!strcmp(categoryname, ""))
  3155.   {
  3156.     /* NAME OF CATEGORY IS INVALID! */
  3157.     MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg18), TMsg(App->Msg68));
  3158.     return NULL;
  3159.   }
  3160.   get(App->LimitesLista, MUIA_List_Entries, &pos);
  3161.   if(pos == 0)
  3162.   {
  3163.     /* LISTA ESTA VAZIA */
  3164.     MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg18), TMsg(App->Msg72));
  3165.     return NULL;
  3166.   }
  3167.  
  3168.   sprintf(teste, "%s/%s", categorydir, categoryname);
  3169.   if(!(saida = fopen(teste, "w")))
  3170.   {
  3171.     /* PROBLEM ON SAVE CATEGORY */
  3172.     MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg18), TMsg(App->Msg69));
  3173.     return NULL;
  3174.   }
  3175.   for(x = 0; x < pos; x++)
  3176.   {
  3177.     DoMethod(App->LimitesLista, MUIM_List_GetEntry, x, &lista);
  3178.     sprintf(teste, "%s %s %s %s %s", HoraSegundo(Corta(lista, ' ', 0)), HoraSegundo(Corta(lista, ' ', 1)), Corta(lista, ' ', 2), Corta(lista, ' ', 3), Corta(lista, ' ', 4));
  3179.     fprintf(saida, "%s\n", teste);
  3180.   }
  3181.   get(App->ComboMoeda, MUIA_Cycle_Active, &moneycombo);
  3182.   fprintf(saida, "**>money:%d@%s\n", moneycombo, money);
  3183.   fclose(saida);
  3184.   /* CATEGORY SAVED */
  3185.   sprintf(teste, "%s \0338[%s]", TMsg(App->Msg70), categoryname);
  3186.   MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg18), teste);
  3187.   CarregaListaCategorias();
  3188.   return NULL;
  3189. }
  3190.  
  3191. APTR SelecionaCategoriaDefault( struct Hook *a0, APTR a2, APTR a1 )
  3192. {
  3193.   /* ROTINA QUE PEGA DA LISTA DE CATEGORIAS SE COLOCA NO CAMPO DEFAULT */
  3194.   char *texto;
  3195.   DoMethod(App->CategoriesList, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, &texto);
  3196.   set(App->TextDefault, MUIA_Text_Contents, texto);
  3197.   CarregaListaLimites(texto);
  3198.   CarregaPilhaCategorias(texto);
  3199.   return NULL;
  3200. }
  3201.  
  3202. APTR DoubleClickCategoria( struct Hook *a0, APTR a2, APTR a1 )
  3203. {
  3204.   char *texto, teste[256];
  3205.  
  3206.   DoMethod(App->CategoriesList, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, &texto);
  3207.   strcpy(teste, texto);
  3208.   CarregaListaLimites(teste);
  3209.   return NULL;
  3210. }
  3211.  
  3212. APTR DeletaCategoria( struct Hook *a0, APTR a2, APTR a1 )
  3213. {
  3214.   /* ROTINA QUE REMOVE UMA DETERMINADA CATEGORIA DO DISCO */
  3215.   char *categorydir, *texto, teste[256], deleta[256], *defaulttext;
  3216.   int x = 0;
  3217.  
  3218.   get(App->TextDefault, MUIA_Text_Contents, &defaulttext);
  3219.   get(App->CategDiretorio, MUIA_String_Contents, &categorydir);
  3220.   DoMethod(App->CategoriesList, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, &texto);
  3221.   if(!strcmp(texto, ""))
  3222.     return NULL;
  3223.   sprintf(deleta, "%s/%s", categorydir, texto);
  3224.   /* CONFIRM DELETING */
  3225.   sprintf(teste, "%s \0338[%s]?", TMsg(App->Msg73), texto);
  3226.   /* _DELETE|_CANCEL */
  3227.   x = MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg74), teste);
  3228.   if(x == 1)
  3229.   {
  3230.     remove(deleta);
  3231.     CarregaListaCategorias();
  3232.   }
  3233.   /* VERIFICA SE O DELETADO NAO EH O DEFAULT */
  3234.   sprintf(deleta, "%s/%s", categorydir, defaulttext);
  3235.   if(!(ExisteArquivo(deleta)))
  3236.     set(App->TextDefault, MUIA_Text_Contents, "");
  3237.   /* CARREGA APOS A DELECAO OS LIMITES DO DEFAULT */
  3238.   CarregaListaLimites(defaulttext);
  3239.   return NULL;
  3240. }
  3241.  
  3242. APTR GeraPedidoRegistro( struct Hook *a0, APTR a2, APTR a1 )
  3243. {
  3244.   char *regemail, *regname, *regcountry, *regcity, *regnumber,
  3245.        *nick, *comment, *regorg;
  3246.  
  3247.   if(TestaPedidoRegistro() == 1)
  3248.   {
  3249.     set(App->RegisterKey, MUIA_String_Contents, "");
  3250.     /* REGISTER INFORMATION INVALID! */
  3251.     MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg18), TMsg(App->Msg38));
  3252.     return NULL;
  3253.   }
  3254.  
  3255.   get(App->RegisterKey, MUIA_String_Contents, ®number);
  3256.   get(App->RegisterName, MUIA_String_Contents, ®name);
  3257.   get(App->RegisterEmail, MUIA_String_Contents, ®email);
  3258.   get(App->RegisterOrganization, MUIA_String_Contents, ®org);
  3259.   get(App->RegisterCountry, MUIA_String_Contents, ®country);
  3260.   get(App->RegisterCity, MUIA_String_Contents, ®city);
  3261.   get(App->PedidoNick, MUIA_String_Contents, &nick);
  3262.   get(App->PedidoFreedomCall, MUIA_String_Contents, &comment);
  3263.  
  3264.   if(!strcmp(nick, "") || !strcmp(comment, ""))
  3265.   {
  3266.     /* PLEASE, COMPLETE FIELDS */
  3267.     MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg18), TMsg(App->Msg77));
  3268.     return NULL;
  3269.   }
  3270.  
  3271.   GravaRegistroDB("Ram:Freedom.RegisterForm", "Send this register form for [surround@iname.com]", "EmailAddress", "w");
  3272.   GravaRegistroDB("Ram:Freedom.RegisterForm", regname, "YourName", "a");
  3273.   GravaRegistroDB("Ram:Freedom.RegisterForm", regorg, "Organization", "a");
  3274.   GravaRegistroDB("Ram:Freedom.RegisterForm", regemail, "YourEmail", "a");
  3275.   GravaRegistroDB("Ram:Freedom.RegisterForm", regcountry, "YourCountry", "a");
  3276.   GravaRegistroDB("Ram:Freedom.RegisterForm", regcity, "City", "a");
  3277.   GravaRegistroDB("Ram:Freedom.RegisterForm", nick, "Nickname", "a");
  3278.   GravaRegistroDB("Ram:Freedom.RegisterForm", comment, "Comment", "a");
  3279.   GravaRegistroDB("Ram:Freedom.RegisterForm", "Don`t change this automatic e-mail, just send it!!!", "Warning", "a");
  3280.  
  3281.   set(App->JanelaPedidoRegistro, MUIA_Window_Open, FALSE);
  3282.   
  3283.   /* FILE WAS GENERATED RAM:FREEDOM.REGISTERFORM */
  3284.   MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg18), TMsg(App->Msg34));
  3285.  
  3286.   return NULL;
  3287. }
  3288.  
  3289. APTR TestaRegistroCusto( struct Hook *a0, APTR a2, APTR a1 )
  3290. {
  3291.   char senha1[256], senha2[256], senhatmp[256], *regnumber2, 
  3292.        *regemail, *regnumber, *regname, *regorg, *regcountry;
  3293.   int registro = 0;
  3294.  
  3295.   /* ROTINA QUE TESTA O TIPO DE REGISTRO */
  3296.   get(App->RegisterName, MUIA_String_Contents, ®name);
  3297.   get(App->RegisterOrganization, MUIA_String_Contents, ®org);
  3298.   get(App->RegisterEmail, MUIA_String_Contents, ®email);
  3299.   get(App->RegisterCountry, MUIA_String_Contents, ®country);
  3300.   get(App->RegisterKey, MUIA_String_Contents, ®number);
  3301.   get(App->RegisterKeyReal, MUIA_String_Contents, ®number2);
  3302.  
  3303.   strcpy(senha1, AsciiString(regnumber, 69));
  3304.   strcpy(senha2, AsciiString(regnumber2, 96));
  3305.  
  3306.   sprintf(senhatmp, "%s%s%s", regname, regemail, regcountry);
  3307.   strcpy(senhatmp, CriptografiaSimples(senhatmp, 0));
  3308.  
  3309.   if(!strcmp(senha1, senhatmp))
  3310.     registro = 1;
  3311.   if(!strcmp(senha1, senhatmp) && !strcmp(senha2, senhatmp))
  3312.     registro = 2;
  3313.   if(!strcmp(regnumber, ""))
  3314.     registro = 0;
  3315.  
  3316.   if(registro == 0)
  3317.   {
  3318.     /* VERSION NOT REGISTER, PLEASE REGISTER */
  3319.     MsgRegistro();
  3320.     return NULL;
  3321.   }
  3322.   set(App->JanelaSelecionaMesCustos, MUIA_Window_Open, TRUE);
  3323.   return NULL;
  3324. }
  3325.  
  3326. APTR AumentaAno2( struct Hook *a0, APTR a2, APTR a1 )
  3327. {
  3328.   /* ROTINA QUE AUMENTA ANO NO EDIT DA SELECAO DE MES */
  3329.   char teste[100], *ano;
  3330.   get(App->TextAno2, MUIA_String_Contents, &ano);
  3331.   sprintf(teste, "%d", (atoi(ano) + 1));
  3332.   strcpy(ano, teste);
  3333.   MUI_Redraw(App->TextAno2, MADF_DRAWOBJECT);
  3334.   return NULL;
  3335. }
  3336.  
  3337. APTR DiminuiAno2( struct Hook *a0, APTR a2, APTR a1 )
  3338. {
  3339.   /* ROTINA QUE DIMINUI ANO NO EDIT DA SELECAO DE MES */
  3340.   char teste[100], *ano;
  3341.   get(App->TextAno2, MUIA_String_Contents, &ano);
  3342.   if(atoi(ano) == 1)
  3343.     strcpy(ano, "1");
  3344.   else
  3345.   {
  3346.     sprintf(teste, "%d", (atoi(ano) - 1));
  3347.     strcpy(ano, teste);
  3348.   }
  3349.   MUI_Redraw(App->TextAno2, MADF_DRAWOBJECT);
  3350.   return NULL;
  3351. }
  3352.  
  3353. APTR CarregaEsseCheckCost( struct Hook *a0, APTR a2, APTR a1 )
  3354. {
  3355.   char senha1[256], senha2[256], senhatmp[256], *regnumber2, 
  3356.        *regemail, *regnumber, *regname, *regorg, *regcountry,
  3357.        teste[256], horason[30], cost[30], *moedac, *precision,
  3358.        media[30], teste2[256], d1[256], d2[256], ultima[60],
  3359.        *extrahour, *providerbill, *limit, *unit; 
  3360.   int totcal = 0, registro = 0;
  3361.   long moeda = 0;
  3362.   float horastotais = 0, limitehoras = 0, precoextra = 0;
  3363.  
  3364.   totcal = LinhasArquivo("t:Freedom.inTmp");
  3365.   if(totcal <= 0)
  3366.   {
  3367.     remove("t:freedom.intmp");
  3368.     remove("t:freedom.outtmp");
  3369.     remove("t:freedom.date");
  3370.     set(App->JanelaGeracaoQuery, MUIA_Window_Open, FALSE);
  3371.     set(App->JanelaDesseMes, MUIA_Window_Open, FALSE);
  3372.     /* NO CONNECTIONS REGISTERED ABOUT THIS DATE */
  3373.     MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg18), TMsg(App->Msg24));
  3374.     return NULL;
  3375.   }
  3376.  
  3377.   /* ROTINA QUE TESTA O TIPO DE REGISTRO */
  3378.   get(App->RegisterName, MUIA_String_Contents, ®name);
  3379.   get(App->RegisterOrganization, MUIA_String_Contents, ®org);
  3380.   get(App->RegisterEmail, MUIA_String_Contents, ®email);
  3381.   get(App->RegisterCountry, MUIA_String_Contents, ®country);
  3382.   get(App->RegisterKeyReal, MUIA_String_Contents, ®number2);
  3383.   get(App->RegisterKey, MUIA_String_Contents, ®number);
  3384.   strcpy(senha1, AsciiString(regnumber, 69));
  3385.   strcpy(senha2, AsciiString(regnumber2, 96));
  3386.   sprintf(senhatmp, "%s%s%s", regname, regemail, regcountry);
  3387.   strcpy(senhatmp, CriptografiaSimples(senhatmp, 0));
  3388.   if(!strcmp(senha1, senhatmp))
  3389.     registro = 1;
  3390.   if(!strcmp(senha1, senhatmp) && !strcmp(senha2, senhatmp))
  3391.     registro = 2;
  3392.   if(!strcmp(regnumber, ""))
  3393.     registro = 0;
  3394.  
  3395.   /* TRAVA A EXECUCAO CASO SEJA USUARIO SEM REGISTRO */
  3396.   if(registro == 0)
  3397.   {
  3398.     set(App->JanelaGeracaoQuery, MUIA_Window_Open, FALSE);
  3399.     /* VERSION NOT REGISTER, PLEASE REGISTER */
  3400.     MsgRegistro();
  3401.     return NULL;
  3402.   }
  3403.  
  3404.   /* EXTRA HOUR & PROVIDER BILL */
  3405.   get(App->HoraExtra, MUIA_String_Contents, &extrahour);
  3406.   get(App->ContaProvedor, MUIA_String_Contents, &providerbill);
  3407.   get(App->InputLimitTime, MUIA_String_Contents, &limit);
  3408.   limitehoras    = atof(limit) * 3600;
  3409.  
  3410.   /* PEGA INFORMACOES DA MOEDA CORRENTE */
  3411.   get(App->ComboMoeda, MUIA_Cycle_Active, &moeda);
  3412.   get(App->NomeMoeda, MUIA_String_Contents, &moedac);
  3413.  
  3414.   /* PEGA A PRECISAO DOS DISPLAYS DE VALORES */
  3415.   get(App->ConfPrecision, MUIA_String_Contents, &precision);
  3416.   /* PEGA UNIDADE DE DESCONTO */
  3417.   get(App->ConfUnit, MUIA_String_Contents, &unit);
  3418.  
  3419.   strcpy(media,   MediaCampo("t:Freedom.inTmp", ',', 6));
  3420.   strcpy(cost,    MediaCampo("t:Freedom.inTmp", ',', 8));
  3421.   strcpy(horason, SegundoHora(Corta(media, ':', 0)));
  3422.   horastotais = atof(Corta(media, ':', 0));
  3423.  
  3424.   /* LOADING QUERY INFORMATION... */
  3425.   set(App->GaugeQuery, MUIA_Gauge_Current, 55);
  3426.   set(App->GaugeQuery, MUIA_Gauge_InfoText, TMsg(App->Msg25));
  3427.  
  3428.   /* ROTINA QUE ACERTA O CABECALHO DA GERACAO, O PERIODO */
  3429.   strcpy(ultima, PrimeiroUltimoCampo("t:freedom.inTmp", ',', 1, ':'));
  3430.   strcpy(teste, LeRegistroDB("t:Freedom.Date", "date"));
  3431.   strcpy(d1, Corta(ultima, ':', 0));
  3432.   strcpy(d2, Corta(ultima, ':', 1));
  3433.   sprintf(teste2, "\033c\0338%s [%s] %s", d1, teste, d2);
  3434.   set(App->LabelCheckCosts, MUIA_Text_Contents, teste2);
  3435.  
  3436.   /* TOTAL ONLINE & DAYS */
  3437.   sprintf(teste, "%s \0338%s\033n", TMsg(App->Msg7), horason);
  3438.   set(App->CheckTotalHoras, MUIA_Text_Contents, teste);
  3439.  
  3440.   /* EXTRA HOUR */
  3441.   if(registro < 2)
  3442.   {
  3443.     sprintf(teste, "%s \033bREALREG\033n", TMsg(App->Msg87));
  3444.     set(App->CheckHorasExtras, MUIA_Text_Contents, teste);
  3445.   } else {
  3446.     if(horastotais <= limitehoras) 
  3447.     { 
  3448.       if(moeda == 0)
  3449.         sprintf(teste, "%s %s0", TMsg(App->Msg87), moedac);
  3450.       else
  3451.         sprintf(teste, "%s 0%s", TMsg(App->Msg87), moedac);
  3452.       set(App->CheckHorasExtras, MUIA_Text_Contents, teste);
  3453.       precoextra = 0;
  3454.     } else {
  3455.       sprintf(d1, "%f", (((horastotais - limitehoras) / 3600) * atof(extrahour)));
  3456.       precoextra = atof(d1);
  3457.       if(moeda == 0)
  3458.         sprintf(teste, "%s %s%s", TMsg(App->Msg87), moedac, CasasAposCaracter(d1, '.', atoi(precision)));
  3459.       else
  3460.         sprintf(teste, "%s %s%s", TMsg(App->Msg87), CasasAposCaracter(d1, '.', atoi(precision)), moedac);
  3461.       set(App->CheckHorasExtras, MUIA_Text_Contents, teste);
  3462.     }
  3463.   }
  3464.  
  3465.   /* PHONE BILL */
  3466.   strcpy(teste2, Corta(cost, ':', 0));
  3467.   sprintf(teste2, "%f", (atof(teste2) - atof(unit)));
  3468.   if(moeda == 0)
  3469.     sprintf(teste, "%s %s%s", TMsg(App->Msg86), moedac, CasasAposCaracter(teste2, '.', atoi(precision)));
  3470.   else
  3471.     sprintf(teste, "%s %s%s", TMsg(App->Msg86), CasasAposCaracter(teste2, '.', atoi(precision)), moedac);
  3472.   if(registro < 2)
  3473.     sprintf(teste, "%s \033bREALREG\033n", TMsg(App->Msg86));
  3474.   set(App->CheckContaTelefonica, MUIA_Text_Contents, teste);
  3475.  
  3476.   /* PROVIDER BILL */
  3477.   if(registro < 2)
  3478.   {
  3479.     sprintf(teste, "%s \033bREALREG\033n", TMsg(App->Msg85));
  3480.     set(App->CheckContaProvedor, MUIA_Text_Contents, teste);
  3481.   } else {
  3482.     sprintf(d1, "%f", (atof(providerbill) + precoextra));
  3483.     if(moeda == 0)
  3484.       sprintf(teste, "%s %s%s", TMsg(App->Msg85), moedac, CasasAposCaracter(d1, '.', atoi(precision)));
  3485.     else
  3486.       sprintf(teste, "%s %s%s", TMsg(App->Msg85), CasasAposCaracter(d1, '.', atoi(precision)), moedac);
  3487.     set(App->CheckContaProvedor, MUIA_Text_Contents, teste);
  3488.   }
  3489.  
  3490.   set(App->GaugeQuery, MUIA_Gauge_Current, 100);
  3491.  
  3492.   /* TOTAL COSTS */
  3493.   if(registro < 2)
  3494.   {
  3495.     sprintf(teste, "%s \033bREALREG\033n", TMsg(App->Msg88));
  3496.     set(App->CheckCustoTotal, MUIA_Text_Contents, teste);
  3497.   } else {
  3498.     /* teste2 POSSUI O VALOR DA CONTA TELEFONICA */
  3499.     sprintf(d2, "%f", atof(teste2) + atof(d1));
  3500.     if(moeda == 0)
  3501.       sprintf(teste, "%s \033b%s%s\033n", TMsg(App->Msg88), moedac, CasasAposCaracter(d2, '.', atoi(precision)));
  3502.     else
  3503.       sprintf(teste, "%s \033b%s%s\033n", TMsg(App->Msg88), CasasAposCaracter(d2, '.', atoi(precision)), moedac);
  3504.     set(App->CheckCustoTotal, MUIA_Text_Contents, teste);
  3505.   }
  3506.  
  3507.   /* FINAL DA GERACAO */
  3508.   remove("t:freedom.outtmp");
  3509.   /* FECHA A JANELA DE DISPLAY DE GERACAO */
  3510.   set(App->JanelaGeracaoQuery, MUIA_Window_Open, FALSE);
  3511.   /* ABRE A JANELA COM AS ESTATISTICAS */
  3512.   set(App->JanelaChecaCustos, MUIA_Window_Open, TRUE);
  3513.  
  3514.   return NULL;
  3515. }
  3516.  
  3517. APTR PreparaChequeCustos( struct Hook *a0, APTR a2, APTR a1 )
  3518. {
  3519.   char teste[256], mesdes[5], *mes, *ano,
  3520.        mesdes2[20], *diax, *horainicio, *horafim, data1[256], 
  3521.        data2[256], *database, freein[256], freeout[256], 
  3522.        arquivo1[256], arquivo2[256];
  3523.   int x = 0;
  3524.  
  3525.   /* FECHA A JANELA DE SELECAO */
  3526.   set(App->JanelaSelecionaMesCustos, MUIA_Window_Open, FALSE);
  3527.  
  3528.   /* TESTA SE O DIRETORIO DA BASE DE DADOS EXISTE */
  3529.   get(App->DataBaseName, MUIA_String_Contents, &database);
  3530.   if(!ExisteDiretorio(database))
  3531.   {
  3532.      MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg18), TMsg(App->Msg17));
  3533.      return NULL;
  3534.   }
  3535.   /* PEGA O NUMERO DA POSICAO DO COMBO DE DIA, MES, ANO */
  3536.   set(App->JanelaGeracaoQuery, MUIA_Window_Open, TRUE);
  3537.   set(App->GaugeQuery, MUIA_Gauge_Current, 5);
  3538.   set(App->GaugeQuery, MUIA_Gauge_InfoText, TMsg(App->Msg26));
  3539.  
  3540.   get(App->TextAno2, MUIA_String_Contents, &ano);
  3541.   get(App->ComboMes2, MUIA_Text_Contents, &mes);
  3542.   get(App->PrefsFreeHInicio, MUIA_String_Contents, &horainicio);
  3543.   get(App->PrefsFreeHFim, MUIA_String_Contents, &horafim);
  3544.   get(App->PrefsDiaInicial, MUIA_String_Contents, &diax);
  3545.  
  3546.   sprintf(mesdes, Corta(mes, ' ', 0));
  3547.   sprintf(mesdes2, Corta(mes, ' ', 1));
  3548.  
  3549.   /* CARREGA VARIAVEIS DE PARA LEITURA DOS ARQUIVOS */
  3550.   sprintf(freeout, "%s/Freedom.Out", database);
  3551.   set(App->GaugeQuery, MUIA_Gauge_Current, 15);
  3552.   sprintf(teste, "%s.%s", mesdes, ano);
  3553.   sprintf(freein, "%s/Freedom.%s.%s", database, mesdes, ano);
  3554.  
  3555.   if( ((!(strcmp(horainicio, "")) && !(strcmp(horafim, ""))) ||
  3556.        (!(strcmp(horainicio, "00:00:00")) && !(strcmp(horafim, "00:00:00")))) && (atoi(diax) <= 1) )
  3557.   {
  3558.     FiltraCampoParaArquivoFREE(teste, freein, "t:freedom.intmp", ',', 1, '.');
  3559.     FiltraCampoParaArquivoFREE(teste, freeout, "t:freedom.outtmp", ',', 1, '.');
  3560.   }
  3561.   else
  3562.   {
  3563.     sprintf(data1, "%s.%s", diax, teste);
  3564.     x = atoi(diax);  
  3565.     x--;
  3566.     if(x < 1)
  3567.       x = 31;
  3568.     sprintf(data2, "%d.%s", x, teste);
  3569.  
  3570.     if(atoi(diax) > 1)
  3571.     {
  3572.       strcpy(data2, ArrumaDataHora(SomaDiminuiMes(data2, 1), '.'));
  3573.       /* PREPARA O ARQUIVO DE LEITURA */
  3574.       sprintf(arquivo1, "%s/Freedom.%s", database, AposCaracter(data1, '.', 1));
  3575.       sprintf(arquivo2, "%s/Freedom.%s", database, AposCaracter(data2, '.', 1));
  3576.       CopiaArquivo(arquivo1, "T:Freedom.InTmp");
  3577.       InsereArquivo(arquivo2, "T:Freedom.InTmp");
  3578.       strcpy(freein, "T:Freedom.InTmp");
  3579.     }
  3580.     SelecionaIntervaloCampo(freein, "T:Freedom.InTmp", "Ram:Freedom.Temp", data1, data2, horainicio, horafim);
  3581.     SelecionaIntervaloCampo(freeout, "T:Freedom.OutTmp", "Ram:Freedom.Temp", data1, data2, horainicio, horafim);
  3582.   }
  3583.   sprintf(teste, "%s %s", mesdes2, ano);
  3584.   GravaRegistroDB("t:Freedom.Date", teste, "date", "w");
  3585.   SemanaCount("t:Freedom.InTmp");
  3586.   return NULL;
  3587. }
  3588.  
  3589. APTR CarregaRates( struct Hook *a0, APTR a2, APTR a1 )
  3590. {
  3591.   char teste[256], teste2[256],
  3592.        senha1[256], senha2[256], senhatmp[256], *regnumber2, 
  3593.        *regemail, *regnumber, *regname, *regorg, *regcountry;
  3594.   int registro = 0;
  3595.  
  3596.   /* LIMPA OS VALORES */
  3597.   set(App->Edt300, MUIA_Text_Contents, "0");
  3598.   set(App->Edt2400, MUIA_Text_Contents, "0");
  3599.   set(App->Edt9600, MUIA_Text_Contents, "0");
  3600.   set(App->Edt14400, MUIA_Text_Contents, "0");
  3601.   set(App->Edt16800, MUIA_Text_Contents, "0");
  3602.   set(App->Edt19200, MUIA_Text_Contents, "0");
  3603.   set(App->Edt21600, MUIA_Text_Contents, "0");
  3604.   set(App->Edt24000, MUIA_Text_Contents, "0");
  3605.   set(App->Edt26400, MUIA_Text_Contents, "0");
  3606.   set(App->Edt28800, MUIA_Text_Contents, "0");
  3607.   set(App->Edt30666, MUIA_Text_Contents, "0");
  3608.   set(App->Edt32000, MUIA_Text_Contents, "0");
  3609.   set(App->Edt31200, MUIA_Text_Contents, "0");
  3610.   set(App->Edt31250, MUIA_Text_Contents, "0");
  3611.   set(App->Edt33600, MUIA_Text_Contents, "0");
  3612.   set(App->Edt38400, MUIA_Text_Contents, "0");
  3613.   set(App->Edt45333, MUIA_Text_Contents, "0");
  3614.   set(App->Edt46666, MUIA_Text_Contents, "0");
  3615.   set(App->Edt48000, MUIA_Text_Contents, "0");
  3616.   set(App->Edt49333, MUIA_Text_Contents, "0");
  3617.   set(App->Edt50666, MUIA_Text_Contents, "0");
  3618.   set(App->Edt52000, MUIA_Text_Contents, "0");
  3619.   set(App->Edt57600, MUIA_Text_Contents, "0");
  3620.   set(App->Edt64000, MUIA_Text_Contents, "0");
  3621.  
  3622.   /* TESTA SE O ARQUIVO RATES EXISTE */
  3623.   if(!(ExisteArquivo("t:freedom.rates")))
  3624.   {
  3625.     /* FILE FOR IMPORTING NOT FOUND */
  3626.     set(App->JanelaRates, MUIA_Window_Open, FALSE);
  3627.     MUI_Request(App->App, 0, 0, 0, TMsg(App->Msg18), TMsg(App->Msg94));
  3628.     return NULL;
  3629.   }
  3630.  
  3631.   /* ROTINA QUE TESTA O TIPO DE REGISTRO */
  3632.   get(App->RegisterName, MUIA_String_Contents, ®name);
  3633.   get(App->RegisterOrganization, MUIA_String_Contents, ®org);
  3634.   get(App->RegisterEmail, MUIA_String_Contents, ®email);
  3635.   get(App->RegisterCountry, MUIA_String_Contents, ®country);
  3636.   get(App->RegisterKeyReal, MUIA_String_Contents, ®number2);
  3637.   get(App->RegisterKey, MUIA_String_Contents, ®number);
  3638.  
  3639.   strcpy(senha1, AsciiString(regnumber, 69));
  3640.   strcpy(senha2, AsciiString(regnumber2, 96));
  3641.   sprintf(senhatmp, "%s%s%s", regname, regemail, regcountry);
  3642.   strcpy(senhatmp, CriptografiaSimples(senhatmp, 0));
  3643.   if(!strcmp(senha1, senhatmp))
  3644.     registro = 1;
  3645.   if(!strcmp(senha1, senhatmp) && !strcmp(senha2, senhatmp))
  3646.     registro = 2;
  3647.   if(!strcmp(regnumber, ""))
  3648.     registro = 0;
  3649.  
  3650.   /* CARREGA OS RATES DO ARQUIVO PARA A TELA */
  3651.   if(registro == 2)
  3652.     set(App->Edt300, MUIA_Text_Contents, LeRegistroDB("t:freedom.rates", "300"));
  3653.   else
  3654.     set(App->Edt300, MUIA_Text_Contents, "REALREG");
  3655.  
  3656.   if(registro == 2)
  3657.     set(App->Edt2400, MUIA_Text_Contents, LeRegistroDB("t:freedom.rates", "2400"));
  3658.   else
  3659.     set(App->Edt2400, MUIA_Text_Contents, "REALREG");
  3660.  
  3661.   if(registro == 2)
  3662.     set(App->Edt9600, MUIA_Text_Contents, LeRegistroDB("t:freedom.rates", "9600"));
  3663.   else
  3664.     set(App->Edt9600, MUIA_Text_Contents, "REALREG");
  3665.  
  3666.   if(registro == 2)
  3667.     set(App->Edt14400, MUIA_Text_Contents, LeRegistroDB("t:freedom.rates", "14400"));
  3668.   else
  3669.     set(App->Edt14400, MUIA_Text_Contents, "REALREG");
  3670.  
  3671.   if(registro == 2)
  3672.     set(App->Edt16800, MUIA_Text_Contents, LeRegistroDB("t:freedom.rates", "16800"));
  3673.   else
  3674.     set(App->Edt16800, MUIA_Text_Contents, "REALREG");
  3675.  
  3676.   if(registro == 2)
  3677.     set(App->Edt19200, MUIA_Text_Contents, LeRegistroDB("t:freedom.rates", "19200"));
  3678.   else
  3679.     set(App->Edt19200, MUIA_Text_Contents, "REALREG");
  3680.  
  3681.   if(registro == 2)
  3682.     set(App->Edt21600, MUIA_Text_Contents, LeRegistroDB("t:freedom.rates", "21600"));
  3683.   else
  3684.     set(App->Edt21600, MUIA_Text_Contents, "REALREG");
  3685.  
  3686.   if(registro == 2)
  3687.     set(App->Edt24000, MUIA_Text_Contents, LeRegistroDB("t:freedom.rates", "24000"));
  3688.   else
  3689.     set(App->Edt24000, MUIA_Text_Contents, "REALREG");
  3690.  
  3691.   if(registro == 2)
  3692.     set(App->Edt26400, MUIA_Text_Contents, LeRegistroDB("t:freedom.rates", "26400"));
  3693.   else
  3694.     set(App->Edt26400, MUIA_Text_Contents, "REALREG");
  3695.  
  3696.   if(registro == 2)
  3697.     set(App->Edt28800, MUIA_Text_Contents, LeRegistroDB("t:freedom.rates", "28800"));
  3698.   else
  3699.     set(App->Edt28800, MUIA_Text_Contents, "REALREG");
  3700.  
  3701.   if(registro == 2)
  3702.     set(App->Edt31200, MUIA_Text_Contents, LeRegistroDB("t:freedom.rates", "31200"));
  3703.   else
  3704.     set(App->Edt31200, MUIA_Text_Contents, "REALREG");
  3705.  
  3706.   if(registro == 2)
  3707.     set(App->Edt31250, MUIA_Text_Contents, LeRegistroDB("t:freedom.rates", "31250"));
  3708.   else
  3709.     set(App->Edt31250, MUIA_Text_Contents, "REALREG");
  3710.  
  3711.   if(registro == 2)
  3712.     set(App->Edt33600, MUIA_Text_Contents, LeRegistroDB("t:freedom.rates", "33600"));
  3713.   else
  3714.     set(App->Edt33600, MUIA_Text_Contents, "REALREG");
  3715.  
  3716.   if(registro == 2)
  3717.     set(App->Edt38400, MUIA_Text_Contents, LeRegistroDB("t:freedom.rates", "38400"));
  3718.   else
  3719.     set(App->Edt38400, MUIA_Text_Contents, "REALREG");
  3720.  
  3721.   if(registro == 2)
  3722.     set(App->Edt57600, MUIA_Text_Contents, LeRegistroDB("t:freedom.rates", "57600"));
  3723.   else
  3724.     set(App->Edt57600, MUIA_Text_Contents, "REALREG");
  3725.  
  3726.   if(registro == 2)
  3727.     set(App->Edt64000, MUIA_Text_Contents, LeRegistroDB("t:freedom.rates", "64000"));
  3728.   else
  3729.     set(App->Edt64000, MUIA_Text_Contents, "REALREG");
  3730.  
  3731.   if(registro == 2)
  3732.     set(App->Edt30666, MUIA_Text_Contents, LeRegistroDB("t:freedom.rates", "30666"));
  3733.   else
  3734.     set(App->Edt30666, MUIA_Text_Contents, "REALREG");
  3735.  
  3736.   if(registro == 2)
  3737.     set(App->Edt32000, MUIA_Text_Contents, LeRegistroDB("t:freedom.rates", "32000"));
  3738.   else
  3739.     set(App->Edt32000, MUIA_Text_Contents, "REALREG");
  3740.  
  3741.   if(registro == 2)
  3742.     set(App->Edt50666, MUIA_Text_Contents, LeRegistroDB("t:freedom.rates", "50666"));
  3743.   else
  3744.     set(App->Edt50666, MUIA_Text_Contents, "REALREG");
  3745.  
  3746.   if(registro == 2)
  3747.     set(App->Edt32000, MUIA_Text_Contents, LeRegistroDB("t:freedom.rates", "32000"));
  3748.   else
  3749.     set(App->Edt32000, MUIA_Text_Contents, "REALREG");
  3750.  
  3751.   if(registro == 2)
  3752.     set(App->Edt45333, MUIA_Text_Contents, LeRegistroDB("t:freedom.rates", "45333"));
  3753.   else
  3754.     set(App->Edt45333, MUIA_Text_Contents, "REALREG");
  3755.  
  3756.   if(registro == 2)
  3757.     set(App->Edt46666, MUIA_Text_Contents, LeRegistroDB("t:freedom.rates", "46666"));
  3758.   else
  3759.     set(App->Edt46666, MUIA_Text_Contents, "REALREG");
  3760.  
  3761.   if(registro == 2)
  3762.     set(App->Edt48000, MUIA_Text_Contents, LeRegistroDB("t:freedom.rates", "48000"));
  3763.   else
  3764.     set(App->Edt48000, MUIA_Text_Contents, "REALREG");
  3765.  
  3766.   if(registro == 2)
  3767.     set(App->Edt49333, MUIA_Text_Contents, LeRegistroDB("t:freedom.rates", "49333"));
  3768.   else
  3769.     set(App->Edt49333, MUIA_Text_Contents, "REALREG");
  3770.  
  3771.   /* COLOCA O TITULO */
  3772.   strcpy(teste, LeRegistroDB("t:Freedom.Date", "date"));
  3773.   sprintf(teste2, "%s", teste);
  3774.   set(App->RatesLabel, MUIA_Text_Contents, teste2);
  3775.   return NULL;
  3776. }
  3777.  
  3778. APTR AumentaMes( struct Hook *a0, APTR a2, APTR a1 )
  3779. {
  3780.   long x = 0;
  3781.   get(App->ComboMes, MUIA_Cycle_Active, &x);
  3782.   if(x >= 11)
  3783.     x = 0;
  3784.   else
  3785.     x++;
  3786.   set(App->ComboMes, MUIA_Cycle_Active, x);
  3787.   return NULL;
  3788. }
  3789.  
  3790. APTR DiminuiMes( struct Hook *a0, APTR a2, APTR a1 )
  3791. {
  3792.   long x = 0;
  3793.   get(App->ComboMes, MUIA_Cycle_Active, &x);
  3794.   if(x <= 0)
  3795.     x = 11;
  3796.   else 
  3797.     x--;
  3798.   set(App->ComboMes, MUIA_Cycle_Active, x);
  3799.   return NULL;
  3800. }
  3801.  
  3802. APTR AbreHtml( struct Hook *a0, APTR a2, APTR a1 )
  3803. {
  3804.   /* FUNCAO QUE ABRE O BROWSER COM O REPORT */
  3805.   char *browser, teste[256];
  3806.  
  3807.   get(App->Browser, MUIA_String_Contents, &browser);
  3808.   if(ExisteArquivo("T:Freedom.HTML"))
  3809.   {
  3810.     sprintf(teste, "C:Run >NIL: %s file://T:Freedom.HTML", browser);
  3811.     system(teste);
  3812.   }
  3813.   return NULL;
  3814. }
  3815.