<?php

class pdfreport_custbill_xml
{
   var $Db;
   var $Erro;
   var $Ini;
   var $Lookup;
   var $nm_data;

   var $arquivo;
   var $arquivo_view;
   var $tit_doc;
   var $sc_proc_grid; 
   var $NM_cmp_hidden = array();

   //---- 
   function pdfreport_custbill_xml()
   {
      $this->nm_data   = new nm_data("en_us");
   }

   //---- 
   function monta_xml()
   {
      $this->inicializa_vars();
      $this->grava_arquivo();
      $this->monta_html();
   }

   //----- 
   function inicializa_vars()
   {
      global $nm_lang;
      $dir_raiz          = strrpos($_SERVER['PHP_SELF'],"/") ;  
      $dir_raiz          = substr($_SERVER['PHP_SELF'], 0, $dir_raiz + 1) ;  
      $this->nm_location = $this->Ini->sc_protocolo . $this->Ini->server . $dir_raiz; 
      $this->nm_data    = new nm_data("en_us");
      $this->arquivo      = "sc_xml";
      $this->arquivo     .= "_" . date("YmdHis") . "_" . rand(0, 1000);
      $this->arquivo     .= "_pdfreport_custbill";
      $this->arquivo_view = $this->arquivo . "_view.xml";
      $this->arquivo     .= ".xml";
      $this->tit_doc      = "pdfreport_custbill.xml";
      $this->Grava_view   = false;
      if (strtolower($_SESSION['scriptcase']['charset']) != strtolower($_SESSION['scriptcase']['charset_html']))
      {
          $this->Grava_view = true;
      }
   }

   //----- 
   function grava_arquivo()
   {
      global $nm_lang;
      global
             $nm_nada, $nm_lang;

      $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
      $this->sc_proc_grid = false; 
      $nm_raiz_img  = ""; 
      if (isset($_SESSION['sc_session'][$this->Ini->sc_page]['pdfreport_custbill']['campos_busca']) && !empty($_SESSION['sc_session'][$this->Ini->sc_page]['pdfreport_custbill']['campos_busca']))
      { 
          $this->id2 = $_SESSION['sc_session'][$this->Ini->sc_page]['pdfreport_custbill']['campos_busca']['id2']; 
          $tmp_pos = strpos($this->id2, "##@@");
          if ($tmp_pos !== false)
          {
              $this->id2 = substr($this->id2, 0, $tmp_pos);
          }
          $this->bcode = $_SESSION['sc_session'][$this->Ini->sc_page]['pdfreport_custbill']['campos_busca']['bcode']; 
          $tmp_pos = strpos($this->bcode, "##@@");
          if ($tmp_pos !== false)
          {
              $this->bcode = substr($this->bcode, 0, $tmp_pos);
          }
          $this->status = $_SESSION['sc_session'][$this->Ini->sc_page]['pdfreport_custbill']['campos_busca']['status']; 
          $tmp_pos = strpos($this->status, "##@@");
          if ($tmp_pos !== false)
          {
              $this->status = substr($this->status, 0, $tmp_pos);
          }
          $this->name = $_SESSION['sc_session'][$this->Ini->sc_page]['pdfreport_custbill']['campos_busca']['name']; 
          $tmp_pos = strpos($this->name, "##@@");
          if ($tmp_pos !== false)
          {
              $this->name = substr($this->name, 0, $tmp_pos);
          }
          $this->number = $_SESSION['sc_session'][$this->Ini->sc_page]['pdfreport_custbill']['campos_busca']['number']; 
          $tmp_pos = strpos($this->number, "##@@");
          if ($tmp_pos !== false)
          {
              $this->number = substr($this->number, 0, $tmp_pos);
          }
      } 
      $this->nm_field_dinamico = array();
      $this->nm_order_dinamico = array();
      $this->sc_where_orig   = $_SESSION['sc_session'][$this->Ini->sc_page]['pdfreport_custbill']['where_orig'];
      $this->sc_where_atual  = $_SESSION['sc_session'][$this->Ini->sc_page]['pdfreport_custbill']['where_pesq'];
      $this->sc_where_filtro = $_SESSION['sc_session'][$this->Ini->sc_page]['pdfreport_custbill']['where_pesq_filtro'];
      if (isset($_SESSION['sc_session'][$this->Ini->sc_page]['pdfreport_custbill']['xml_name']))
      {
          $this->arquivo = $_SESSION['sc_session'][$this->Ini->sc_page]['pdfreport_custbill']['xml_name'];
          $this->tit_doc = $_SESSION['sc_session'][$this->Ini->sc_page]['pdfreport_custbill']['xml_name'];
          unset($_SESSION['sc_session'][$this->Ini->sc_page]['pdfreport_custbill']['xml_name']);
      }
      if (!$this->Grava_view)
      {
          $this->arquivo_view = $this->arquivo;
      }
      if (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_sybase))
      { 
          $nmgp_select = "SELECT BCODE, STATUS, NAME, NUMBER, PREFIX, ADDRESS1, ADDRESS2, CITY, STATE, COUNTRY, ZIP_CODE, SALESMAN, EMAIL, CAT1, CAT2, CAT3, CAT4, CAT5, CAT6, CAT7, TERMS, PHONE, ADDED, CONTACT, str_replace (convert(char(10),TDATE,102), '.', '-') + ' ' + convert(char(8),TDATE,20), MEMO, ATT, CPHONE1, CPHONE2, CONTACT2, CEMAIL1, CEMAIL2, FAX, CFAX1, CFAX2, MTD, YTD, QTD, JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, `DEC` as sc_def_col_1, LYEAR, LLYEAR, Q1, Q2, Q3, Q4, str_replace (convert(char(10),UPDATED,102), '.', '-') + ' ' + convert(char(8),UPDATED,20), S365, TEMP, ID2 from " . $this->Ini->nm_tabela; 
      } 
      elseif (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_mysql))
      { 
          $nmgp_select = "SELECT BCODE, STATUS, NAME, NUMBER, PREFIX, ADDRESS1, ADDRESS2, CITY, STATE, COUNTRY, ZIP_CODE, SALESMAN, EMAIL, CAT1, CAT2, CAT3, CAT4, CAT5, CAT6, CAT7, TERMS, PHONE, ADDED, CONTACT, TDATE, MEMO, ATT, CPHONE1, CPHONE2, CONTACT2, CEMAIL1, CEMAIL2, FAX, CFAX1, CFAX2, MTD, YTD, QTD, JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, `DEC` as sc_def_col_1, LYEAR, LLYEAR, Q1, Q2, Q3, Q4, UPDATED, S365, TEMP, ID2 from " . $this->Ini->nm_tabela; 
      } 
      elseif (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_mssql))
      { 
       $nmgp_select = "SELECT BCODE, STATUS, NAME, NUMBER, PREFIX, ADDRESS1, ADDRESS2, CITY, STATE, COUNTRY, ZIP_CODE, SALESMAN, EMAIL, CAT1, CAT2, CAT3, CAT4, CAT5, CAT6, CAT7, TERMS, PHONE, ADDED, CONTACT, convert(char(23),TDATE,121), MEMO, ATT, CPHONE1, CPHONE2, CONTACT2, CEMAIL1, CEMAIL2, FAX, CFAX1, CFAX2, MTD, YTD, QTD, JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, `DEC` as sc_def_col_1, LYEAR, LLYEAR, Q1, Q2, Q3, Q4, convert(char(23),UPDATED,121), S365, TEMP, ID2 from " . $this->Ini->nm_tabela; 
      } 
      elseif (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_oracle))
      { 
          $nmgp_select = "SELECT BCODE, STATUS, NAME, NUMBER, PREFIX, ADDRESS1, ADDRESS2, CITY, STATE, COUNTRY, ZIP_CODE, SALESMAN, EMAIL, CAT1, CAT2, CAT3, CAT4, CAT5, CAT6, CAT7, TERMS, PHONE, ADDED, CONTACT, TDATE, MEMO, ATT, CPHONE1, CPHONE2, CONTACT2, CEMAIL1, CEMAIL2, FAX, CFAX1, CFAX2, MTD, YTD, QTD, JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, `DEC` as sc_def_col_1, LYEAR, LLYEAR, Q1, Q2, Q3, Q4, UPDATED, S365, TEMP, ID2 from " . $this->Ini->nm_tabela; 
      } 
      elseif (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_informix))
      { 
          $nmgp_select = "SELECT BCODE, STATUS, NAME, NUMBER, PREFIX, ADDRESS1, ADDRESS2, CITY, STATE, COUNTRY, ZIP_CODE, SALESMAN, EMAIL, CAT1, CAT2, CAT3, CAT4, CAT5, CAT6, CAT7, TERMS, PHONE, ADDED, CONTACT, EXTEND(TDATE, YEAR TO DAY), MEMO, ATT, CPHONE1, CPHONE2, CONTACT2, CEMAIL1, CEMAIL2, FAX, CFAX1, CFAX2, MTD, YTD, QTD, JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, `DEC` as sc_def_col_1, LYEAR, LLYEAR, Q1, Q2, Q3, Q4, EXTEND(UPDATED, YEAR TO DAY), S365, TEMP, ID2 from " . $this->Ini->nm_tabela; 
      } 
      else 
      { 
          $nmgp_select = "SELECT BCODE, STATUS, NAME, NUMBER, PREFIX, ADDRESS1, ADDRESS2, CITY, STATE, COUNTRY, ZIP_CODE, SALESMAN, EMAIL, CAT1, CAT2, CAT3, CAT4, CAT5, CAT6, CAT7, TERMS, PHONE, ADDED, CONTACT, TDATE, MEMO, ATT, CPHONE1, CPHONE2, CONTACT2, CEMAIL1, CEMAIL2, FAX, CFAX1, CFAX2, MTD, YTD, QTD, JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, `DEC` as sc_def_col_1, LYEAR, LLYEAR, Q1, Q2, Q3, Q4, UPDATED, S365, TEMP, ID2 from " . $this->Ini->nm_tabela; 
      } 
      $nmgp_select .= " " . $_SESSION['sc_session'][$this->Ini->sc_page]['pdfreport_custbill']['where_pesq'];
      $nmgp_order_by = $_SESSION['sc_session'][$this->Ini->sc_page]['pdfreport_custbill']['order_grid'];
      $nmgp_select .= $nmgp_order_by; 
      $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nmgp_select;
      $rs = $this->Db->Execute($nmgp_select);
      if ($rs === false && !$rs->EOF && $GLOBALS["NM_ERRO_IBASE"] != 1)
      {
         $this->Erro->mensagem(__FILE__, __LINE__, "banco", $this->Ini->Nm_lang['lang_errm_dber'], $this->Db->ErrorMsg());
         exit;
      }

      $xml_charset = $_SESSION['scriptcase']['charset'];
      $xml_f = fopen($this->Ini->root . $this->Ini->path_imag_temp . "/" . $this->arquivo, "w");
      fwrite($xml_f, "<?xml version=\"1.0\" encoding=\"$xml_charset\" ?>\r\n");
      fwrite($xml_f, "<root>\r\n");
      if ($this->Grava_view)
      {
          $xml_charset_v = $_SESSION['scriptcase']['charset_html'];
          $xml_v         = fopen($this->Ini->root . $this->Ini->path_imag_temp . "/" . $this->arquivo_view, "w");
          fwrite($xml_v, "<?xml version=\"1.0\" encoding=\"$xml_charset_v\" ?>\r\n");
          fwrite($xml_v, "<root>\r\n");
      }
      while (!$rs->EOF)
      {
         $this->xml_registro = "<pdfreport_custbill";
         $this->bcode = $rs->fields[0] ;  
         $this->status = $rs->fields[1] ;  
         $this->name = $rs->fields[2] ;  
         $this->number = $rs->fields[3] ;  
         $this->number = (string)$this->number;
         $this->prefix = $rs->fields[4] ;  
         $this->address1 = $rs->fields[5] ;  
         $this->address2 = $rs->fields[6] ;  
         $this->city = $rs->fields[7] ;  
         $this->state = $rs->fields[8] ;  
         $this->country = $rs->fields[9] ;  
         $this->zip_code = $rs->fields[10] ;  
         $this->salesman = $rs->fields[11] ;  
         $this->email = $rs->fields[12] ;  
         $this->cat1 = $rs->fields[13] ;  
         $this->cat2 = $rs->fields[14] ;  
         $this->cat3 = $rs->fields[15] ;  
         $this->cat4 = $rs->fields[16] ;  
         $this->cat5 = $rs->fields[17] ;  
         $this->cat6 = $rs->fields[18] ;  
         $this->cat7 = $rs->fields[19] ;  
         $this->terms = $rs->fields[20] ;  
         $this->phone = $rs->fields[21] ;  
         $this->added = $rs->fields[22] ;  
         $this->contact = $rs->fields[23] ;  
         $this->tdate = $rs->fields[24] ;  
         $this->memo = $rs->fields[25] ;  
         $this->att = $rs->fields[26] ;  
         $this->cphone1 = $rs->fields[27] ;  
         $this->cphone2 = $rs->fields[28] ;  
         $this->contact2 = $rs->fields[29] ;  
         $this->cemail1 = $rs->fields[30] ;  
         $this->cemail2 = $rs->fields[31] ;  
         $this->fax = $rs->fields[32] ;  
         $this->cfax1 = $rs->fields[33] ;  
         $this->cfax2 = $rs->fields[34] ;  
         $this->mtd = $rs->fields[35] ;  
         $this->mtd =  str_replace(",", ".", $this->mtd);
         $this->mtd = (strpos(strtolower($this->mtd), "e")) ? (float)$this->mtd : $this->mtd; 
         $this->mtd = (string)$this->mtd;
         $this->ytd = $rs->fields[36] ;  
         $this->ytd =  str_replace(",", ".", $this->ytd);
         $this->ytd = (strpos(strtolower($this->ytd), "e")) ? (float)$this->ytd : $this->ytd; 
         $this->ytd = (string)$this->ytd;
         $this->qtd = $rs->fields[37] ;  
         $this->qtd =  str_replace(",", ".", $this->qtd);
         $this->qtd = (strpos(strtolower($this->qtd), "e")) ? (float)$this->qtd : $this->qtd; 
         $this->qtd = (string)$this->qtd;
         $this->jan = $rs->fields[38] ;  
         $this->jan =  str_replace(",", ".", $this->jan);
         $this->jan = (strpos(strtolower($this->jan), "e")) ? (float)$this->jan : $this->jan; 
         $this->jan = (string)$this->jan;
         $this->feb = $rs->fields[39] ;  
         $this->feb =  str_replace(",", ".", $this->feb);
         $this->feb = (strpos(strtolower($this->feb), "e")) ? (float)$this->feb : $this->feb; 
         $this->feb = (string)$this->feb;
         $this->mar = $rs->fields[40] ;  
         $this->mar =  str_replace(",", ".", $this->mar);
         $this->mar = (strpos(strtolower($this->mar), "e")) ? (float)$this->mar : $this->mar; 
         $this->mar = (string)$this->mar;
         $this->apr = $rs->fields[41] ;  
         $this->apr =  str_replace(",", ".", $this->apr);
         $this->apr = (strpos(strtolower($this->apr), "e")) ? (float)$this->apr : $this->apr; 
         $this->apr = (string)$this->apr;
         $this->may = $rs->fields[42] ;  
         $this->may =  str_replace(",", ".", $this->may);
         $this->may = (strpos(strtolower($this->may), "e")) ? (float)$this->may : $this->may; 
         $this->may = (string)$this->may;
         $this->jun = $rs->fields[43] ;  
         $this->jun =  str_replace(",", ".", $this->jun);
         $this->jun = (strpos(strtolower($this->jun), "e")) ? (float)$this->jun : $this->jun; 
         $this->jun = (string)$this->jun;
         $this->jul = $rs->fields[44] ;  
         $this->jul =  str_replace(",", ".", $this->jul);
         $this->jul = (strpos(strtolower($this->jul), "e")) ? (float)$this->jul : $this->jul; 
         $this->jul = (string)$this->jul;
         $this->aug = $rs->fields[45] ;  
         $this->aug =  str_replace(",", ".", $this->aug);
         $this->aug = (strpos(strtolower($this->aug), "e")) ? (float)$this->aug : $this->aug; 
         $this->aug = (string)$this->aug;
         $this->sep = $rs->fields[46] ;  
         $this->sep =  str_replace(",", ".", $this->sep);
         $this->sep = (strpos(strtolower($this->sep), "e")) ? (float)$this->sep : $this->sep; 
         $this->sep = (string)$this->sep;
         $this->oct = $rs->fields[47] ;  
         $this->oct =  str_replace(",", ".", $this->oct);
         $this->oct = (strpos(strtolower($this->oct), "e")) ? (float)$this->oct : $this->oct; 
         $this->oct = (string)$this->oct;
         $this->nov = $rs->fields[48] ;  
         $this->nov =  str_replace(",", ".", $this->nov);
         $this->nov = (strpos(strtolower($this->nov), "e")) ? (float)$this->nov : $this->nov; 
         $this->nov = (string)$this->nov;
         $this->dec = $rs->fields[49] ;  
         $this->dec =  str_replace(",", ".", $this->dec);
         $this->dec = (strpos(strtolower($this->dec), "e")) ? (float)$this->dec : $this->dec; 
         $this->dec = (string)$this->dec;
         $this->lyear = $rs->fields[50] ;  
         $this->lyear =  str_replace(",", ".", $this->lyear);
         $this->lyear = (strpos(strtolower($this->lyear), "e")) ? (float)$this->lyear : $this->lyear; 
         $this->lyear = (string)$this->lyear;
         $this->llyear = $rs->fields[51] ;  
         $this->llyear =  str_replace(",", ".", $this->llyear);
         $this->llyear = (strpos(strtolower($this->llyear), "e")) ? (float)$this->llyear : $this->llyear; 
         $this->llyear = (string)$this->llyear;
         $this->q1 = $rs->fields[52] ;  
         $this->q1 =  str_replace(",", ".", $this->q1);
         $this->q1 = (strpos(strtolower($this->q1), "e")) ? (float)$this->q1 : $this->q1; 
         $this->q1 = (string)$this->q1;
         $this->q2 = $rs->fields[53] ;  
         $this->q2 =  str_replace(",", ".", $this->q2);
         $this->q2 = (strpos(strtolower($this->q2), "e")) ? (float)$this->q2 : $this->q2; 
         $this->q2 = (string)$this->q2;
         $this->q3 = $rs->fields[54] ;  
         $this->q3 =  str_replace(",", ".", $this->q3);
         $this->q3 = (strpos(strtolower($this->q3), "e")) ? (float)$this->q3 : $this->q3; 
         $this->q3 = (string)$this->q3;
         $this->q4 = $rs->fields[55] ;  
         $this->q4 =  str_replace(",", ".", $this->q4);
         $this->q4 = (strpos(strtolower($this->q4), "e")) ? (float)$this->q4 : $this->q4; 
         $this->q4 = (string)$this->q4;
         $this->updated = $rs->fields[56] ;  
         $this->s365 = $rs->fields[57] ;  
         $this->s365 =  str_replace(",", ".", $this->s365);
         $this->s365 = (strpos(strtolower($this->s365), "e")) ? (float)$this->s365 : $this->s365; 
         $this->s365 = (string)$this->s365;
         $this->temp = $rs->fields[58] ;  
         $this->id2 = $rs->fields[59] ;  
         $this->id2 = (string)$this->id2;
         $this->sc_proc_grid = true; 
         foreach ($_SESSION['sc_session'][$this->Ini->sc_page]['pdfreport_custbill']['field_order'] as $Cada_col)
         { 
            if (!isset($this->NM_cmp_hidden[$Cada_col]) || $this->NM_cmp_hidden[$Cada_col] != "off")
            { 
                $NM_func_exp = "NM_export_" . $Cada_col;
                $this->$NM_func_exp();
            } 
         } 
         $this->xml_registro .= " />\r\n";
         fwrite($xml_f, $this->xml_registro);
         if ($this->Grava_view)
         {
            fwrite($xml_v, $this->xml_registro);
         }
         $rs->MoveNext();
      }
      fwrite($xml_f, "</root>");
      fclose($xml_f);
      if ($this->Grava_view)
      {
         fwrite($xml_v, "</root>");
         fclose($xml_v);
      }

      $rs->Close();
   }
   //----- bcode
   function NM_export_bcode()
   {
         if ($_SESSION['scriptcase']['charset'] == "UTF-8" && !NM_is_utf8($this->bcode))
         {
             $this->bcode = mb_convert_encoding($this->bcode, "UTF-8");
         }
         $this->xml_registro .= " bcode =\"" . $this->trata_dados($this->bcode) . "\"";
   }
   //----- status
   function NM_export_status()
   {
         if ($_SESSION['scriptcase']['charset'] == "UTF-8" && !NM_is_utf8($this->status))
         {
             $this->status = mb_convert_encoding($this->status, "UTF-8");
         }
         $this->xml_registro .= " status =\"" . $this->trata_dados($this->status) . "\"";
   }
   //----- name
   function NM_export_name()
   {
         if ($_SESSION['scriptcase']['charset'] == "UTF-8" && !NM_is_utf8($this->name))
         {
             $this->name = mb_convert_encoding($this->name, "UTF-8");
         }
         $this->xml_registro .= " name =\"" . $this->trata_dados($this->name) . "\"";
   }
   //----- number
   function NM_export_number()
   {
         nmgp_Form_Num_Val($this->number, $_SESSION['scriptcase']['reg_conf']['grup_num'], $_SESSION['scriptcase']['reg_conf']['dec_num'], "0", "S", "2", "", "N:" . $_SESSION['scriptcase']['reg_conf']['neg_num'] , $_SESSION['scriptcase']['reg_conf']['simb_neg'], $_SESSION['scriptcase']['reg_conf']['num_group_digit']) ; 
         if ($_SESSION['scriptcase']['charset'] == "UTF-8" && !NM_is_utf8($this->number))
         {
             $this->number = mb_convert_encoding($this->number, "UTF-8");
         }
         $this->xml_registro .= " number =\"" . $this->trata_dados($this->number) . "\"";
   }
   //----- prefix
   function NM_export_prefix()
   {
         if ($_SESSION['scriptcase']['charset'] == "UTF-8" && !NM_is_utf8($this->prefix))
         {
             $this->prefix = mb_convert_encoding($this->prefix, "UTF-8");
         }
         $this->xml_registro .= " prefix =\"" . $this->trata_dados($this->prefix) . "\"";
   }
   //----- address1
   function NM_export_address1()
   {
         if ($_SESSION['scriptcase']['charset'] == "UTF-8" && !NM_is_utf8($this->address1))
         {
             $this->address1 = mb_convert_encoding($this->address1, "UTF-8");
         }
         $this->xml_registro .= " address1 =\"" . $this->trata_dados($this->address1) . "\"";
   }
   //----- address2
   function NM_export_address2()
   {
         if ($_SESSION['scriptcase']['charset'] == "UTF-8" && !NM_is_utf8($this->address2))
         {
             $this->address2 = mb_convert_encoding($this->address2, "UTF-8");
         }
         $this->xml_registro .= " address2 =\"" . $this->trata_dados($this->address2) . "\"";
   }
   //----- city
   function NM_export_city()
   {
         if ($_SESSION['scriptcase']['charset'] == "UTF-8" && !NM_is_utf8($this->city))
         {
             $this->city = mb_convert_encoding($this->city, "UTF-8");
         }
         $this->xml_registro .= " city =\"" . $this->trata_dados($this->city) . "\"";
   }
   //----- state
   function NM_export_state()
   {
         if ($_SESSION['scriptcase']['charset'] == "UTF-8" && !NM_is_utf8($this->state))
         {
             $this->state = mb_convert_encoding($this->state, "UTF-8");
         }
         $this->xml_registro .= " state =\"" . $this->trata_dados($this->state) . "\"";
   }
   //----- country
   function NM_export_country()
   {
         if ($_SESSION['scriptcase']['charset'] == "UTF-8" && !NM_is_utf8($this->country))
         {
             $this->country = mb_convert_encoding($this->country, "UTF-8");
         }
         $this->xml_registro .= " country =\"" . $this->trata_dados($this->country) . "\"";
   }
   //----- zip_code
   function NM_export_zip_code()
   {
         if ($_SESSION['scriptcase']['charset'] == "UTF-8" && !NM_is_utf8($this->zip_code))
         {
             $this->zip_code = mb_convert_encoding($this->zip_code, "UTF-8");
         }
         $this->xml_registro .= " zip_code =\"" . $this->trata_dados($this->zip_code) . "\"";
   }
   //----- salesman
   function NM_export_salesman()
   {
         if ($_SESSION['scriptcase']['charset'] == "UTF-8" && !NM_is_utf8($this->salesman))
         {
             $this->salesman = mb_convert_encoding($this->salesman, "UTF-8");
         }
         $this->xml_registro .= " salesman =\"" . $this->trata_dados($this->salesman) . "\"";
   }
   //----- email
   function NM_export_email()
   {
         if ($_SESSION['scriptcase']['charset'] == "UTF-8" && !NM_is_utf8($this->email))
         {
             $this->email = mb_convert_encoding($this->email, "UTF-8");
         }
         $this->xml_registro .= " email =\"" . $this->trata_dados($this->email) . "\"";
   }
   //----- cat1
   function NM_export_cat1()
   {
         if ($_SESSION['scriptcase']['charset'] == "UTF-8" && !NM_is_utf8($this->cat1))
         {
             $this->cat1 = mb_convert_encoding($this->cat1, "UTF-8");
         }
         $this->xml_registro .= " cat1 =\"" . $this->trata_dados($this->cat1) . "\"";
   }
   //----- cat2
   function NM_export_cat2()
   {
         if ($_SESSION['scriptcase']['charset'] == "UTF-8" && !NM_is_utf8($this->cat2))
         {
             $this->cat2 = mb_convert_encoding($this->cat2, "UTF-8");
         }
         $this->xml_registro .= " cat2 =\"" . $this->trata_dados($this->cat2) . "\"";
   }
   //----- cat3
   function NM_export_cat3()
   {
         if ($_SESSION['scriptcase']['charset'] == "UTF-8" && !NM_is_utf8($this->cat3))
         {
             $this->cat3 = mb_convert_encoding($this->cat3, "UTF-8");
         }
         $this->xml_registro .= " cat3 =\"" . $this->trata_dados($this->cat3) . "\"";
   }
   //----- cat4
   function NM_export_cat4()
   {
         if ($_SESSION['scriptcase']['charset'] == "UTF-8" && !NM_is_utf8($this->cat4))
         {
             $this->cat4 = mb_convert_encoding($this->cat4, "UTF-8");
         }
         $this->xml_registro .= " cat4 =\"" . $this->trata_dados($this->cat4) . "\"";
   }
   //----- cat5
   function NM_export_cat5()
   {
         if ($_SESSION['scriptcase']['charset'] == "UTF-8" && !NM_is_utf8($this->cat5))
         {
             $this->cat5 = mb_convert_encoding($this->cat5, "UTF-8");
         }
         $this->xml_registro .= " cat5 =\"" . $this->trata_dados($this->cat5) . "\"";
   }
   //----- cat6
   function NM_export_cat6()
   {
         if ($_SESSION['scriptcase']['charset'] == "UTF-8" && !NM_is_utf8($this->cat6))
         {
             $this->cat6 = mb_convert_encoding($this->cat6, "UTF-8");
         }
         $this->xml_registro .= " cat6 =\"" . $this->trata_dados($this->cat6) . "\"";
   }
   //----- cat7
   function NM_export_cat7()
   {
         if ($_SESSION['scriptcase']['charset'] == "UTF-8" && !NM_is_utf8($this->cat7))
         {
             $this->cat7 = mb_convert_encoding($this->cat7, "UTF-8");
         }
         $this->xml_registro .= " cat7 =\"" . $this->trata_dados($this->cat7) . "\"";
   }
   //----- terms
   function NM_export_terms()
   {
         if ($_SESSION['scriptcase']['charset'] == "UTF-8" && !NM_is_utf8($this->terms))
         {
             $this->terms = mb_convert_encoding($this->terms, "UTF-8");
         }
         $this->xml_registro .= " terms =\"" . $this->trata_dados($this->terms) . "\"";
   }
   //----- phone
   function NM_export_phone()
   {
         if ($_SESSION['scriptcase']['charset'] == "UTF-8" && !NM_is_utf8($this->phone))
         {
             $this->phone = mb_convert_encoding($this->phone, "UTF-8");
         }
         $this->xml_registro .= " phone =\"" . $this->trata_dados($this->phone) . "\"";
   }
   //----- added
   function NM_export_added()
   {
         if ($_SESSION['scriptcase']['charset'] == "UTF-8" && !NM_is_utf8($this->added))
         {
             $this->added = mb_convert_encoding($this->added, "UTF-8");
         }
         $this->xml_registro .= " added =\"" . $this->trata_dados($this->added) . "\"";
   }
   //----- contact
   function NM_export_contact()
   {
         if ($_SESSION['scriptcase']['charset'] == "UTF-8" && !NM_is_utf8($this->contact))
         {
             $this->contact = mb_convert_encoding($this->contact, "UTF-8");
         }
         $this->xml_registro .= " contact =\"" . $this->trata_dados($this->contact) . "\"";
   }
   //----- tdate
   function NM_export_tdate()
   {
         $conteudo_x =  $this->tdate;
         nm_conv_limpa_dado($conteudo_x, "YYYY-MM-DD");
         if (is_numeric($conteudo_x) && $conteudo_x > 0) 
         { 
             $this->nm_data->SetaData($this->tdate, "YYYY-MM-DD");
             $this->tdate = $this->nm_data->FormataSaida($this->Nm_date_format("DT", "ddmmaaaa"));
         } 
         if ($_SESSION['scriptcase']['charset'] == "UTF-8" && !NM_is_utf8($this->tdate))
         {
             $this->tdate = mb_convert_encoding($this->tdate, "UTF-8");
         }
         $this->xml_registro .= " tdate =\"" . $this->trata_dados($this->tdate) . "\"";
   }
   //----- memo
   function NM_export_memo()
   {
         if ($_SESSION['scriptcase']['charset'] == "UTF-8" && !NM_is_utf8($this->memo))
         {
             $this->memo = mb_convert_encoding($this->memo, "UTF-8");
         }
         $this->xml_registro .= " memo =\"" . $this->trata_dados($this->memo) . "\"";
   }
   //----- att
   function NM_export_att()
   {
         if ($_SESSION['scriptcase']['charset'] == "UTF-8" && !NM_is_utf8($this->att))
         {
             $this->att = mb_convert_encoding($this->att, "UTF-8");
         }
         $this->xml_registro .= " att =\"" . $this->trata_dados($this->att) . "\"";
   }
   //----- cphone1
   function NM_export_cphone1()
   {
         if ($_SESSION['scriptcase']['charset'] == "UTF-8" && !NM_is_utf8($this->cphone1))
         {
             $this->cphone1 = mb_convert_encoding($this->cphone1, "UTF-8");
         }
         $this->xml_registro .= " cphone1 =\"" . $this->trata_dados($this->cphone1) . "\"";
   }
   //----- cphone2
   function NM_export_cphone2()
   {
         if ($_SESSION['scriptcase']['charset'] == "UTF-8" && !NM_is_utf8($this->cphone2))
         {
             $this->cphone2 = mb_convert_encoding($this->cphone2, "UTF-8");
         }
         $this->xml_registro .= " cphone2 =\"" . $this->trata_dados($this->cphone2) . "\"";
   }
   //----- contact2
   function NM_export_contact2()
   {
         if ($_SESSION['scriptcase']['charset'] == "UTF-8" && !NM_is_utf8($this->contact2))
         {
             $this->contact2 = mb_convert_encoding($this->contact2, "UTF-8");
         }
         $this->xml_registro .= " contact2 =\"" . $this->trata_dados($this->contact2) . "\"";
   }
   //----- cemail1
   function NM_export_cemail1()
   {
         if ($_SESSION['scriptcase']['charset'] == "UTF-8" && !NM_is_utf8($this->cemail1))
         {
             $this->cemail1 = mb_convert_encoding($this->cemail1, "UTF-8");
         }
         $this->xml_registro .= " cemail1 =\"" . $this->trata_dados($this->cemail1) . "\"";
   }
   //----- cemail2
   function NM_export_cemail2()
   {
         if ($_SESSION['scriptcase']['charset'] == "UTF-8" && !NM_is_utf8($this->cemail2))
         {
             $this->cemail2 = mb_convert_encoding($this->cemail2, "UTF-8");
         }
         $this->xml_registro .= " cemail2 =\"" . $this->trata_dados($this->cemail2) . "\"";
   }
   //----- fax
   function NM_export_fax()
   {
         if ($_SESSION['scriptcase']['charset'] == "UTF-8" && !NM_is_utf8($this->fax))
         {
             $this->fax = mb_convert_encoding($this->fax, "UTF-8");
         }
         $this->xml_registro .= " fax =\"" . $this->trata_dados($this->fax) . "\"";
   }
   //----- cfax1
   function NM_export_cfax1()
   {
         if ($_SESSION['scriptcase']['charset'] == "UTF-8" && !NM_is_utf8($this->cfax1))
         {
             $this->cfax1 = mb_convert_encoding($this->cfax1, "UTF-8");
         }
         $this->xml_registro .= " cfax1 =\"" . $this->trata_dados($this->cfax1) . "\"";
   }
   //----- cfax2
   function NM_export_cfax2()
   {
         if ($_SESSION['scriptcase']['charset'] == "UTF-8" && !NM_is_utf8($this->cfax2))
         {
             $this->cfax2 = mb_convert_encoding($this->cfax2, "UTF-8");
         }
         $this->xml_registro .= " cfax2 =\"" . $this->trata_dados($this->cfax2) . "\"";
   }
   //----- mtd
   function NM_export_mtd()
   {
         nmgp_Form_Num_Val($this->mtd, $_SESSION['scriptcase']['reg_conf']['grup_val'], $_SESSION['scriptcase']['reg_conf']['dec_val'], "2", "S", "2", "", "V:" . $_SESSION['scriptcase']['reg_conf']['monet_f_pos'] . ":" . $_SESSION['scriptcase']['reg_conf']['monet_f_neg'], $_SESSION['scriptcase']['reg_conf']['simb_neg'], $_SESSION['scriptcase']['reg_conf']['unid_mont_group_digit']) ; 
         if ($_SESSION['scriptcase']['charset'] == "UTF-8" && !NM_is_utf8($this->mtd))
         {
             $this->mtd = mb_convert_encoding($this->mtd, "UTF-8");
         }
         $this->xml_registro .= " mtd =\"" . $this->trata_dados($this->mtd) . "\"";
   }
   //----- ytd
   function NM_export_ytd()
   {
         nmgp_Form_Num_Val($this->ytd, $_SESSION['scriptcase']['reg_conf']['grup_val'], $_SESSION['scriptcase']['reg_conf']['dec_val'], "2", "S", "2", "", "V:" . $_SESSION['scriptcase']['reg_conf']['monet_f_pos'] . ":" . $_SESSION['scriptcase']['reg_conf']['monet_f_neg'], $_SESSION['scriptcase']['reg_conf']['simb_neg'], $_SESSION['scriptcase']['reg_conf']['unid_mont_group_digit']) ; 
         if ($_SESSION['scriptcase']['charset'] == "UTF-8" && !NM_is_utf8($this->ytd))
         {
             $this->ytd = mb_convert_encoding($this->ytd, "UTF-8");
         }
         $this->xml_registro .= " ytd =\"" . $this->trata_dados($this->ytd) . "\"";
   }
   //----- qtd
   function NM_export_qtd()
   {
         nmgp_Form_Num_Val($this->qtd, $_SESSION['scriptcase']['reg_conf']['grup_val'], $_SESSION['scriptcase']['reg_conf']['dec_val'], "2", "S", "2", "", "V:" . $_SESSION['scriptcase']['reg_conf']['monet_f_pos'] . ":" . $_SESSION['scriptcase']['reg_conf']['monet_f_neg'], $_SESSION['scriptcase']['reg_conf']['simb_neg'], $_SESSION['scriptcase']['reg_conf']['unid_mont_group_digit']) ; 
         if ($_SESSION['scriptcase']['charset'] == "UTF-8" && !NM_is_utf8($this->qtd))
         {
             $this->qtd = mb_convert_encoding($this->qtd, "UTF-8");
         }
         $this->xml_registro .= " qtd =\"" . $this->trata_dados($this->qtd) . "\"";
   }
   //----- jan
   function NM_export_jan()
   {
         nmgp_Form_Num_Val($this->jan, $_SESSION['scriptcase']['reg_conf']['grup_val'], $_SESSION['scriptcase']['reg_conf']['dec_val'], "2", "S", "2", "", "V:" . $_SESSION['scriptcase']['reg_conf']['monet_f_pos'] . ":" . $_SESSION['scriptcase']['reg_conf']['monet_f_neg'], $_SESSION['scriptcase']['reg_conf']['simb_neg'], $_SESSION['scriptcase']['reg_conf']['unid_mont_group_digit']) ; 
         if ($_SESSION['scriptcase']['charset'] == "UTF-8" && !NM_is_utf8($this->jan))
         {
             $this->jan = mb_convert_encoding($this->jan, "UTF-8");
         }
         $this->xml_registro .= " jan =\"" . $this->trata_dados($this->jan) . "\"";
   }
   //----- feb
   function NM_export_feb()
   {
         nmgp_Form_Num_Val($this->feb, $_SESSION['scriptcase']['reg_conf']['grup_val'], $_SESSION['scriptcase']['reg_conf']['dec_val'], "2", "S", "2", "", "V:" . $_SESSION['scriptcase']['reg_conf']['monet_f_pos'] . ":" . $_SESSION['scriptcase']['reg_conf']['monet_f_neg'], $_SESSION['scriptcase']['reg_conf']['simb_neg'], $_SESSION['scriptcase']['reg_conf']['unid_mont_group_digit']) ; 
         if ($_SESSION['scriptcase']['charset'] == "UTF-8" && !NM_is_utf8($this->feb))
         {
             $this->feb = mb_convert_encoding($this->feb, "UTF-8");
         }
         $this->xml_registro .= " feb =\"" . $this->trata_dados($this->feb) . "\"";
   }
   //----- mar
   function NM_export_mar()
   {
         nmgp_Form_Num_Val($this->mar, $_SESSION['scriptcase']['reg_conf']['grup_val'], $_SESSION['scriptcase']['reg_conf']['dec_val'], "2", "S", "2", "", "V:" . $_SESSION['scriptcase']['reg_conf']['monet_f_pos'] . ":" . $_SESSION['scriptcase']['reg_conf']['monet_f_neg'], $_SESSION['scriptcase']['reg_conf']['simb_neg'], $_SESSION['scriptcase']['reg_conf']['unid_mont_group_digit']) ; 
         if ($_SESSION['scriptcase']['charset'] == "UTF-8" && !NM_is_utf8($this->mar))
         {
             $this->mar = mb_convert_encoding($this->mar, "UTF-8");
         }
         $this->xml_registro .= " mar =\"" . $this->trata_dados($this->mar) . "\"";
   }
   //----- apr
   function NM_export_apr()
   {
         nmgp_Form_Num_Val($this->apr, $_SESSION['scriptcase']['reg_conf']['grup_val'], $_SESSION['scriptcase']['reg_conf']['dec_val'], "2", "S", "2", "", "V:" . $_SESSION['scriptcase']['reg_conf']['monet_f_pos'] . ":" . $_SESSION['scriptcase']['reg_conf']['monet_f_neg'], $_SESSION['scriptcase']['reg_conf']['simb_neg'], $_SESSION['scriptcase']['reg_conf']['unid_mont_group_digit']) ; 
         if ($_SESSION['scriptcase']['charset'] == "UTF-8" && !NM_is_utf8($this->apr))
         {
             $this->apr = mb_convert_encoding($this->apr, "UTF-8");
         }
         $this->xml_registro .= " apr =\"" . $this->trata_dados($this->apr) . "\"";
   }
   //----- may
   function NM_export_may()
   {
         nmgp_Form_Num_Val($this->may, $_SESSION['scriptcase']['reg_conf']['grup_val'], $_SESSION['scriptcase']['reg_conf']['dec_val'], "2", "S", "2", "", "V:" . $_SESSION['scriptcase']['reg_conf']['monet_f_pos'] . ":" . $_SESSION['scriptcase']['reg_conf']['monet_f_neg'], $_SESSION['scriptcase']['reg_conf']['simb_neg'], $_SESSION['scriptcase']['reg_conf']['unid_mont_group_digit']) ; 
         if ($_SESSION['scriptcase']['charset'] == "UTF-8" && !NM_is_utf8($this->may))
         {
             $this->may = mb_convert_encoding($this->may, "UTF-8");
         }
         $this->xml_registro .= " may =\"" . $this->trata_dados($this->may) . "\"";
   }
   //----- jun
   function NM_export_jun()
   {
         nmgp_Form_Num_Val($this->jun, $_SESSION['scriptcase']['reg_conf']['grup_val'], $_SESSION['scriptcase']['reg_conf']['dec_val'], "2", "S", "2", "", "V:" . $_SESSION['scriptcase']['reg_conf']['monet_f_pos'] . ":" . $_SESSION['scriptcase']['reg_conf']['monet_f_neg'], $_SESSION['scriptcase']['reg_conf']['simb_neg'], $_SESSION['scriptcase']['reg_conf']['unid_mont_group_digit']) ; 
         if ($_SESSION['scriptcase']['charset'] == "UTF-8" && !NM_is_utf8($this->jun))
         {
             $this->jun = mb_convert_encoding($this->jun, "UTF-8");
         }
         $this->xml_registro .= " jun =\"" . $this->trata_dados($this->jun) . "\"";
   }
   //----- jul
   function NM_export_jul()
   {
         nmgp_Form_Num_Val($this->jul, $_SESSION['scriptcase']['reg_conf']['grup_val'], $_SESSION['scriptcase']['reg_conf']['dec_val'], "2", "S", "2", "", "V:" . $_SESSION['scriptcase']['reg_conf']['monet_f_pos'] . ":" . $_SESSION['scriptcase']['reg_conf']['monet_f_neg'], $_SESSION['scriptcase']['reg_conf']['simb_neg'], $_SESSION['scriptcase']['reg_conf']['unid_mont_group_digit']) ; 
         if ($_SESSION['scriptcase']['charset'] == "UTF-8" && !NM_is_utf8($this->jul))
         {
             $this->jul = mb_convert_encoding($this->jul, "UTF-8");
         }
         $this->xml_registro .= " jul =\"" . $this->trata_dados($this->jul) . "\"";
   }
   //----- aug
   function NM_export_aug()
   {
         nmgp_Form_Num_Val($this->aug, $_SESSION['scriptcase']['reg_conf']['grup_val'], $_SESSION['scriptcase']['reg_conf']['dec_val'], "2", "S", "2", "", "V:" . $_SESSION['scriptcase']['reg_conf']['monet_f_pos'] . ":" . $_SESSION['scriptcase']['reg_conf']['monet_f_neg'], $_SESSION['scriptcase']['reg_conf']['simb_neg'], $_SESSION['scriptcase']['reg_conf']['unid_mont_group_digit']) ; 
         if ($_SESSION['scriptcase']['charset'] == "UTF-8" && !NM_is_utf8($this->aug))
         {
             $this->aug = mb_convert_encoding($this->aug, "UTF-8");
         }
         $this->xml_registro .= " aug =\"" . $this->trata_dados($this->aug) . "\"";
   }
   //----- sep
   function NM_export_sep()
   {
         nmgp_Form_Num_Val($this->sep, $_SESSION['scriptcase']['reg_conf']['grup_val'], $_SESSION['scriptcase']['reg_conf']['dec_val'], "2", "S", "2", "", "V:" . $_SESSION['scriptcase']['reg_conf']['monet_f_pos'] . ":" . $_SESSION['scriptcase']['reg_conf']['monet_f_neg'], $_SESSION['scriptcase']['reg_conf']['simb_neg'], $_SESSION['scriptcase']['reg_conf']['unid_mont_group_digit']) ; 
         if ($_SESSION['scriptcase']['charset'] == "UTF-8" && !NM_is_utf8($this->sep))
         {
             $this->sep = mb_convert_encoding($this->sep, "UTF-8");
         }
         $this->xml_registro .= " sep =\"" . $this->trata_dados($this->sep) . "\"";
   }
   //----- oct
   function NM_export_oct()
   {
         nmgp_Form_Num_Val($this->oct, $_SESSION['scriptcase']['reg_conf']['grup_val'], $_SESSION['scriptcase']['reg_conf']['dec_val'], "2", "S", "2", "", "V:" . $_SESSION['scriptcase']['reg_conf']['monet_f_pos'] . ":" . $_SESSION['scriptcase']['reg_conf']['monet_f_neg'], $_SESSION['scriptcase']['reg_conf']['simb_neg'], $_SESSION['scriptcase']['reg_conf']['unid_mont_group_digit']) ; 
         if ($_SESSION['scriptcase']['charset'] == "UTF-8" && !NM_is_utf8($this->oct))
         {
             $this->oct = mb_convert_encoding($this->oct, "UTF-8");
         }
         $this->xml_registro .= " oct =\"" . $this->trata_dados($this->oct) . "\"";
   }
   //----- nov
   function NM_export_nov()
   {
         nmgp_Form_Num_Val($this->nov, $_SESSION['scriptcase']['reg_conf']['grup_val'], $_SESSION['scriptcase']['reg_conf']['dec_val'], "2", "S", "2", "", "V:" . $_SESSION['scriptcase']['reg_conf']['monet_f_pos'] . ":" . $_SESSION['scriptcase']['reg_conf']['monet_f_neg'], $_SESSION['scriptcase']['reg_conf']['simb_neg'], $_SESSION['scriptcase']['reg_conf']['unid_mont_group_digit']) ; 
         if ($_SESSION['scriptcase']['charset'] == "UTF-8" && !NM_is_utf8($this->nov))
         {
             $this->nov = mb_convert_encoding($this->nov, "UTF-8");
         }
         $this->xml_registro .= " nov =\"" . $this->trata_dados($this->nov) . "\"";
   }
   //----- dec
   function NM_export_dec()
   {
         nmgp_Form_Num_Val($this->dec, $_SESSION['scriptcase']['reg_conf']['grup_val'], $_SESSION['scriptcase']['reg_conf']['dec_val'], "2", "S", "2", "", "V:" . $_SESSION['scriptcase']['reg_conf']['monet_f_pos'] . ":" . $_SESSION['scriptcase']['reg_conf']['monet_f_neg'], $_SESSION['scriptcase']['reg_conf']['simb_neg'], $_SESSION['scriptcase']['reg_conf']['unid_mont_group_digit']) ; 
         if ($_SESSION['scriptcase']['charset'] == "UTF-8" && !NM_is_utf8($this->dec))
         {
             $this->dec = mb_convert_encoding($this->dec, "UTF-8");
         }
         $this->xml_registro .= " dec =\"" . $this->trata_dados($this->dec) . "\"";
   }
   //----- lyear
   function NM_export_lyear()
   {
         nmgp_Form_Num_Val($this->lyear, $_SESSION['scriptcase']['reg_conf']['grup_val'], $_SESSION['scriptcase']['reg_conf']['dec_val'], "2", "S", "2", "", "V:" . $_SESSION['scriptcase']['reg_conf']['monet_f_pos'] . ":" . $_SESSION['scriptcase']['reg_conf']['monet_f_neg'], $_SESSION['scriptcase']['reg_conf']['simb_neg'], $_SESSION['scriptcase']['reg_conf']['unid_mont_group_digit']) ; 
         if ($_SESSION['scriptcase']['charset'] == "UTF-8" && !NM_is_utf8($this->lyear))
         {
             $this->lyear = mb_convert_encoding($this->lyear, "UTF-8");
         }
         $this->xml_registro .= " lyear =\"" . $this->trata_dados($this->lyear) . "\"";
   }
   //----- llyear
   function NM_export_llyear()
   {
         nmgp_Form_Num_Val($this->llyear, $_SESSION['scriptcase']['reg_conf']['grup_val'], $_SESSION['scriptcase']['reg_conf']['dec_val'], "2", "S", "2", "", "V:" . $_SESSION['scriptcase']['reg_conf']['monet_f_pos'] . ":" . $_SESSION['scriptcase']['reg_conf']['monet_f_neg'], $_SESSION['scriptcase']['reg_conf']['simb_neg'], $_SESSION['scriptcase']['reg_conf']['unid_mont_group_digit']) ; 
         if ($_SESSION['scriptcase']['charset'] == "UTF-8" && !NM_is_utf8($this->llyear))
         {
             $this->llyear = mb_convert_encoding($this->llyear, "UTF-8");
         }
         $this->xml_registro .= " llyear =\"" . $this->trata_dados($this->llyear) . "\"";
   }
   //----- q1
   function NM_export_q1()
   {
         nmgp_Form_Num_Val($this->q1, $_SESSION['scriptcase']['reg_conf']['grup_val'], $_SESSION['scriptcase']['reg_conf']['dec_val'], "2", "S", "2", "", "V:" . $_SESSION['scriptcase']['reg_conf']['monet_f_pos'] . ":" . $_SESSION['scriptcase']['reg_conf']['monet_f_neg'], $_SESSION['scriptcase']['reg_conf']['simb_neg'], $_SESSION['scriptcase']['reg_conf']['unid_mont_group_digit']) ; 
         if ($_SESSION['scriptcase']['charset'] == "UTF-8" && !NM_is_utf8($this->q1))
         {
             $this->q1 = mb_convert_encoding($this->q1, "UTF-8");
         }
         $this->xml_registro .= " q1 =\"" . $this->trata_dados($this->q1) . "\"";
   }
   //----- q2
   function NM_export_q2()
   {
         nmgp_Form_Num_Val($this->q2, $_SESSION['scriptcase']['reg_conf']['grup_val'], $_SESSION['scriptcase']['reg_conf']['dec_val'], "2", "S", "2", "", "V:" . $_SESSION['scriptcase']['reg_conf']['monet_f_pos'] . ":" . $_SESSION['scriptcase']['reg_conf']['monet_f_neg'], $_SESSION['scriptcase']['reg_conf']['simb_neg'], $_SESSION['scriptcase']['reg_conf']['unid_mont_group_digit']) ; 
         if ($_SESSION['scriptcase']['charset'] == "UTF-8" && !NM_is_utf8($this->q2))
         {
             $this->q2 = mb_convert_encoding($this->q2, "UTF-8");
         }
         $this->xml_registro .= " q2 =\"" . $this->trata_dados($this->q2) . "\"";
   }
   //----- q3
   function NM_export_q3()
   {
         nmgp_Form_Num_Val($this->q3, $_SESSION['scriptcase']['reg_conf']['grup_val'], $_SESSION['scriptcase']['reg_conf']['dec_val'], "2", "S", "2", "", "V:" . $_SESSION['scriptcase']['reg_conf']['monet_f_pos'] . ":" . $_SESSION['scriptcase']['reg_conf']['monet_f_neg'], $_SESSION['scriptcase']['reg_conf']['simb_neg'], $_SESSION['scriptcase']['reg_conf']['unid_mont_group_digit']) ; 
         if ($_SESSION['scriptcase']['charset'] == "UTF-8" && !NM_is_utf8($this->q3))
         {
             $this->q3 = mb_convert_encoding($this->q3, "UTF-8");
         }
         $this->xml_registro .= " q3 =\"" . $this->trata_dados($this->q3) . "\"";
   }
   //----- q4
   function NM_export_q4()
   {
         nmgp_Form_Num_Val($this->q4, $_SESSION['scriptcase']['reg_conf']['grup_val'], $_SESSION['scriptcase']['reg_conf']['dec_val'], "2", "S", "2", "", "V:" . $_SESSION['scriptcase']['reg_conf']['monet_f_pos'] . ":" . $_SESSION['scriptcase']['reg_conf']['monet_f_neg'], $_SESSION['scriptcase']['reg_conf']['simb_neg'], $_SESSION['scriptcase']['reg_conf']['unid_mont_group_digit']) ; 
         if ($_SESSION['scriptcase']['charset'] == "UTF-8" && !NM_is_utf8($this->q4))
         {
             $this->q4 = mb_convert_encoding($this->q4, "UTF-8");
         }
         $this->xml_registro .= " q4 =\"" . $this->trata_dados($this->q4) . "\"";
   }
   //----- updated
   function NM_export_updated()
   {
         $conteudo_x =  $this->updated;
         nm_conv_limpa_dado($conteudo_x, "YYYY-MM-DD");
         if (is_numeric($conteudo_x) && $conteudo_x > 0) 
         { 
             $this->nm_data->SetaData($this->updated, "YYYY-MM-DD");
             $this->updated = $this->nm_data->FormataSaida($this->Nm_date_format("DT", "ddmmaaaa"));
         } 
         if ($_SESSION['scriptcase']['charset'] == "UTF-8" && !NM_is_utf8($this->updated))
         {
             $this->updated = mb_convert_encoding($this->updated, "UTF-8");
         }
         $this->xml_registro .= " updated =\"" . $this->trata_dados($this->updated) . "\"";
   }
   //----- s365
   function NM_export_s365()
   {
         nmgp_Form_Num_Val($this->s365, $_SESSION['scriptcase']['reg_conf']['grup_val'], $_SESSION['scriptcase']['reg_conf']['dec_val'], "2", "S", "2", "", "V:" . $_SESSION['scriptcase']['reg_conf']['monet_f_pos'] . ":" . $_SESSION['scriptcase']['reg_conf']['monet_f_neg'], $_SESSION['scriptcase']['reg_conf']['simb_neg'], $_SESSION['scriptcase']['reg_conf']['unid_mont_group_digit']) ; 
         if ($_SESSION['scriptcase']['charset'] == "UTF-8" && !NM_is_utf8($this->s365))
         {
             $this->s365 = mb_convert_encoding($this->s365, "UTF-8");
         }
         $this->xml_registro .= " s365 =\"" . $this->trata_dados($this->s365) . "\"";
   }
   //----- temp
   function NM_export_temp()
   {
         if ($_SESSION['scriptcase']['charset'] == "UTF-8" && !NM_is_utf8($this->temp))
         {
             $this->temp = mb_convert_encoding($this->temp, "UTF-8");
         }
         $this->xml_registro .= " temp =\"" . $this->trata_dados($this->temp) . "\"";
   }
   //----- id2
   function NM_export_id2()
   {
         nmgp_Form_Num_Val($this->id2, $_SESSION['scriptcase']['reg_conf']['grup_num'], $_SESSION['scriptcase']['reg_conf']['dec_num'], "0", "S", "2", "", "N:" . $_SESSION['scriptcase']['reg_conf']['neg_num'] , $_SESSION['scriptcase']['reg_conf']['simb_neg'], $_SESSION['scriptcase']['reg_conf']['num_group_digit']) ; 
         if ($_SESSION['scriptcase']['charset'] == "UTF-8" && !NM_is_utf8($this->id2))
         {
             $this->id2 = mb_convert_encoding($this->id2, "UTF-8");
         }
         $this->xml_registro .= " id2 =\"" . $this->trata_dados($this->id2) . "\"";
   }

   //----- 
   function trata_dados($conteudo)
   {
      $str_temp =  $conteudo;
      $str_temp =  str_replace("<br />", "",  $str_temp);
      $str_temp =  str_replace("&", "&amp;",  $str_temp);
      $str_temp =  str_replace("<", "&lt;",   $str_temp);
      $str_temp =  str_replace(">", "&gt;",   $str_temp);
      $str_temp =  str_replace("'", "&apos;", $str_temp);
      $str_temp =  str_replace('"', "&quot;",  $str_temp);
      $str_temp =  str_replace('(', "_",  $str_temp);
      $str_temp =  str_replace(')', "",  $str_temp);
      return ($str_temp);
   }

   function nm_conv_data_db($dt_in, $form_in, $form_out)
   {
       $dt_out = $dt_in;
       if (strtoupper($form_in) == "DB_FORMAT")
       {
           if ($dt_out == "null" || $dt_out == "")
           {
               $dt_out = "";
               return $dt_out;
           }
           $form_in = "AAAA-MM-DD";
       }
       if (strtoupper($form_out) == "DB_FORMAT")
       {
           if (empty($dt_out))
           {
               $dt_out = "null";
               return $dt_out;
           }
           $form_out = "AAAA-MM-DD";
       }
       nm_conv_form_data($dt_out, $form_in, $form_out);
       return $dt_out;
   }
   //---- 
   function monta_html()
   {
      global $nm_url_saida, $nm_lang;
      include($this->Ini->path_btn . $this->Ini->Str_btn_grid);
      unset($_SESSION['sc_session'][$this->Ini->sc_page]['pdfreport_custbill']['xml_file']);
      if (is_file($this->Ini->root . $this->Ini->path_imag_temp . "/" . $this->arquivo))
      {
          $_SESSION['sc_session'][$this->Ini->sc_page]['pdfreport_custbill']['xml_file'] = $this->Ini->root . $this->Ini->path_imag_temp . "/" . $this->arquivo;
      }
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
            "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<HTML<?php echo $_SESSION['scriptcase']['reg_conf']['html_dir'] ?>>
<HEAD>
 <TITLE><?php echo $this->Ini->Nm_lang['lang_othr_grid_titl'] ?> - custbill :: XML</TITLE>
 <META http-equiv="Content-Type" content="text/html; charset=<?php echo $_SESSION['scriptcase']['charset_html'] ?>" />
 <META http-equiv="Expires" content="Fri, Jan 01 1900 00:00:00 GMT"/>
 <META http-equiv="Last-Modified" content="<?php echo gmdate("D, d M Y H:i:s"); ?> GMT"/>
 <META http-equiv="Cache-Control" content="no-store, no-cache, must-revalidate"/>
 <META http-equiv="Cache-Control" content="post-check=0, pre-check=0"/>
 <META http-equiv="Pragma" content="no-cache"/>
  <link rel="stylesheet" type="text/css" href="../_lib/css/<?php echo $this->Ini->str_schema_all ?>_export.css" /> 
  <link rel="stylesheet" type="text/css" href="../_lib/buttons/<?php echo $this->Ini->Str_btn_css ?>" /> 
</HEAD>
<BODY class="scExportPage">
<?php echo $this->Ini->Ajax_result_set ?>
<table style="border-collapse: collapse; border-width: 0; height: 100%; width: 100%"><tr><td style="padding: 0; text-align: center; vertical-align: middle">
 <table class="scExportTable" align="center">
  <tr>
   <td class="scExportTitle" style="height: 25px">XML</td>
  </tr>
  <tr>
   <td class="scExportLine" style="width: 100%">
    <table style="border-collapse: collapse; border-width: 0; width: 100%"><tr><td class="scExportLineFont" style="padding: 3px 0 0 0" id="idMessage">
    <?php echo $this->Ini->Nm_lang['lang_othr_file_msge'] ?>
    </td><td class="scExportLineFont" style="text-align:right; padding: 3px 0 0 0">
     <?php echo nmButtonOutput($this->arr_buttons, "bexportview", "document.Fview.submit()", "document.Fview.submit()", "idBtnView", "", "", "", "", "", "", $this->Ini->path_botoes, "", "", "", "", "", "only_text", "text_right", "", "");
 ?>
     <?php echo nmButtonOutput($this->arr_buttons, "bdownload", "document.Fdown.submit()", "document.Fdown.submit()", "idBtnDown", "", "", "", "", "", "", $this->Ini->path_botoes, "", "", "", "", "", "only_text", "text_right", "", "");
 ?>
     <?php echo nmButtonOutput($this->arr_buttons, "bvoltar", "document.F0.submit()", "document.F0.submit()", "idBtnBack", "", "", "", "", "", "", $this->Ini->path_botoes, "", "", "", "", "", "only_text", "text_right", "", "");
 ?>
    </td></tr></table>
   </td>
  </tr>
 </table>
</td></tr></table>
<form name="Fview" method="get" action="<?php echo $this->Ini->path_imag_temp . "/" . $this->arquivo_view ?>" target="_blank" style="display: none"> 
</form>
<form name="Fdown" method="get" action="pdfreport_custbill_download.php" target="_blank" style="display: none"> 
<input type="hidden" name="nm_tit_doc" value="<?php echo NM_encode_input($this->tit_doc); ?>"> 
<input type="hidden" name="nm_name_doc" value="<?php echo NM_encode_input($this->Ini->path_imag_temp . "/" . $this->arquivo) ?>"> 
</form>
<FORM name="F0" method=post action="./" style="display: none"> 
<INPUT type="hidden" name="script_case_init" value="<?php echo NM_encode_input($this->Ini->sc_page); ?>"> 
<INPUT type="hidden" name="script_case_session" value="<?php echo NM_encode_input(session_id()); ?>"> 
<INPUT type="hidden" name="nmgp_opcao" value="volta_grid"> 
</FORM> 
</BODY>
</HTML>
<?php
   }

 function Nm_date_format($Type, $Format)
 {
     $Form_base = str_replace("/", "", $Format);
     $Form_base = str_replace("-", "", $Form_base);
     $Form_base = str_replace(":", "", $Form_base);
     $Form_base = str_replace(";", "", $Form_base);
     $Form_base = str_replace(" ", "", $Form_base);
     $Form_base = str_replace("a", "Y", $Form_base);
     $Form_base = str_replace("y", "Y", $Form_base);
     $Form_base = str_replace("h", "H", $Form_base);
     $date_format_show = "";
     if ($Type == "DT" || $Type == "DH")
     {
         $Str_date = str_replace("a", "y", strtolower($_SESSION['scriptcase']['reg_conf']['date_format']));
         $Str_date = str_replace("y", "Y", $Str_date);
         $Str_date = str_replace("h", "H", $Str_date);
         $Lim   = strlen($Str_date);
         $Ult   = "";
         $Arr_D = array();
         for ($I = 0; $I < $Lim; $I++)
         {
              $Char = substr($Str_date, $I, 1);
              if ($Char != $Ult)
              {
                  $Arr_D[] = $Char;
              }
              $Ult = $Char;
         }
         $Prim = true;
         foreach ($Arr_D as $Cada_d)
         {
             if (strpos($Form_base, $Cada_d) !== false)
             {
                 $date_format_show .= (!$Prim) ? $_SESSION['scriptcase']['reg_conf']['date_sep'] : "";
                 $date_format_show .= $Cada_d;
                 $Prim = false;
             }
         }
     }
     if ($Type == "DH" || $Type == "HH")
     {
         if ($Type == "DH")
         {
             $date_format_show .= " ";
         }
         $Str_time = strtolower($_SESSION['scriptcase']['reg_conf']['time_format']);
         $Str_time = str_replace("h", "H", $Str_time);
         $Lim   = strlen($Str_time);
         $Ult   = "";
         $Arr_T = array();
         for ($I = 0; $I < $Lim; $I++)
         {
              $Char = substr($Str_time, $I, 1);
              if ($Char != $Ult)
              {
                  $Arr_T[] = $Char;
              }
              $Ult = $Char;
         }
         $Prim = true;
         foreach ($Arr_T as $Cada_t)
         {
             if (strpos($Form_base, $Cada_t) !== false)
             {
                 $date_format_show .= (!$Prim) ? $_SESSION['scriptcase']['reg_conf']['time_sep'] : "";
                 $date_format_show .= $Cada_t;
                 $Prim = false;
             }
         }
     }
     return $date_format_show;
 }

   function nm_gera_mask(&$nm_campo, $nm_mask)
   { 
      $trab_campo = $nm_campo;
      $trab_mask  = $nm_mask;
      $tam_campo  = strlen($nm_campo);
      $trab_saida = "";
      $mask_num = false;
      for ($x=0; $x < strlen($trab_mask); $x++)
      {
          if (substr($trab_mask, $x, 1) == "#")
          {
              $mask_num = true;
              break;
          }
      }
      if ($mask_num )
      {
          $ver_duas = explode(";", $trab_mask);
          if (isset($ver_duas[1]) && !empty($ver_duas[1]))
          {
              $cont1 = count(explode("#", $ver_duas[0])) - 1;
              $cont2 = count(explode("#", $ver_duas[1])) - 1;
              if ($cont2 >= $tam_campo)
              {
                  $trab_mask = $ver_duas[1];
              }
              else
              {
                  $trab_mask = $ver_duas[0];
              }
          }
          $tam_mask = strlen($trab_mask);
          $xdados = 0;
          for ($x=0; $x < $tam_mask; $x++)
          {
              if (substr($trab_mask, $x, 1) == "#" && $xdados < $tam_campo)
              {
                  $trab_saida .= substr($trab_campo, $xdados, 1);
                  $xdados++;
              }
              elseif ($xdados < $tam_campo)
              {
                  $trab_saida .= substr($trab_mask, $x, 1);
              }
          }
          if ($xdados < $tam_campo)
          {
              $trab_saida .= substr($trab_campo, $xdados);
          }
          $nm_campo = $trab_saida;
          return;
      }
      for ($ix = strlen($trab_mask); $ix > 0; $ix--)
      {
           $char_mask = substr($trab_mask, $ix - 1, 1);
           if ($char_mask != "x" && $char_mask != "z")
           {
               $trab_saida = $char_mask . $trab_saida;
           }
           else
           {
               if ($tam_campo != 0)
               {
                   $trab_saida = substr($trab_campo, $tam_campo - 1, 1) . $trab_saida;
                   $tam_campo--;
               }
               else
               {
                   $trab_saida = "0" . $trab_saida;
               }
           }
      }
      if ($tam_campo != 0)
      {
          $trab_saida = substr($trab_campo, 0, $tam_campo) . $trab_saida;
          $trab_mask  = str_repeat("z", $tam_campo) . $trab_mask;
      }
   
      $iz = 0; 
      for ($ix = 0; $ix < strlen($trab_mask); $ix++)
      {
           $char_mask = substr($trab_mask, $ix, 1);
           if ($char_mask != "x" && $char_mask != "z")
           {
               if ($char_mask == "." || $char_mask == ",")
               {
                   $trab_saida = substr($trab_saida, 0, $iz) . substr($trab_saida, $iz + 1);
               }
               else
               {
                   $iz++;
               }
           }
           elseif ($char_mask == "x" || substr($trab_saida, $iz, 1) != "0")
           {
               $ix = strlen($trab_mask) + 1;
           }
           else
           {
               $trab_saida = substr($trab_saida, 0, $iz) . substr($trab_saida, $iz + 1);
           }
      }
      $nm_campo = $trab_saida;
   } 
}

?>
