<?php
//
class recherche_fiche_ps_mob_apl
{
   var $has_where_params = false;
   var $NM_is_redirected = false;
   var $NM_non_ajax_info = false;
   var $formatado = false;
   var $use_100perc_fields = true;
   var $classes_100perc_fields = array();
   var $close_modal_after_insert = false;
   var $NM_ajax_flag    = false;
   var $NM_ajax_opcao   = '';
   var $NM_ajax_retorno = '';
   var $NM_ajax_info    = array('result'            => '',
                                'param'             => array(),
                                'autoComp'          => '',
                                'rsSize'            => '',
                                'msgDisplay'        => '',
                                'errList'           => array(),
                                'fldList'           => array(),
                                'varList'           => array(),
                                'focus'             => '',
                                'navStatus'         => array(),
                                'redir'             => array(),
                                'blockDisplay'      => array(),
                                'fieldDisplay'      => array(),
                                'fieldLabel'        => array(),
                                'readOnly'          => array(),
                                'btnVars'           => array(),
                                'ajaxAlert'         => array(),
                                'ajaxMessage'       => array(),
                                'ajaxJavascript'    => array(),
                                'buttonDisplay'     => array(),
                                'buttonDisplayVert' => array(),
                                'calendarReload'    => false,
                                'quickSearchRes'    => false,
                                'displayMsg'        => false,
                                'displayMsgTxt'     => '',
                                'dyn_search'        => array(),
                                'empty_filter'      => '',
                                'event_field'       => '',
                                'fieldsWithErrors'  => array(),
                               );
   var $NM_ajax_force_values = false;
   var $Nav_permite_ava     = true;
   var $Nav_permite_ret     = true;
   var $Apl_com_erro        = false;
   var $app_is_initializing = false;
   var $Ini;
   var $Erro;
   var $Db;
   var $code_fp;
   var $info;
   var $resultat;
   var $nin;
   var $nm_data;
   var $nmgp_opcao;
   var $nmgp_opc_ant;
   var $sc_evento;
   var $nmgp_clone;
   var $nmgp_return_img = array();
   var $nmgp_dados_form = array();
   var $nmgp_dados_select = array();
   var $nm_location;
   var $nm_flag_iframe;
   var $nm_flag_saida_novo;
   var $nmgp_botoes = array();
   var $nmgp_url_saida;
   var $nmgp_form_show;
   var $nmgp_form_empty;
   var $nmgp_cmp_readonly = array();
   var $nmgp_cmp_hidden   = array();
   var $Field_no_validate  = array();
   var $form_paginacao = 'parcial';
   var $lig_edit_lookup      = false;
   var $lig_edit_lookup_call = false;
   var $lig_edit_lookup_cb   = '';
   var $lig_edit_lookup_row  = '';
   var $is_calendar_app = false;
   var $Embutida_call  = false;
   var $Embutida_ronly = false;
   var $Embutida_proc  = false;
   var $Embutida_form  = false;
   var $Grid_editavel  = false;
   var $url_webhelp = '';
   var $nm_todas_criticas;
   var $Campos_Mens_erro;
   var $nm_new_label = array();
   var $record_insert_ok = false;
   var $record_delete_ok = false;
//
//----- 
   function ini_controle()
   {
        global $nm_url_saida, $teste_validade, $script_case_init, 
            $glo_senha_protect, $bok, $nm_apl_dependente, $nm_form_submit, $nm_opc_form_php, $nm_call_php, $nm_opc_lookup, $nmgp_redir;


      if ($this->NM_ajax_flag)
      {
          if (isset($this->NM_ajax_info['param']['code_fp']))
          {
              $this->code_fp = $this->NM_ajax_info['param']['code_fp'];
          }
          if (isset($this->NM_ajax_info['param']['csrf_token']))
          {
              $this->csrf_token = $this->NM_ajax_info['param']['csrf_token'];
          }
          if (isset($this->NM_ajax_info['param']['info']))
          {
              $this->info = $this->NM_ajax_info['param']['info'];
          }
          if (isset($this->NM_ajax_info['param']['nin']))
          {
              $this->nin = $this->NM_ajax_info['param']['nin'];
          }
          if (isset($this->NM_ajax_info['param']['nm_form_submit']))
          {
              $this->nm_form_submit = $this->NM_ajax_info['param']['nm_form_submit'];
          }
          if (isset($this->NM_ajax_info['param']['nmgp_ancora']))
          {
              $this->nmgp_ancora = $this->NM_ajax_info['param']['nmgp_ancora'];
          }
          if (isset($this->NM_ajax_info['param']['nmgp_arg_dyn_search']))
          {
              $this->nmgp_arg_dyn_search = $this->NM_ajax_info['param']['nmgp_arg_dyn_search'];
          }
          if (isset($this->NM_ajax_info['param']['nmgp_num_form']))
          {
              $this->nmgp_num_form = $this->NM_ajax_info['param']['nmgp_num_form'];
          }
          if (isset($this->NM_ajax_info['param']['nmgp_opcao']))
          {
              $this->nmgp_opcao = $this->NM_ajax_info['param']['nmgp_opcao'];
          }
          if (isset($this->NM_ajax_info['param']['nmgp_ordem']))
          {
              $this->nmgp_ordem = $this->NM_ajax_info['param']['nmgp_ordem'];
          }
          if (isset($this->NM_ajax_info['param']['nmgp_parms']))
          {
              $this->nmgp_parms = $this->NM_ajax_info['param']['nmgp_parms'];
          }
          if (isset($this->NM_ajax_info['param']['nmgp_url_saida']))
          {
              $this->nmgp_url_saida = $this->NM_ajax_info['param']['nmgp_url_saida'];
          }
          if (isset($this->NM_ajax_info['param']['resultat']))
          {
              $this->resultat = $this->NM_ajax_info['param']['resultat'];
          }
          if (isset($this->NM_ajax_info['param']['script_case_init']))
          {
              $this->script_case_init = $this->NM_ajax_info['param']['script_case_init'];
          }
          if (isset($this->nmgp_refresh_fields))
          {
              $this->nmgp_refresh_fields = explode('_#fld#_', $this->nmgp_refresh_fields);
              $this->nmgp_opcao          = 'recarga';
          }
          if (!isset($this->nmgp_refresh_row))
          {
              $this->nmgp_refresh_row = '';
          }
      }

      $this->scSajaxReservedWords = array('rs', 'rst', 'rsrnd', 'rsargs');
      $this->sc_conv_var = array();
      if (!empty($_FILES))
      {
          foreach ($_FILES as $nmgp_campo => $nmgp_valores)
          {
               if (!in_array(strtolower($nmgp_campo), $this->scSajaxReservedWords)) {
                   if (isset($this->sc_conv_var[$nmgp_campo]))
                   {
                       $nmgp_campo = $this->sc_conv_var[$nmgp_campo];
                   }
                   elseif (isset($this->sc_conv_var[strtolower($nmgp_campo)]))
                   {
                       $nmgp_campo = $this->sc_conv_var[strtolower($nmgp_campo)];
                   }
               }
               $tmp_scfile_name     = $nmgp_campo . "_scfile_name";
               $tmp_scfile_type     = $nmgp_campo . "_scfile_type";
               $this->$nmgp_campo = is_array($nmgp_valores['tmp_name']) ? $nmgp_valores['tmp_name'][0] : $nmgp_valores['tmp_name'];
               $this->$tmp_scfile_type   = is_array($nmgp_valores['type'])     ? $nmgp_valores['type'][0]     : $nmgp_valores['type'];
               $this->$tmp_scfile_name   = is_array($nmgp_valores['name'])     ? $nmgp_valores['name'][0]     : $nmgp_valores['name'];
          }
      }
      $Sc_lig_md5 = false;
      if (!empty($_POST))
      {
          foreach ($_POST as $nmgp_var => $nmgp_val)
          {
               if (substr($nmgp_var, 0, 11) == "SC_glo_par_")
               {
                   $nmgp_var = substr($nmgp_var, 11);
                   $nmgp_val = $_SESSION[$nmgp_val];
               }
              if ($nmgp_var == "nmgp_parms" && substr($nmgp_val, 0, 8) == "@SC_par@")
              {
                  $SC_Ind_Val = explode("@SC_par@", $nmgp_val);
                  if (count($SC_Ind_Val) == 4 && isset($_SESSION['sc_session'][$SC_Ind_Val[1]][$SC_Ind_Val[2]]['Lig_Md5'][$SC_Ind_Val[3]]))
                  {
                      $nmgp_val = $_SESSION['sc_session'][$SC_Ind_Val[1]][$SC_Ind_Val[2]]['Lig_Md5'][$SC_Ind_Val[3]];
                      $Sc_lig_md5 = true;
                  }
                  else
                  {
                      $_SESSION['sc_session']['SC_parm_violation'] = true;
                  }
              }
               if (!in_array(strtolower($nmgp_var), $this->scSajaxReservedWords)) {
                   if (isset($this->sc_conv_var[$nmgp_var]))
                   {
                       $nmgp_var = $this->sc_conv_var[$nmgp_var];
                   }
                   elseif (isset($this->sc_conv_var[strtolower($nmgp_var)]))
                   {
                       $nmgp_var = $this->sc_conv_var[strtolower($nmgp_var)];
                   }
               }
               $nmgp_val = NM_decode_input($nmgp_val);
               $this->$nmgp_var = $nmgp_val;
          }
      }
      if (!empty($_GET))
      {
          foreach ($_GET as $nmgp_var => $nmgp_val)
          {
               if (substr($nmgp_var, 0, 11) == "SC_glo_par_")
               {
                   $nmgp_var = substr($nmgp_var, 11);
                   $nmgp_val = $_SESSION[$nmgp_val];
               }
              if ($nmgp_var == "nmgp_parms" && substr($nmgp_val, 0, 8) == "@SC_par@")
              {
                  $SC_Ind_Val = explode("@SC_par@", $nmgp_val);
                  if (count($SC_Ind_Val) == 4 && isset($_SESSION['sc_session'][$SC_Ind_Val[1]][$SC_Ind_Val[2]]['Lig_Md5'][$SC_Ind_Val[3]]))
                  {
                      $nmgp_val = $_SESSION['sc_session'][$SC_Ind_Val[1]][$SC_Ind_Val[2]]['Lig_Md5'][$SC_Ind_Val[3]];
                      $Sc_lig_md5 = true;
                  }
                  else
                  {
                       $_SESSION['sc_session']['SC_parm_violation'] = true;
                  }
              }
               if (!in_array(strtolower($nmgp_var), $this->scSajaxReservedWords)) {
                   if (isset($this->sc_conv_var[$nmgp_var]))
                   {
                       $nmgp_var = $this->sc_conv_var[$nmgp_var];
                   }
                   elseif (isset($this->sc_conv_var[strtolower($nmgp_var)]))
                   {
                       $nmgp_var = $this->sc_conv_var[strtolower($nmgp_var)];
                   }
               }
               $nmgp_val = NM_decode_input($nmgp_val);
               $this->$nmgp_var = $nmgp_val;
          }
      }
      if (isset($SC_lig_apl_orig) && !$Sc_lig_md5 && (!isset($nmgp_parms) || ($nmgp_parms != "SC_null" && substr($nmgp_parms, 0, 8) != "OrScLink")))
      {
          $_SESSION['sc_session']['SC_parm_violation'] = true;
      }
      if (isset($nmgp_parms) && $nmgp_parms == "SC_null")
      {
          $nmgp_parms = "";
      }
      if (isset($this->nmgp_opcao) && $this->nmgp_opcao == "reload_novo") {
          $_POST['nmgp_opcao'] = "novo";
          $this->nmgp_opcao    = "novo";
          $_SESSION['sc_session'][$script_case_init]['recherche_fiche_ps_mob']['opcao']   = "novo";
          $_SESSION['sc_session'][$script_case_init]['recherche_fiche_ps_mob']['opc_ant'] = "inicio";
      }
      if (isset($_SESSION['sc_session'][$script_case_init]['recherche_fiche_ps_mob']['embutida_parms']))
      { 
          $this->nmgp_parms = $_SESSION['sc_session'][$script_case_init]['recherche_fiche_ps_mob']['embutida_parms'];
          unset($_SESSION['sc_session'][$script_case_init]['recherche_fiche_ps_mob']['embutida_parms']);
      } 
      if (isset($this->nmgp_parms) && !empty($this->nmgp_parms)) 
      { 
          if (isset($_SESSION['nm_aba_bg_color'])) 
          { 
              unset($_SESSION['nm_aba_bg_color']);
          }   
          $nmgp_parms = str_replace("@aspass@", "'", $this->nmgp_parms);
          $nmgp_parms = str_replace("*scout", "?@?", $nmgp_parms);
          $nmgp_parms = str_replace("*scin", "?#?", $nmgp_parms);
          $todox = str_replace("?#?@?@?", "?#?@ ?@?", $nmgp_parms);
          $todo  = explode("?@?", $todox);
          $ix = 0;
          while (!empty($todo[$ix]))
          {
             $cadapar = explode("?#?", $todo[$ix]);
             if (1 < sizeof($cadapar))
             {
                if (substr($cadapar[0], 0, 11) == "SC_glo_par_")
                {
                    $cadapar[0] = substr($cadapar[0], 11);
                    $cadapar[1] = $_SESSION[$cadapar[1]];
                }
                 if (isset($this->sc_conv_var[$cadapar[0]]))
                 {
                     $cadapar[0] = $this->sc_conv_var[$cadapar[0]];
                 }
                 elseif (isset($this->sc_conv_var[strtolower($cadapar[0])]))
                 {
                     $cadapar[0] = $this->sc_conv_var[strtolower($cadapar[0])];
                 }
                 nm_limpa_str_recherche_fiche_ps_mob($cadapar[1]);
                 if ($cadapar[1] == "@ ") {$cadapar[1] = trim($cadapar[1]); }
                 $Tmp_par = $cadapar[0];
                 $this->$Tmp_par = $cadapar[1];
             }
             $ix++;
          }
          if (isset($this->NM_where_filter_form))
          {
              $_SESSION['sc_session'][$script_case_init]['recherche_fiche_ps_mob']['where_filter_form'] = $this->NM_where_filter_form;
              unset($_SESSION['sc_session'][$script_case_init]['recherche_fiche_ps_mob']['total']);
          }
          if (isset($this->sc_redir_atualiz))
          {
              $_SESSION['sc_session'][$script_case_init]['recherche_fiche_ps_mob']['sc_redir_atualiz'] = $this->sc_redir_atualiz;
          }
          if (isset($this->sc_redir_insert))
          {
              $_SESSION['sc_session'][$script_case_init]['recherche_fiche_ps_mob']['sc_redir_insert'] = $this->sc_redir_insert;
          }
      } 
      elseif (isset($script_case_init) && !empty($script_case_init) && isset($_SESSION['sc_session'][$script_case_init]['recherche_fiche_ps_mob']['parms']))
      {
          if ((!isset($this->nmgp_opcao) || ($this->nmgp_opcao != "incluir" && $this->nmgp_opcao != "alterar" && $this->nmgp_opcao != "excluir" && $this->nmgp_opcao != "novo" && $this->nmgp_opcao != "recarga" && $this->nmgp_opcao != "muda_form")) && (!isset($this->NM_ajax_opcao) || $this->NM_ajax_opcao == ""))
          {
              $todox = str_replace("?#?@?@?", "?#?@ ?@?", $_SESSION['sc_session'][$script_case_init]['recherche_fiche_ps_mob']['parms']);
              $todo  = explode("?@?", $todox);
              $ix = 0;
              while (!empty($todo[$ix]))
              {
                 $cadapar = explode("?#?", $todo[$ix]);
                 if (substr($cadapar[0], 0, 11) == "SC_glo_par_")
                 {
                     $cadapar[0] = substr($cadapar[0], 11);
                     $cadapar[1] = $_SESSION[$cadapar[1]];
                 }
                 if ($cadapar[1] == "@ ") {$cadapar[1] = trim($cadapar[1]); }
                 $Tmp_par = $cadapar[0];
                 $this->$Tmp_par = $cadapar[1];
                 $ix++;
              }
          }
      } 

      if (isset($this->nm_run_menu) && $this->nm_run_menu == 1)
      { 
          $_SESSION['sc_session'][$script_case_init]['recherche_fiche_ps_mob']['nm_run_menu'] = 1;
      } 
      if (!$this->NM_ajax_flag && 'autocomp_' == substr($this->NM_ajax_opcao, 0, 9))
      {
          $this->NM_ajax_flag = true;
      }

      $dir_raiz          = strrpos($_SERVER['PHP_SELF'],"/") ;  
      $dir_raiz          = substr($_SERVER['PHP_SELF'], 0, $dir_raiz + 1) ;  
      if (isset($this->nm_evt_ret_edit) && '' != $this->nm_evt_ret_edit)
      {
          $_SESSION['sc_session'][$script_case_init]['recherche_fiche_ps_mob']['lig_edit_lookup']     = true;
          $_SESSION['sc_session'][$script_case_init]['recherche_fiche_ps_mob']['lig_edit_lookup_cb']  = $this->nm_evt_ret_edit;
          $_SESSION['sc_session'][$script_case_init]['recherche_fiche_ps_mob']['lig_edit_lookup_row'] = isset($this->nm_evt_ret_row) ? $this->nm_evt_ret_row : '';
      }
      if (isset($_SESSION['sc_session'][$script_case_init]['recherche_fiche_ps_mob']['lig_edit_lookup']) && $_SESSION['sc_session'][$script_case_init]['recherche_fiche_ps_mob']['lig_edit_lookup'])
      {
          $this->lig_edit_lookup     = true;
          $this->lig_edit_lookup_cb  = $_SESSION['sc_session'][$script_case_init]['recherche_fiche_ps_mob']['lig_edit_lookup_cb'];
          $this->lig_edit_lookup_row = $_SESSION['sc_session'][$script_case_init]['recherche_fiche_ps_mob']['lig_edit_lookup_row'];
      }
      if (!$this->Ini)
      { 
          $this->Ini = new recherche_fiche_ps_mob_ini(); 
          $this->Ini->init();
          $this->nm_data = new nm_data("fr");
          $this->app_is_initializing = $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['initialize'];
          $this->Db = $this->Ini->Db; 
          if (isset($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['initialize']) && $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['initialize'])
          {
              $_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  $_SESSION['recherche_fiche_ps_mob']['code_p'] = false;
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
          if (isset($_SESSION['scriptcase']['sc_apl_conf']['recherche_fiche_ps']))
          {
              foreach ($_SESSION['scriptcase']['sc_apl_conf']['recherche_fiche_ps'] as $I_conf => $Conf_opt)
              {
                  $_SESSION['scriptcase']['sc_apl_conf']['recherche_fiche_ps_mob'][$I_conf]  = $Conf_opt;
              }
          }
          }
          $this->Ini->init2();
      } 
      else 
      { 
         $this->nm_data = new nm_data("fr");
      } 
      $_SESSION['sc_session'][$script_case_init]['recherche_fiche_ps_mob']['upload_field_info'] = array();

      unset($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['masterValue']);
      $this->Change_Menu = false;
      $run_iframe = (isset($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['run_iframe']) && ($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['run_iframe'] == "F" || $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['run_iframe'] == "R")) ? true : false;
      if (!$run_iframe && isset($_SESSION['scriptcase']['menu_atual']) && (!isset($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['sc_outra_jan']) || !$_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['sc_outra_jan']))
      {
          $this->sc_init_menu = "x";
          if (isset($_SESSION['scriptcase'][$_SESSION['scriptcase']['menu_atual']]['sc_init']['recherche_fiche_ps_mob']))
          {
              $this->sc_init_menu = $_SESSION['scriptcase'][$_SESSION['scriptcase']['menu_atual']]['sc_init']['recherche_fiche_ps_mob'];
          }
          elseif (isset($_SESSION['scriptcase']['menu_apls'][$_SESSION['scriptcase']['menu_atual']]))
          {
              foreach ($_SESSION['scriptcase']['menu_apls'][$_SESSION['scriptcase']['menu_atual']] as $init => $resto)
              {
                  if ($this->Ini->sc_page == $init)
                  {
                      $this->sc_init_menu = $init;
                      break;
                  }
              }
          }
          if ($this->Ini->sc_page == $this->sc_init_menu && !isset($_SESSION['scriptcase']['menu_apls'][$_SESSION['scriptcase']['menu_atual']][$this->sc_init_menu]['recherche_fiche_ps_mob']))
          {
               $_SESSION['scriptcase']['menu_apls'][$_SESSION['scriptcase']['menu_atual']][$this->sc_init_menu]['recherche_fiche_ps_mob']['link'] = $this->Ini->sc_protocolo . $this->Ini->server . $this->Ini->path_link . "" . SC_dir_app_name('recherche_fiche_ps_mob') . "/recherche_fiche_ps_mob.php";
               $_SESSION['scriptcase']['menu_apls'][$_SESSION['scriptcase']['menu_atual']][$this->sc_init_menu]['recherche_fiche_ps_mob']['label'] = "Rechercher une fiche de malade";
               $this->Change_Menu = true;
          }
          elseif ($this->Ini->sc_page == $this->sc_init_menu)
          {
              $achou = false;
              foreach ($_SESSION['scriptcase']['menu_apls'][$_SESSION['scriptcase']['menu_atual']][$this->sc_init_menu] as $apl => $parms)
              {
                  if ($apl == "recherche_fiche_ps_mob")
                  {
                      $achou = true;
                  }
                  elseif ($achou)
                  {
                      unset($_SESSION['scriptcase']['menu_apls'][$_SESSION['scriptcase']['menu_atual']][$this->sc_init_menu][$apl]);
                      $this->Change_Menu = true;
                  }
              }
          }
      }
      if (!function_exists("nmButtonOutput"))
      {
          include_once($this->Ini->path_lib_php . "nm_gp_config_btn.php");
      }
      include("../_lib/css/" . $this->Ini->str_schema_all . "_form.php");
      $this->Ini->Str_btn_form    = trim($str_button);
      include($this->Ini->path_btn . $this->Ini->Str_btn_form . '/' . $this->Ini->Str_btn_form . $_SESSION['scriptcase']['reg_conf']['css_dir'] . '.php');
      $_SESSION['scriptcase']['css_form_help'] = '../_lib/css/' . $this->Ini->str_schema_all . "_form.css";
      $_SESSION['scriptcase']['css_form_help_dir'] = '../_lib/css/' . $this->Ini->str_schema_all . "_form" . $_SESSION['scriptcase']['reg_conf']['css_dir'] . ".css";
      $this->Db = $this->Ini->Db; 
      $this->Ini->str_google_fonts = isset($str_google_fonts)?$str_google_fonts:'';
      $this->Ini->Img_sep_form    = "/" . trim($str_toolbar_separator);
      $this->Ini->Color_bg_ajax   = !isset($str_ajax_bg)         || "" == trim($str_ajax_bg)         ? "#000" : $str_ajax_bg;
      $this->Ini->Border_c_ajax   = !isset($str_ajax_border_c)   || "" == trim($str_ajax_border_c)   ? ""     : $str_ajax_border_c;
      $this->Ini->Border_s_ajax   = !isset($str_ajax_border_s)   || "" == trim($str_ajax_border_s)   ? ""     : $str_ajax_border_s;
      $this->Ini->Border_w_ajax   = !isset($str_ajax_border_w)   || "" == trim($str_ajax_border_w)   ? ""     : $str_ajax_border_w;
      $this->Ini->Block_img_exp   = !isset($str_block_exp)       || "" == trim($str_block_exp)       ? ""     : $str_block_exp;
      $this->Ini->Block_img_col   = !isset($str_block_col)       || "" == trim($str_block_col)       ? ""     : $str_block_col;
      $this->Ini->Msg_ico_title   = !isset($str_msg_ico_title)   || "" == trim($str_msg_ico_title)   ? ""     : $str_msg_ico_title;
      $this->Ini->Msg_ico_body    = !isset($str_msg_ico_body)    || "" == trim($str_msg_ico_body)    ? ""     : $str_msg_ico_body;
      $this->Ini->Err_ico_title   = !isset($str_err_ico_title)   || "" == trim($str_err_ico_title)   ? ""     : $str_err_ico_title;
      $this->Ini->Err_ico_body    = !isset($str_err_ico_body)    || "" == trim($str_err_ico_body)    ? ""     : $str_err_ico_body;
      $this->Ini->Cal_ico_back    = !isset($str_cal_ico_back)    || "" == trim($str_cal_ico_back)    ? ""     : $str_cal_ico_back;
      $this->Ini->Cal_ico_for     = !isset($str_cal_ico_for)     || "" == trim($str_cal_ico_for)     ? ""     : $str_cal_ico_for;
      $this->Ini->Cal_ico_close   = !isset($str_cal_ico_close)   || "" == trim($str_cal_ico_close)   ? ""     : $str_cal_ico_close;
      $this->Ini->Tab_space       = !isset($str_tab_space)       || "" == trim($str_tab_space)       ? ""     : $str_tab_space;
      $this->Ini->Bubble_tail     = !isset($str_bubble_tail)     || "" == trim($str_bubble_tail)     ? ""     : $str_bubble_tail;
      $this->Ini->Label_sort_pos  = !isset($str_label_sort_pos)  || "" == trim($str_label_sort_pos)  ? ""     : $str_label_sort_pos;
      $this->Ini->Label_sort      = !isset($str_label_sort)      || "" == trim($str_label_sort)      ? ""     : $str_label_sort;
      $this->Ini->Label_sort_asc  = !isset($str_label_sort_asc)  || "" == trim($str_label_sort_asc)  ? ""     : $str_label_sort_asc;
      $this->Ini->Label_sort_desc = !isset($str_label_sort_desc) || "" == trim($str_label_sort_desc) ? ""     : $str_label_sort_desc;
      $this->Ini->Img_status_ok       = !isset($str_img_status_ok)  || "" == trim($str_img_status_ok)   ? ""     : $str_img_status_ok;
      $this->Ini->Img_status_err      = !isset($str_img_status_err) || "" == trim($str_img_status_err)  ? ""     : $str_img_status_err;
      $this->Ini->Css_status          = "scFormInputError";
      $this->Ini->Css_status_pwd_box  = "scFormInputErrorPwdBox";
      $this->Ini->Css_status_pwd_text = "scFormInputErrorPwdText";
      $this->Ini->Error_icon_span      = !isset($str_error_icon_span)  || "" == trim($str_error_icon_span)  ? false  : "message" == $str_error_icon_span;
      $this->Ini->Img_qs_search        = !isset($img_qs_search)        || "" == trim($img_qs_search)        ? "scriptcase__NM__qs_lupa.png"  : $img_qs_search;
      $this->Ini->Img_qs_clean         = !isset($img_qs_clean)         || "" == trim($img_qs_clean)         ? "scriptcase__NM__qs_close.png" : $img_qs_clean;
      $this->Ini->Str_qs_image_padding = !isset($str_qs_image_padding) || "" == trim($str_qs_image_padding) ? "0"                            : $str_qs_image_padding;
      $this->Ini->App_div_tree_img_col = trim($app_div_str_tree_col);
      $this->Ini->App_div_tree_img_exp = trim($app_div_str_tree_exp);
      $this->Ini->form_table_width     = isset($str_form_table_width) && '' != trim($str_form_table_width) ? $str_form_table_width : '';

        $this->classes_100perc_fields['table'] = '';
        $this->classes_100perc_fields['input'] = '';
        $this->classes_100perc_fields['span_input'] = '';
        $this->classes_100perc_fields['span_select'] = '';
        $this->classes_100perc_fields['style_category'] = '';
        $this->classes_100perc_fields['keep_field_size'] = true;
        if ($this->use_100perc_fields) {
            $this->classes_100perc_fields['table'] = ' sc-ui-100perc-table';
            $this->classes_100perc_fields['input'] = ' sc-ui-100perc-input';
            $this->classes_100perc_fields['span_input'] = ' sc-ui-100perc-span-input';
            $this->classes_100perc_fields['span_select'] = ' sc-ui-100perc-span-select';
            $this->classes_100perc_fields['style_category'] = ' style="width: 100%"';
            $this->classes_100perc_fields['keep_field_size'] = false;
        }


      $this->arr_buttons['fiche_patient']['hint']             = "";
      $this->arr_buttons['fiche_patient']['type']             = "button";
      $this->arr_buttons['fiche_patient']['value']            = "Voir la Fiche";
      $this->arr_buttons['fiche_patient']['display']          = "text_fontawesomeicon";
      $this->arr_buttons['fiche_patient']['display_position'] = "text_right";
      $this->arr_buttons['fiche_patient']['style']            = "facebook";
      $this->arr_buttons['fiche_patient']['image']            = "";
      $this->arr_buttons['fiche_patient']['has_fa']            = "true";
      $this->arr_buttons['fiche_patient']['fontawesomeicon']            = "fas fa-tv";

      $this->arr_buttons['recherche_fiche']['hint']             = "";
      $this->arr_buttons['recherche_fiche']['type']             = "button";
      $this->arr_buttons['recherche_fiche']['value']            = "Rechercher une fiche de malade";
      $this->arr_buttons['recherche_fiche']['display']          = "text_fontawesomeicon";
      $this->arr_buttons['recherche_fiche']['display_position'] = "text_right";
      $this->arr_buttons['recherche_fiche']['style']            = "default";
      $this->arr_buttons['recherche_fiche']['image']            = "";
      $this->arr_buttons['recherche_fiche']['has_fa']            = "true";
      $this->arr_buttons['recherche_fiche']['fontawesomeicon']            = "fas fa-search";


      $_SESSION['scriptcase']['error_icon']['recherche_fiche_ps_mob']  = "<img src=\"" . $this->Ini->path_icones . "/scriptcase__NM__btn__NM__scriptcase9_Rhino__NM__nm_scriptcase9_Rhino_error.png\" style=\"border-width: 0px\" align=\"top\">&nbsp;";
      $_SESSION['scriptcase']['error_close']['recherche_fiche_ps_mob'] = "<td>" . nmButtonOutput($this->arr_buttons, "berrm_clse", "document.getElementById('id_error_display_fixed').style.display = 'none'; document.getElementById('id_error_message_fixed').innerHTML = ''; return false", "document.getElementById('id_error_display_fixed').style.display = 'none'; document.getElementById('id_error_message_fixed').innerHTML = ''; return false", "", "", "", "", "", "", "", $this->Ini->path_botoes, "", "", "", "", "") . "</td>";

      $this->Embutida_proc = isset($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['embutida_proc']) ? $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['embutida_proc'] : $this->Embutida_proc;
      $this->Embutida_form = isset($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['embutida_form']) ? $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['embutida_form'] : $this->Embutida_form;
      $this->Embutida_call = isset($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['embutida_call']) ? $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['embutida_call'] : $this->Embutida_call;

      $this->form_3versions_single = false;

       $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['table_refresh'] = false;

      if (isset($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['embutida_liga_grid_edit']) && '' != $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['embutida_liga_grid_edit'])
      {
          $this->Grid_editavel = ('on' == $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['embutida_liga_grid_edit']) ? true : false;
      }
      if (isset($this->Grid_editavel) && $this->Grid_editavel)
      {
          $this->Embutida_form  = true;
          $this->Embutida_ronly = true;
      }
      $this->Embutida_multi = false;
      if (isset($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['embutida_multi']) && $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['embutida_multi'])
      {
          $this->Grid_editavel  = false;
          $this->Embutida_form  = false;
          $this->Embutida_ronly = false;
          $this->Embutida_multi = true;
      }
      if (isset($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['embutida_liga_tp_pag']) && '' != $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['embutida_liga_tp_pag'])
      {
          $this->form_paginacao = $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['embutida_liga_tp_pag'];
      }

      if (!isset($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['embutida_form']) || '' == $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['embutida_form'])
      {
          $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['embutida_form'] = $this->Embutida_form;
      }
      if (!isset($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['embutida_liga_grid_edit']) || '' == $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['embutida_liga_grid_edit'])
      {
          $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['embutida_liga_grid_edit'] = $this->Grid_editavel ? 'on' : 'off';
      }
      if (!isset($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['embutida_liga_grid_edit']) || '' == $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['embutida_liga_grid_edit'])
      {
          $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['embutida_liga_grid_edit'] = $this->Embutida_call;
      }

      $this->Ini->cor_grid_par = $this->Ini->cor_grid_impar;
      $this->nm_location = $this->Ini->sc_protocolo . $this->Ini->server . $dir_raiz . "recherche_fiche_ps_mob.php"; 
      $this->nmgp_url_saida  = $nm_url_saida;
      $this->nmgp_form_show  = "on";
      $this->nmgp_form_empty = false;
      $this->Ini->sc_Include($this->Ini->path_lib_php . "/nm_valida.php", "C", "NM_Valida") ; 
      $teste_validade = new NM_Valida ;

      $this->loadFieldConfig();

      if ($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['first_time'])
      {
          unset($_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['insert']);
          unset($_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['new']);
          unset($_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['update']);
          unset($_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['delete']);
          unset($_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['first']);
          unset($_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['back']);
          unset($_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['forward']);
          unset($_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['last']);
          unset($_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['qsearch']);
          unset($_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['dynsearch']);
          unset($_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['summary']);
          unset($_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['navpage']);
          unset($_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['goto']);
      }
      $this->NM_cancel_return_new = (isset($this->NM_cancel_return_new) && $this->NM_cancel_return_new == 1) ? "1" : "";
      $this->NM_cancel_insert_new = ((isset($this->NM_cancel_insert_new) && $this->NM_cancel_insert_new == 1) || $this->NM_cancel_return_new == 1) ? "document.F5.action='" . $nm_url_saida . "';" : "";
      if (isset($this->NM_btn_insert) && '' != $this->NM_btn_insert && (!isset($_SESSION['scriptcase']['sc_apl_conf']['recherche_fiche_ps_mob']['insert']) || '' == $_SESSION['scriptcase']['sc_apl_conf']['recherche_fiche_ps_mob']['insert']))
      {
          if ('N' == $this->NM_btn_insert)
          {
              $_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['insert'] = 'off';
          }
          else
          {
              $_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['insert'] = 'on';
          }
      }
      if (isset($this->NM_btn_new) && 'N' == $this->NM_btn_new)
      {
          $_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['new'] = 'off';
      }
      if (isset($this->NM_btn_update) && '' != $this->NM_btn_update && (!isset($_SESSION['scriptcase']['sc_apl_conf']['recherche_fiche_ps_mob']['update']) || '' == $_SESSION['scriptcase']['sc_apl_conf']['recherche_fiche_ps_mob']['update']))
      {
          if ('N' == $this->NM_btn_update)
          {
              $_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['update'] = 'off';
          }
          else
          {
              $_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['update'] = 'on';
          }
      }
      if (isset($this->NM_btn_delete) && '' != $this->NM_btn_delete && (!isset($_SESSION['scriptcase']['sc_apl_conf']['recherche_fiche_ps_mob']['delete']) || '' == $_SESSION['scriptcase']['sc_apl_conf']['recherche_fiche_ps_mob']['delete']))
      {
          if ('N' == $this->NM_btn_delete)
          {
              $_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['delete'] = 'off';
          }
          else
          {
              $_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['delete'] = 'on';
          }
      }
      if (isset($this->NM_btn_navega) && '' != $this->NM_btn_navega)
      {
          if ('N' == $this->NM_btn_navega)
          {
              $_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['first']     = 'off';
              $_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['back']      = 'off';
              $_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['forward']   = 'off';
              $_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['last']      = 'off';
              $_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['qsearch']   = 'off';
              $_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['dynsearch'] = 'off';
              $_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['summary']   = 'off';
              $_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['navpage']   = 'off';
              $_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['goto']      = 'off';
              $this->Nav_permite_ava = false;
              $this->Nav_permite_ret = false;
          }
          else
          {
              $_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['first']     = 'on';
              $_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['back']      = 'on';
              $_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['forward']   = 'on';
              $_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['last']      = 'on';
              $_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['qsearch']   = 'on';
              $_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['dynsearch'] = 'on';
              $_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['summary']   = 'on';
              $_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['navpage']   = 'on';
              $_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['goto']      = 'on';
          }
      }

      $this->nmgp_botoes['cancel'] = "on";
      $this->nmgp_botoes['exit'] = "on";
      $this->nmgp_botoes['ok'] = "on";
      $this->nmgp_botoes['facebook'] = "off";
      $this->nmgp_botoes['google'] = "off";
      $this->nmgp_botoes['twitter'] = "off";
      $this->nmgp_botoes['paypal'] = "off";
      $this->nmgp_botoes['fiche_patient'] = "on";
      $this->nmgp_botoes['recherche_fiche'] = "on";
      if (isset($this->NM_btn_cancel) && 'N' == $this->NM_btn_cancel)
      {
          $this->nmgp_botoes['cancel'] = "off";
      }
      $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['where_orig'] = "";
      if (!isset($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['where_pesq']))
      {
          $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['where_pesq'] = "";
          $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['where_pesq_filtro'] = "";
      }
      $this->sc_where_orig   = $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['where_orig'];
      $this->sc_where_atual  = $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['where_pesq'];
      $this->sc_where_filtro = $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['where_pesq_filtro'];
      if ($this->NM_ajax_flag && 'event_' == substr($this->NM_ajax_opcao, 0, 6)) {
          $this->nmgp_botoes = $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['buttonStatus'];
      }
      if (isset($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['iframe_filtro']) && $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['iframe_filtro'] == "S")
      {
          $this->nmgp_botoes['exit'] = "off";
      }
      if (isset($_SESSION['scriptcase']['sc_apl_conf']['recherche_fiche_ps_mob']['btn_display']) && !empty($_SESSION['scriptcase']['sc_apl_conf']['recherche_fiche_ps_mob']['btn_display']))
      {
          foreach ($_SESSION['scriptcase']['sc_apl_conf']['recherche_fiche_ps_mob']['btn_display'] as $NM_cada_btn => $NM_cada_opc)
          {
              $this->nmgp_botoes[$NM_cada_btn] = $NM_cada_opc;
          }
      }

      if (isset($_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['insert']) && $_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['insert'] != '')
      {
          $this->nmgp_botoes['new']    = $_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['insert'];
          $this->nmgp_botoes['insert'] = $_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['insert'];
      }
      if (isset($_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['new']) && $_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['new'] != '')
      {
          $this->nmgp_botoes['new']    = $_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['new'];
      }
      if (isset($_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['update']) && $_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['update'] != '')
      {
          $this->nmgp_botoes['update'] = $_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['update'];
      }
      if (isset($_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['delete']) && $_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['delete'] != '')
      {
          $this->nmgp_botoes['delete'] = $_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['delete'];
      }
      if (isset($_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['first']) && $_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['first'] != '')
      {
          $this->nmgp_botoes['first'] = $_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['first'];
      }
      if (isset($_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['back']) && $_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['back'] != '')
      {
          $this->nmgp_botoes['back'] = $_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['back'];
      }
      if (isset($_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['forward']) && $_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['forward'] != '')
      {
          $this->nmgp_botoes['forward'] = $_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['forward'];
      }
      if (isset($_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['last']) && $_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['last'] != '')
      {
          $this->nmgp_botoes['last'] = $_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['last'];
      }
      if (isset($_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['qsearch']) && $_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['qsearch'] != '')
      {
          $this->nmgp_botoes['qsearch'] = $_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['qsearch'];
      }
      if (isset($_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['dynsearch']) && $_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['dynsearch'] != '')
      {
          $this->nmgp_botoes['dynsearch'] = $_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['dynsearch'];
      }
      if (isset($_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['summary']) && $_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['summary'] != '')
      {
          $this->nmgp_botoes['summary'] = $_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['summary'];
      }
      if (isset($_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['navpage']) && $_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['navpage'] != '')
      {
          $this->nmgp_botoes['navpage'] = $_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['navpage'];
      }
      if (isset($_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['goto']) && $_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['goto'] != '')
      {
          $this->nmgp_botoes['goto'] = $_SESSION['scriptcase']['sc_apl_conf_lig']['recherche_fiche_ps_mob']['goto'];
      }

      if (isset($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['embutida_liga_form_insert']) && $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['embutida_liga_form_insert'] != '')
      {
          $this->nmgp_botoes['new']    = $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['embutida_liga_form_insert'];
          $this->nmgp_botoes['insert'] = $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['embutida_liga_form_insert'];
      }
      if (isset($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['embutida_liga_form_update']) && $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['embutida_liga_form_update'] != '')
      {
          $this->nmgp_botoes['update'] = $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['embutida_liga_form_update'];
      }
      if (isset($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['embutida_liga_form_delete']) && $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['embutida_liga_form_delete'] != '')
      {
          $this->nmgp_botoes['delete'] = $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['embutida_liga_form_delete'];
      }
      if (isset($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['embutida_liga_form_btn_nav']) && $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['embutida_liga_form_btn_nav'] != '')
      {
          $this->nmgp_botoes['first']   = $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['embutida_liga_form_btn_nav'];
          $this->nmgp_botoes['back']    = $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['embutida_liga_form_btn_nav'];
          $this->nmgp_botoes['forward'] = $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['embutida_liga_form_btn_nav'];
          $this->nmgp_botoes['last']    = $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['embutida_liga_form_btn_nav'];
      }

      if (isset($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['dashboard_info']['under_dashboard']) && $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['dashboard_info']['under_dashboard'] && !$_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['dashboard_info']['maximized']) {
          $tmpDashboardApp = $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['dashboard_info']['dashboard_app'];
          if (isset($_SESSION['scriptcase']['dashboard_toolbar'][$tmpDashboardApp]['recherche_fiche_ps_mob'])) {
              $tmpDashboardButtons = $_SESSION['scriptcase']['dashboard_toolbar'][$tmpDashboardApp]['recherche_fiche_ps_mob'];

              $this->nmgp_botoes['update']     = $tmpDashboardButtons['form_update']    ? 'on' : 'off';
              $this->nmgp_botoes['new']        = $tmpDashboardButtons['form_insert']    ? 'on' : 'off';
              $this->nmgp_botoes['insert']     = $tmpDashboardButtons['form_insert']    ? 'on' : 'off';
              $this->nmgp_botoes['delete']     = $tmpDashboardButtons['form_delete']    ? 'on' : 'off';
              $this->nmgp_botoes['copy']       = $tmpDashboardButtons['form_copy']      ? 'on' : 'off';
              $this->nmgp_botoes['first']      = $tmpDashboardButtons['form_navigate']  ? 'on' : 'off';
              $this->nmgp_botoes['back']       = $tmpDashboardButtons['form_navigate']  ? 'on' : 'off';
              $this->nmgp_botoes['last']       = $tmpDashboardButtons['form_navigate']  ? 'on' : 'off';
              $this->nmgp_botoes['forward']    = $tmpDashboardButtons['form_navigate']  ? 'on' : 'off';
              $this->nmgp_botoes['navpage']    = $tmpDashboardButtons['form_navpage']   ? 'on' : 'off';
              $this->nmgp_botoes['goto']       = $tmpDashboardButtons['form_goto']      ? 'on' : 'off';
              $this->nmgp_botoes['qtline']     = $tmpDashboardButtons['form_lineqty']   ? 'on' : 'off';
              $this->nmgp_botoes['summary']    = $tmpDashboardButtons['form_summary']   ? 'on' : 'off';
              $this->nmgp_botoes['qsearch']    = $tmpDashboardButtons['form_qsearch']   ? 'on' : 'off';
              $this->nmgp_botoes['dynsearch']  = $tmpDashboardButtons['form_dynsearch'] ? 'on' : 'off';
              $this->nmgp_botoes['reload']     = $tmpDashboardButtons['form_reload']    ? 'on' : 'off';
          }
      }

      if (isset($_SESSION['scriptcase']['sc_apl_conf']['recherche_fiche_ps_mob']['insert']) && $_SESSION['scriptcase']['sc_apl_conf']['recherche_fiche_ps_mob']['insert'] != '')
      {
          $this->nmgp_botoes['new']    = $_SESSION['scriptcase']['sc_apl_conf']['recherche_fiche_ps_mob']['insert'];
          $this->nmgp_botoes['insert'] = $_SESSION['scriptcase']['sc_apl_conf']['recherche_fiche_ps_mob']['insert'];
      }
      if (isset($_SESSION['scriptcase']['sc_apl_conf']['recherche_fiche_ps_mob']['update']) && $_SESSION['scriptcase']['sc_apl_conf']['recherche_fiche_ps_mob']['update'] != '')
      {
          $this->nmgp_botoes['update'] = $_SESSION['scriptcase']['sc_apl_conf']['recherche_fiche_ps_mob']['update'];
      }
      if (isset($_SESSION['scriptcase']['sc_apl_conf']['recherche_fiche_ps_mob']['delete']) && $_SESSION['scriptcase']['sc_apl_conf']['recherche_fiche_ps_mob']['delete'] != '')
      {
          $this->nmgp_botoes['delete'] = $_SESSION['scriptcase']['sc_apl_conf']['recherche_fiche_ps_mob']['delete'];
      }

      if (isset($_SESSION['scriptcase']['sc_apl_conf']['recherche_fiche_ps_mob']['field_display']) && !empty($_SESSION['scriptcase']['sc_apl_conf']['recherche_fiche_ps_mob']['field_display']))
      {
          foreach ($_SESSION['scriptcase']['sc_apl_conf']['recherche_fiche_ps_mob']['field_display'] as $NM_cada_field => $NM_cada_opc)
          {
              $this->nmgp_cmp_hidden[$NM_cada_field] = $NM_cada_opc;
              $this->NM_ajax_info['fieldDisplay'][$NM_cada_field] = $NM_cada_opc;
          }
      }
      if (isset($_SESSION['scriptcase']['sc_apl_conf']['recherche_fiche_ps_mob']['field_readonly']) && !empty($_SESSION['scriptcase']['sc_apl_conf']['recherche_fiche_ps_mob']['field_readonly']))
      {
          foreach ($_SESSION['scriptcase']['sc_apl_conf']['recherche_fiche_ps_mob']['field_readonly'] as $NM_cada_field => $NM_cada_opc)
          {
              $this->nmgp_cmp_readonly[$NM_cada_field] = "on";
              $this->NM_ajax_info['readOnly'][$NM_cada_field] = $NM_cada_opc;
          }
      }
      if (isset($_SESSION['scriptcase']['sc_apl_conf']['recherche_fiche_ps_mob']['exit']) && $_SESSION['scriptcase']['sc_apl_conf']['recherche_fiche_ps_mob']['exit'] != '')
      {
          $_SESSION['scriptcase']['sc_url_saida'][$this->Ini->sc_page]       = $_SESSION['scriptcase']['sc_apl_conf']['recherche_fiche_ps_mob']['exit'];
          $_SESSION['scriptcase']['sc_force_url_saida'][$this->Ini->sc_page] = true;
      }
      if (isset($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['dados_form']))
      {
          $this->nmgp_dados_form = $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['dados_form'];
      }
      $glo_senha_protect = (isset($_SESSION['scriptcase']['glo_senha_protect'])) ? $_SESSION['scriptcase']['glo_senha_protect'] : "S";
      $this->aba_iframe = false;
      if (isset($_SESSION['scriptcase']['sc_aba_iframe']))
      {
          foreach ($_SESSION['scriptcase']['sc_aba_iframe'] as $aba => $apls_aba)
          {
              if (in_array("recherche_fiche_ps_mob", $apls_aba))
              {
                  $this->aba_iframe = true;
                  break;
              }
          }
      }
      if ($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['iframe_menu'] && (!isset($_SESSION['scriptcase']['menu_mobile']) || empty($_SESSION['scriptcase']['menu_mobile'])))
      {
          $this->aba_iframe = true;
      }
      $this->Ini->sc_Include($this->Ini->path_lib_php . "/nm_gp_limpa.php", "F", "nm_limpa_valor") ; 
      $this->Ini->sc_Include($this->Ini->path_libs . "/nm_gc.php", "F", "nm_gc") ; 
      $_SESSION['scriptcase']['sc_tab_meses']['int'] = array(
                                      $this->Ini->Nm_lang['lang_mnth_janu'],
                                      $this->Ini->Nm_lang['lang_mnth_febr'],
                                      $this->Ini->Nm_lang['lang_mnth_marc'],
                                      $this->Ini->Nm_lang['lang_mnth_apri'],
                                      $this->Ini->Nm_lang['lang_mnth_mayy'],
                                      $this->Ini->Nm_lang['lang_mnth_june'],
                                      $this->Ini->Nm_lang['lang_mnth_july'],
                                      $this->Ini->Nm_lang['lang_mnth_augu'],
                                      $this->Ini->Nm_lang['lang_mnth_sept'],
                                      $this->Ini->Nm_lang['lang_mnth_octo'],
                                      $this->Ini->Nm_lang['lang_mnth_nove'],
                                      $this->Ini->Nm_lang['lang_mnth_dece']);
      $_SESSION['scriptcase']['sc_tab_meses']['abr'] = array(
                                      $this->Ini->Nm_lang['lang_shrt_mnth_janu'],
                                      $this->Ini->Nm_lang['lang_shrt_mnth_febr'],
                                      $this->Ini->Nm_lang['lang_shrt_mnth_marc'],
                                      $this->Ini->Nm_lang['lang_shrt_mnth_apri'],
                                      $this->Ini->Nm_lang['lang_shrt_mnth_mayy'],
                                      $this->Ini->Nm_lang['lang_shrt_mnth_june'],
                                      $this->Ini->Nm_lang['lang_shrt_mnth_july'],
                                      $this->Ini->Nm_lang['lang_shrt_mnth_augu'],
                                      $this->Ini->Nm_lang['lang_shrt_mnth_sept'],
                                      $this->Ini->Nm_lang['lang_shrt_mnth_octo'],
                                      $this->Ini->Nm_lang['lang_shrt_mnth_nove'],
                                      $this->Ini->Nm_lang['lang_shrt_mnth_dece']);
      $_SESSION['scriptcase']['sc_tab_dias']['int'] = array(
                                      $this->Ini->Nm_lang['lang_days_sund'],
                                      $this->Ini->Nm_lang['lang_days_mond'],
                                      $this->Ini->Nm_lang['lang_days_tued'],
                                      $this->Ini->Nm_lang['lang_days_wend'],
                                      $this->Ini->Nm_lang['lang_days_thud'],
                                      $this->Ini->Nm_lang['lang_days_frid'],
                                      $this->Ini->Nm_lang['lang_days_satd']);
      $_SESSION['scriptcase']['sc_tab_dias']['abr'] = array(
                                      $this->Ini->Nm_lang['lang_shrt_days_sund'],
                                      $this->Ini->Nm_lang['lang_shrt_days_mond'],
                                      $this->Ini->Nm_lang['lang_shrt_days_tued'],
                                      $this->Ini->Nm_lang['lang_shrt_days_wend'],
                                      $this->Ini->Nm_lang['lang_shrt_days_thud'],
                                      $this->Ini->Nm_lang['lang_shrt_days_frid'],
                                      $this->Ini->Nm_lang['lang_shrt_days_satd']);
      nm_gc($this->Ini->path_libs);
      $this->Ini->Gd_missing  = true;
      if(function_exists("getProdVersion"))
      {
         $_SESSION['scriptcase']['sc_prod_Version'] = str_replace(".", "", getProdVersion($this->Ini->path_libs));
         if(function_exists("gd_info"))
         {
            $this->Ini->Gd_missing = false;
         }
      }
      $this->Ini->sc_Include($this->Ini->path_lib_php . "/nm_trata_img.php", "C", "nm_trata_img") ; 

      if (is_file($this->Ini->path_aplicacao . 'recherche_fiche_ps_mob_help.txt'))
      {
          $arr_link_webhelp = file($this->Ini->path_aplicacao . 'recherche_fiche_ps_mob_help.txt');
          if ($arr_link_webhelp)
          {
              foreach ($arr_link_webhelp as $str_link_webhelp)
              {
                  $str_link_webhelp = trim($str_link_webhelp);
                  if ('contr:' == substr($str_link_webhelp, 0, 6))
                  {
                      $arr_link_parts = explode(':', $str_link_webhelp);
                      if ('' != $arr_link_parts[1] && is_file($this->Ini->root . $this->Ini->path_help . $arr_link_parts[1]))
                      {
                          $this->url_webhelp = $this->Ini->path_help . $arr_link_parts[1];
                      }
                  }
              }
          }
      }

      if (is_dir($this->Ini->path_aplicacao . 'img'))
      {
          $Res_dir_img = @opendir($this->Ini->path_aplicacao . 'img');
          if ($Res_dir_img)
          {
              while (FALSE !== ($Str_arquivo = @readdir($Res_dir_img))) 
              {
                 if (@is_file($this->Ini->path_aplicacao . 'img/' . $Str_arquivo) && '.' != $Str_arquivo && '..' != $this->Ini->path_aplicacao . 'img/' . $Str_arquivo)
                 {
                     @unlink($this->Ini->path_aplicacao . 'img/' . $Str_arquivo);
                 }
              }
          }
          @closedir($Res_dir_img);
          rmdir($this->Ini->path_aplicacao . 'img');
      }

      if ($this->Embutida_proc)
      { 
          require_once($this->Ini->path_embutida . 'recherche_fiche_ps/recherche_fiche_ps_mob_erro.class.php');
      }
      else
      { 
          require_once($this->Ini->path_aplicacao . "recherche_fiche_ps_mob_erro.class.php"); 
      }
      $this->Erro      = new recherche_fiche_ps_mob_erro();
      $this->Erro->Ini = $this->Ini;
      $this->proc_fast_search = false;
      if (isset($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['opcao']) && !empty($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['opcao']) && empty($this->nmgp_refresh_fields))
      {
          $this->nmgp_opcao = $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['opcao'];  
          $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['opcao'] = "" ;  
          if ($this->nmgp_opcao == "edit_novo")  
          {
             $this->nmgp_opcao = "novo";
             $this->nm_flag_saida_novo = "S";
          }
      } 
      $this->nm_Start_new = false;
      if (isset($_SESSION['scriptcase']['sc_apl_conf']['recherche_fiche_ps_mob']['start']) && $_SESSION['scriptcase']['sc_apl_conf']['recherche_fiche_ps_mob']['start'] == 'new')
      {
          $this->nmgp_opcao = "novo";
          $this->nm_Start_new = true;
          $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['opcao'] = "novo";
          unset($_SESSION['scriptcase']['sc_apl_conf']['recherche_fiche_ps_mob']['start']);
      }
      if ($this->nmgp_opcao == "igual")  
      {
          $this->nmgp_opc_ant = $this->nmgp_opcao;
      } 
      else
      {
          $this->nmgp_opc_ant = (isset($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['opc_ant'])) ? $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['opc_ant'] : "";
      } 
      if ($this->nmgp_opcao == "novo")  
      {
          $this->nmgp_botoes['fiche_patient'] = "off";
          $this->nmgp_botoes['recherche_fiche'] = "off";
      }
      elseif ($this->nmgp_opcao == "incluir")  
      {
          $this->nmgp_botoes['fiche_patient'] = $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['botoes']['fiche_patient'];
          $this->nmgp_botoes['recherche_fiche'] = $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['botoes']['recherche_fiche'];
      }
      if ($this->nmgp_opcao == "recarga" || $this->nmgp_opcao == "muda_form")  
      {
          $this->nmgp_botoes = $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['botoes'];
          $this->Nav_permite_ret = 0 != $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['inicio'];
          $this->Nav_permite_ava = $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['total'] != $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['final'];
      }
      else
      {
      }
      $this->nm_flag_iframe = false;
      if (isset($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['dados_form'])) 
      {
         $this->nmgp_dados_form = $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['dados_form'];
      }
      if ($this->nmgp_opcao == "edit_novo")  
      {
          $this->nmgp_opcao = "novo";
          $this->nm_flag_saida_novo = "S";
      }
//
      $this->NM_case_insensitive = false;
      $this->sc_evento = $this->nmgp_opcao;
            if ('ajax_check_file' == $this->nmgp_opcao ){
                 ob_start(); 
                 include_once("../_lib/lib/php/nm_api.php"); 
            switch( $_POST['rsargs'] ){
               default:
                   echo 0;exit;
               break;
               }

            $out1_img_cache = $_SESSION['scriptcase']['recherche_fiche_ps_mob']['glo_nm_path_imag_temp'] . $file_name;
            $orig_img = $_SESSION['scriptcase']['recherche_fiche_ps_mob']['glo_nm_path_imag_temp']. '/sc_'.md5(date('YmdHis').basename($_POST['AjaxCheckImg'])).'.gif';
            copy($__file_download, $_SERVER['DOCUMENT_ROOT'].$orig_img);
            echo $orig_img . '_@@NM@@_';            copy($__file_download, $_SERVER['DOCUMENT_ROOT'].$out1_img_cache);
            $sc_obj_img = new nm_trata_img($_SERVER['DOCUMENT_ROOT'].$out1_img_cache, true);

            if(!empty($img_width) && !empty($img_height)){
                $sc_obj_img->setWidth($img_width);
                $sc_obj_img->setHeight($img_height);
            }            $sc_obj_img->createImg($_SERVER['DOCUMENT_ROOT'].$out1_img_cache);
            echo $out1_img_cache;
               exit;
            }
      if ($nm_opc_form_php == "formphp")
      { 
          if ($nm_call_php == "fiche_patient")
          { 
              $this->sc_btn_fiche_patient();
          } 
          if ($nm_call_php == "recherche_fiche")
          { 
              $this->sc_btn_recherche_fiche();
          } 
          $this->NM_close_db(); 
          exit;
      } 
      $Campos_Crit       = "";
      $Campos_erro       = "";
      $Campos_Falta      = array();
      $Campos_Erros      = array();
      $dir_raiz          = strrpos($_SERVER['PHP_SELF'],"/") ;  
      $dir_raiz          =  substr($_SERVER['PHP_SELF'], 0, $dir_raiz + 1) ;  
      $this->Field_no_validate = (isset($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['Field_no_validate'])) ? $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['Field_no_validate'] : array();
      $this->nm_location = $this->Ini->sc_protocolo . $this->Ini->server . $dir_raiz . "recherche_fiche_ps_mob.php"; 
      $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['opc_edit'] = true;  
     if (isset($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['dados_select'])) 
     {
        $this->nmgp_dados_select = $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['dados_select'];
     }
   }

   function loadFieldConfig()
   {
      $this->field_config = array();
   }

   function controle()
   {
        global $nm_url_saida, $teste_validade, 
            $glo_senha_protect, $bok, $nm_apl_dependente, $nm_form_submit, $nm_opc_form_php, $nm_call_php, $nm_opc_lookup, $nmgp_redir;


      $this->ini_controle();
      if ($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['Gera_log_access'])
      {
          $this->NM_gera_log_insert("Scriptcase", "access");
          $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['Gera_log_access'] = false;
      }

      if ('' != $_SESSION['scriptcase']['change_regional_old'])
      {
          $_SESSION['scriptcase']['str_conf_reg'] = $_SESSION['scriptcase']['change_regional_old'];
          $this->Ini->regionalDefault($_SESSION['scriptcase']['str_conf_reg']);
          $this->loadFieldConfig();
          $this->nm_tira_formatacao();

          $_SESSION['scriptcase']['str_conf_reg'] = $_SESSION['scriptcase']['change_regional_new'];
          $this->Ini->regionalDefault($_SESSION['scriptcase']['str_conf_reg']);
          $this->loadFieldConfig();
          $guarda_formatado = $this->formatado;
          $this->nm_formatar_campos();
          $this->formatado = $guarda_formatado;

          $_SESSION['scriptcase']['change_regional_old'] = '';
          $_SESSION['scriptcase']['change_regional_new'] = '';
      }

      if ($nm_form_submit == 1 && ($this->nmgp_opcao == 'inicio' || $this->nmgp_opcao == 'igual'))
      {
          $this->nm_tira_formatacao();
      }
      if (!$this->NM_ajax_flag || 'alterar' != $this->nmgp_opcao || 'submit_form' != $this->NM_ajax_opcao)
      {
         $this->info = "Veuillez renseigner le code de la Fiche du malade, ou son NIN  dans les champs ci-dessous pour effectuer une recherche.";
         $this->resultat = "";
      }
//
//-----> 
//
      if ($this->NM_ajax_flag && 'validate_' == substr($this->NM_ajax_opcao, 0, 9))
      {
          if ('validate_code_fp' == $this->NM_ajax_opcao)
          {
              $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros, 'code_fp');
          }
          if ('validate_nin' == $this->NM_ajax_opcao)
          {
              $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros, 'nin');
          }
          recherche_fiche_ps_mob_pack_ajax_response();
          exit;
      }
      if ($this->NM_ajax_flag && 'event_' == substr($this->NM_ajax_opcao, 0, 6))
      {
          $this->nm_tira_formatacao();
          if ('event_scajaxbutton_recherche_fiche_onclick' == $this->NM_ajax_opcao)
          {
              $this->scajaxbutton_recherche_fiche_onClick();
          }
          recherche_fiche_ps_mob_pack_ajax_response();
          exit;
      }
      if (isset($this->sc_inline_call) && 'Y' == $this->sc_inline_call)
      {
          $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['inline_form_seq'] = $this->sc_seq_row;
          $this->nm_tira_formatacao();
      }
      if ($this->nmgp_opcao == "recarga" || $this->nmgp_opcao == "recarga_mobile" || $this->nmgp_opcao == "muda_form") 
      {
          $this->nm_tira_formatacao();
          $nm_sc_sv_opcao = $this->nmgp_opcao; 
          $this->nmgp_opcao = "nada"; 
          if ($this->NM_ajax_flag)
          {
              $this->ajax_return_values();
              recherche_fiche_ps_mob_pack_ajax_response();
              exit;
          }
          $this->nmgp_opcao = $nm_sc_sv_opcao; 
          $this->nm_gera_html();
          $this->NM_close_db(); 
          $this->nmgp_opcao = ""; 
          exit; 
      }
      if ($this->nmgp_opcao == "incluir" || $this->nmgp_opcao == "alterar" || $this->nmgp_opcao == "excluir") 
      {
          $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros) ; 
          if ($this->nmgp_opcao != "incluir")
          {
              $this->scFormFocusErrorName = '';
          }
          $_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
          if ($Campos_Crit != "") 
          {
              $Campos_Crit = $this->Ini->Nm_lang['lang_errm_flds'] . ' ' . $Campos_Crit ; 
          }
          if ($Campos_Crit != "" || !empty($Campos_Falta) || $this->Campos_Mens_erro != "")
          {
              if ($this->NM_ajax_flag)
              {
                  recherche_fiche_ps_mob_pack_ajax_response();
                  exit;
              }
              $campos_erro = $this->Formata_Erros($Campos_Crit, $Campos_Falta, $Campos_Erros, 4);
              $this->Campos_Mens_erro = ""; 
              $this->Erro->mensagem(__FILE__, __LINE__, "critica", $campos_erro, '', true, true); 
              $this->nmgp_opc_ant = $this->nmgp_opcao ; 
              if ($this->nmgp_opcao == "incluir" && $nm_apl_dependente == 1) 
              { 
                  $this->nm_flag_saida_novo = "S";; 
              }
              if ($this->nmgp_opcao == "incluir") 
              { 
                  $GLOBALS["erro_incl"] = 1; 
              }
              $this->nmgp_opcao = "nada" ; 
          }
      }
      elseif (isset($nm_form_submit) && 1 == $nm_form_submit && $this->nmgp_opcao != "menu_link" && $this->nmgp_opcao != "recarga_mobile")
      {
          $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros) ; 
          $_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
          if ($Campos_Crit != "") 
          {
              $Campos_Crit = $this->Ini->Nm_lang['lang_errm_flds'] . $Campos_Crit ; 
          }
          if ($Campos_Crit != "" || !empty($Campos_Falta) || $this->Campos_Mens_erro != "")
          {
              if ($this->NM_ajax_flag)
              {
                  recherche_fiche_ps_mob_pack_ajax_response();
                  exit;
              }
              $campos_erro = $this->Formata_Erros($Campos_Crit, $Campos_Falta, $Campos_Erros, '', true, true);
              $this->Campos_Mens_erro = ""; 
              $this->Erro->mensagem(__FILE__, __LINE__, "critica", $campos_erro); 
              $this->nmgp_opc_ant = $this->nmgp_opcao ; 
              if ($this->nmgp_opcao == "incluir") 
              { 
                  $GLOBALS["erro_incl"] = 1; 
              }
              $this->nmgp_opcao = "nada" ; 
          }
      }
//
      if (!isset($nm_form_submit) && $this->nmgp_opcao != "nada")
      {
          $this->code_fp = "" ;  
          $this->info = "" ;  
          $this->resultat = "" ;  
          $this->nin = "" ;  
          $this->info = "Veuillez renseigner le code de la Fiche du malade, ou son NIN  dans les champs ci-dessous pour effectuer une recherche.";
          $this->resultat = "";
          if (isset($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['dados_form']) && !empty($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['dados_form']))
          {
              foreach ($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['dados_form'] as $NM_campo => $NM_valor)
              {
                  $$NM_campo = $NM_valor;
              }
          }
      }
      else
      {
           if ($this->nmgp_opcao != "nada")
           {
           }
           if ($this->nmgp_opc_ant == "incluir") 
           { 
               $this->nm_proc_onload(false);
           }
           else
           { 
              $this->nm_guardar_campos();
           }
      }
      if ($this->nmgp_opcao != "recarga" && $this->nmgp_opcao != "muda_form" && !$this->Apl_com_erro)
      {
          $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['recarga'] = $this->nmgp_opcao;
      }
      if ($Campos_Crit != "" || !empty($Campos_Falta) || $this->Campos_Mens_erro != "" || $campos_erro != "" || !isset($this->bok) || $this->bok != "OK" || $this->nmgp_opcao == "recarga")
      {
          if ($Campos_Crit == "" && empty($Campos_Falta) && $this->Campos_Mens_erro == "" && !isset($this->bok) && $this->nmgp_opcao != "recarga")
          {
              if (isset($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['campos']))
              { 
                  $info = $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['campos'][0]; 
                  $code_fp = $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['campos'][1]; 
                  $nin = $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['campos'][2]; 
                  $resultat = $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['campos'][3]; 
              } 
          }
          $this->nm_gera_html();
          $this->NM_close_db(); 
      }
      elseif (isset($this->bok) && $this->bok == "OK")
      {
          $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['campos'] = array(); 
          $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['campos'][0] = $this->info; 
          $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['campos'][1] = $this->code_fp; 
          $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['campos'][2] = $this->nin; 
          $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['campos'][3] = $this->resultat; 
          if ($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['redir'] == "redir")
          {
              $this->nmgp_redireciona(); 
          }
          else
          {
              $contr_menu = "";
              if ($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['iframe_menu'])
              {
                  $contr_menu = "glo_menu";
              }
              if (isset($_SESSION['scriptcase']['sc_ult_apl_menu']) && in_array("recherche_fiche_ps_mob", $_SESSION['scriptcase']['sc_ult_apl_menu']))
              {
                  $this->NM_close_db(); 
                  $this->nmgp_redireciona_form("recherche_fiche_ps_mob_fim.php", $this->nm_location, $contr_menu); 
              }
              else
              {
                  $this->nm_gera_html();
                  if (!$_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['embutida_proc'])
                  { 
                      $this->NM_close_db(); 
                  } 
              }
          }
          $this->NM_close_db(); 
          if ($this->NM_ajax_flag)
          {
              recherche_fiche_ps_mob_pack_ajax_response();
              exit;
          }
      }
      $this->nmgp_opcao = ""; 
      if ($this->Change_Menu)
      {
          $apl_menu  = $_SESSION['scriptcase']['menu_atual'];
          $Arr_rastro = array();
          if (isset($_SESSION['scriptcase']['menu_apls'][$apl_menu][$this->sc_init_menu]) && count($_SESSION['scriptcase']['menu_apls'][$apl_menu][$this->sc_init_menu]) > 1)
          {
              foreach ($_SESSION['scriptcase']['menu_apls'][$apl_menu][$this->sc_init_menu] as $menu => $apls)
              {
                 $Arr_rastro[] = "'<a href=\"" . $apls['link'] . "?script_case_init=" . $this->sc_init_menu . "\" target=\"#NMIframe#\">" . $apls['label'] . "</a>'";
              }
              $ult_apl = count($Arr_rastro) - 1;
              unset($Arr_rastro[$ult_apl]);
              $rastro = implode(",", $Arr_rastro);
?>
  <script type="text/javascript">
     link_atual = new Array (<?php echo $rastro ?>);
     parent.writeFastMenu(link_atual);
  </script>
<?php
          }
          else
          {
?>
  <script type="text/javascript">
     parent.clearFastMenu();
  </script>
<?php
          }
      }
   }
  function html_export_print($nm_arquivo_html, $nmgp_password)
  {
      $Html_password = "";
          $Arq_base  = $this->Ini->root . $this->Ini->path_imag_temp . $nm_arquivo_html;
          $Parm_pass = ($Html_password != "") ? " -p" : "";
          $Zip_name = "sc_prt_" . date("YmdHis") . "_" . rand(0, 1000) . "recherche_fiche_ps_mob.zip";
          $Arq_htm = $this->Ini->path_imag_temp . "/" . $Zip_name;
          $Arq_zip = $this->Ini->root . $Arq_htm;
          $Zip_f     = (FALSE !== strpos($Arq_zip, ' ')) ? " \"" . $Arq_zip . "\"" :  $Arq_zip;
          $Arq_input = (FALSE !== strpos($Arq_base, ' ')) ? " \"" . $Arq_base . "\"" :  $Arq_base;
           if (is_file($Arq_zip)) {
               unlink($Arq_zip);
           }
           $str_zip = "";
           if (FALSE !== strpos(strtolower(php_uname()), 'windows')) 
           {
               chdir($this->Ini->path_third . "/zip/windows");
               $str_zip = "zip.exe " . strtoupper($Parm_pass) . " -j " . $Html_password . " " . $Zip_f . " " . $Arq_input;
           }
           elseif (FALSE !== strpos(strtolower(php_uname()), 'linux')) 
           {
                if (FALSE !== strpos(strtolower(php_uname()), 'i686')) 
                {
                    chdir($this->Ini->path_third . "/zip/linux-i386/bin");
                }
                else
                {
                    chdir($this->Ini->path_third . "/zip/linux-amd64/bin");
                }
               $str_zip = "./7za " . $Parm_pass . $Html_password . " a " . $Zip_f . " " . $Arq_input;
           }
           elseif (FALSE !== strpos(strtolower(php_uname()), 'darwin'))
           {
               chdir($this->Ini->path_third . "/zip/mac/bin");
               $str_zip = "./7za " . $Parm_pass . $Html_password . " a " . $Zip_f . " " . $Arq_input;
           }
           if (!empty($str_zip)) {
               exec($str_zip);
           }
           // ----- ZIP log
           $fp = @fopen(trim(str_replace(array(".zip",'"'), array(".log",""), $Zip_f)), 'w');
           if ($fp)
           {
               @fwrite($fp, $str_zip . "\r\n\r\n");
               @fclose($fp);
           }
           foreach ($this->Ini->Img_export_zip as $cada_img_zip)
           {
               $str_zip      = "";
              $cada_img_zip = '"' . $cada_img_zip . '"';
               if (FALSE !== strpos(strtolower(php_uname()), 'windows')) 
               {
                   $str_zip = "zip.exe " . strtoupper($Parm_pass) . " -j -u " . $Html_password . " " . $Zip_f . " " . $cada_img_zip;
               }
               elseif (FALSE !== strpos(strtolower(php_uname()), 'linux')) 
               {
                   $str_zip = "./7za " . $Parm_pass . $Html_password . " a " . $Zip_f . " " . $cada_img_zip;
               }
               elseif (FALSE !== strpos(strtolower(php_uname()), 'darwin'))
               {
                   $str_zip = "./7za " . $Parm_pass . $Html_password . " a " . $Zip_f . " " . $cada_img_zip;
               }
               if (!empty($str_zip)) {
                   exec($str_zip);
               }
               // ----- ZIP log
               $fp = @fopen(trim(str_replace(array(".zip",'"'), array(".log",""), $Zip_f)), 'a');
               if ($fp)
               {
                   @fwrite($fp, $str_zip . "\r\n\r\n");
                   @fclose($fp);
               }
           }
           if (is_file($Arq_zip)) {
               unlink($Arq_base);
           } 
          $path_doc_md5 = md5($Arq_htm);
          $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob'][$path_doc_md5][0] = $Arq_htm;
          $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob'][$path_doc_md5][1] = $Zip_name;
?>
<HTML<?php echo $_SESSION['scriptcase']['reg_conf']['html_dir'] ?>>
<HEAD>
 <TITLE><?php echo strip_tags("Rechercher une fiche de malade") ?></TITLE>
 <META http-equiv="Content-Type" content="text/html; charset=<?php echo $_SESSION['scriptcase']['charset_html'] ?>" />
<?php

if (isset($_SESSION['scriptcase']['device_mobile']) && $_SESSION['scriptcase']['device_mobile'] && $_SESSION['scriptcase']['display_mobile'])
{
?>
 <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
<?php
}

?>
 <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/css/<?php echo $this->Ini->str_schema_all ?>_export<?php echo $_SESSION['scriptcase']['reg_conf']['css_dir'] ?>.css" /> 
  <link rel="stylesheet" type="text/css" href="../_lib/buttons/<?php echo $this->Ini->Str_btn_form . '/' . $this->Ini->Str_btn_form ?>.css" /> 
  <link rel="stylesheet" type="text/css" href="<?php echo $this->Ini->path_prod; ?>/third/font-awesome/css/all.min.css" /> 
  <link rel="shortcut icon" href="../_lib/img/sys__NM__img__NM__emergency_2785811.png">
</HEAD>
<BODY class="scExportPage">
<table style="border-collapse: collapse; border-width: 0; height: 100%; width: 100%"><tr><td style="padding: 0; text-align: center; vertical-align: top">
 <table class="scExportTable" align="center">
  <tr>
   <td class="scExportTitle" style="height: 25px">PRINT</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", "", "", "", "absmiddle", "", "0", $this->Ini->path_botoes, "", "", "", "", "");?>

   <?php echo nmButtonOutput($this->arr_buttons, "bdownload", "document.Fdown.submit()", "document.Fdown.submit()", "idBtnDown", "", "", "", "absmiddle", "", "0", $this->Ini->path_botoes, "", "", "", "", "");?>

   <?php echo nmButtonOutput($this->arr_buttons, "bvoltar", "document.F0.submit()", "document.F0.submit()", "idBtnBack", "", "", "", "absmiddle", "", "0", $this->Ini->path_botoes, "", "", "", "", "");?>

    </td></tr></table>
   </td>
  </tr>
 </table>
</td></tr></table>
<form name="Fview" method="get" action="<?php echo  $this->form_encode_input($Arq_htm) ?>" target="_self" style="display: none"> 
</form>
<form name="Fdown" method="get" action="recherche_fiche_ps_mob_download.php" target="_self" style="display: none"> 
<input type="hidden" name="script_case_init" value="<?php echo $this->form_encode_input($this->Ini->sc_page); ?>"> 
<input type="hidden" name="nm_tit_doc" value="recherche_fiche_ps_mob"> 
<input type="hidden" name="nm_name_doc" value="<?php echo $path_doc_md5 ?>"> 
</form>
<form name="F0" method=post action="recherche_fiche_ps_mob.php" target="_self" style="display: none"> 
<input type="hidden" name="script_case_init" value="<?php echo $this->form_encode_input($this->Ini->sc_page); ?>"> 
<input type="hidden" name="nmgp_opcao" value="<?php echo $this->nmgp_opcao ?>"> 
</form> 
         </BODY>
         </HTML>
<?php
          exit;
  }
//
//--------------------------------------------------------------------------------------
   function NM_has_trans()
   {
       return !in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_access);
   }
//
//--------------------------------------------------------------------------------------
   function NM_commit_db()
   {
       if ($this->Ini->sc_tem_trans_banco && !$this->Embutida_proc)
       { 
           $this->Db->CommitTrans(); 
           $this->Ini->sc_tem_trans_banco = false;
       } 
   }
//
//--------------------------------------------------------------------------------------
   function NM_rollback_db()
   {
       if ($this->Ini->sc_tem_trans_banco && !$this->Embutida_proc)
       { 
           $this->Db->RollbackTrans(); 
           $this->Ini->sc_tem_trans_banco = false;
       } 
   }
//
//--------------------------------------------------------------------------------------
   function NM_gera_log_insert($orig="Scriptcase", $evento="", $texto="")
   {
       $delim  = "'";
       $delim1 = "'";
       if (in_array(strtolower($_SESSION['scriptcase']['glo_tpbanco']), $this->Ini->nm_bases_access))
       { 
           $delim  = "#";
           $delim1 = "#";
       } 
       if (isset($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['SC_sep_date']) && !empty($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['SC_sep_date']))
       {
           $delim  = $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['SC_sep_date'];
           $delim1 = $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['SC_sep_date1'];
       }
       $dt  = $delim . date('Y-m-d H:i:s') . $delim1;
       $usr = isset($_SESSION['usr_login']) ? $_SESSION['usr_login'] : "";
       if (strtolower($_SESSION['scriptcase']['glo_tpbanco']) == 'pdo_sqlsrv' || strtolower($_SESSION['scriptcase']['glo_tpbanco']) == 'pdo_dblib')
       { 
           $dt  = $delim . date('Ymd H:i:s') . $delim1;
       } 
       if (in_array(strtolower($_SESSION['scriptcase']['glo_tpbanco']), $this->Ini->nm_bases_access))
       { 
           $dt  = $delim . date('Y-m-d H:i:s') . $delim1;
       } 
       if (in_array(strtolower($_SESSION['scriptcase']['glo_tpbanco']), $this->Ini->nm_bases_informix))
       { 
           $dt  = "EXTEND(" . $dt . ", YEAR TO FRACTION)";
       } 
       if (in_array(strtolower($_SESSION['scriptcase']['glo_tpbanco']), $this->Ini->nm_bases_access))
       { 
           $comando = "INSERT INTO sc_log (inserted_date, username, application, creator, ip_user, `action`, description) VALUES ($dt, " . $this->Db->qstr($usr) . ", 'recherche_fiche_ps_mob', '$orig', '" . $_SERVER['REMOTE_ADDR'] . "', '$evento', " . $this->Db->qstr($texto) . ")"; 
       } 
       elseif (in_array(strtolower($_SESSION['scriptcase']['glo_tpbanco']), $this->Ini->nm_bases_sqlite))
       { 
           $comando = "INSERT INTO sc_log (id, inserted_date, username, application, creator, ip_user, action, description) VALUES (NULL, $dt, " . $this->Db->qstr($usr) . ", 'recherche_fiche_ps_mob', '$orig', '" . $_SERVER['REMOTE_ADDR'] . "', '$evento', " . $this->Db->qstr($texto) . ")"; 
       } 
       else
       { 
           $comando = "INSERT INTO sc_log (inserted_date, username, application, creator, ip_user, action, description) VALUES ($dt, " . $this->Db->qstr($usr) . ", 'recherche_fiche_ps_mob', '$orig', '" . $_SERVER['REMOTE_ADDR'] . "', '$evento', " . $this->Db->qstr($texto) . ")"; 
       } 
       $_SESSION['scriptcase']['sc_sql_ult_comando'] = $comando; 
       $rlog = $this->Db->Execute($comando); 
       if ($rlog === false)  
       { 
           $this->Erro->mensagem (__FILE__, __LINE__, "banco", $this->Ini->Nm_lang['lang_errm_inst'], $this->Db->ErrorMsg()); 
           if ($this->NM_ajax_flag)
           {
               recherche_fiche_ps_mob_pack_ajax_response();
               exit; 
           }
       }
   }
//
//--------------------------------------------------------------------------------------
   function NM_close_db()
   {
       if ($this->Db && !$this->Embutida_proc)
       { 
           $this->Db->Close(); 
       } 
   }
   function sc_btn_fiche_patient() 
   {
        global $nm_url_saida, $teste_validade, 
            $glo_senha_protect, $bok, $nm_apl_dependente, $nm_form_submit, $nm_opc_form_php, $nm_call_php, $nm_opc_lookup, $nmgp_redir;
 
     ob_start();
?>
<!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>
    <META http-equiv="Content-Type" content="text/html; charset=<?php echo $_SESSION['scriptcase']['charset_html'] ?>" />
<?php

      if (isset($_SESSION['scriptcase']['device_mobile']) && $_SESSION['scriptcase']['device_mobile'] && $_SESSION['scriptcase']['display_mobile'])
      {
?>
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
<?php
      }

?>
        <link rel="shortcut icon" href="../_lib/img/sys__NM__img__NM__emergency_2785811.png">
    <SCRIPT type="text/javascript">
      var sc_pathToTB = '<?php echo $this->Ini->path_prod ?>/third/jquery_plugin/thickbox/';
      var sc_tbLangClose = "<?php echo html_entity_decode($this->Ini->Nm_lang["lang_tb_close"], ENT_COMPAT, $_SESSION["scriptcase"]["charset"]) ?>";
      var sc_tbLangEsc = "<?php echo html_entity_decode($this->Ini->Nm_lang["lang_tb_esc"], ENT_COMPAT, $_SESSION["scriptcase"]["charset"]) ?>";
      var sc_userSweetAlertDisplayed = false;
    </SCRIPT>
    <SCRIPT type="text/javascript" src="<?php echo $this->Ini->url_third; ?>jquery/js/jquery.js"></SCRIPT>
    <SCRIPT type="text/javascript" src="<?php echo $this->Ini->path_prod; ?>/third/jquery_plugin/malsup-blockui/jquery.blockUI.js"></SCRIPT>
    <SCRIPT type="text/javascript" src="<?php echo $this->Ini->path_prod; ?>/third/jquery_plugin/thickbox/thickbox-compressed.js"></SCRIPT>
<?php
include_once("recherche_fiche_ps_mob_sajax_js.php");
?>
 <link rel="stylesheet" type="text/css" href="<?php echo $this->Ini->path_link ?>_lib/css/<?php echo $this->Ini->str_schema_all ?>_sweetalert.css" />
 <SCRIPT type="text/javascript" src="<?php echo $this->Ini->path_prod; ?>/third/sweetalert/sweetalert2.all.min.js"></SCRIPT>
 <SCRIPT type="text/javascript" src="<?php echo $this->Ini->path_prod; ?>/third/sweetalert/polyfill.min.js"></SCRIPT>
 <script type="text/javascript" src="../_lib/lib/js/frameControl.js"></script>
    <link rel="stylesheet" href="<?php echo $this->Ini->path_prod ?>/third/jquery_plugin/thickbox/thickbox.css" type="text/css" media="screen" />
    <link rel="stylesheet" type="text/css" href="../_lib/css/<?php echo $this->Ini->str_schema_all ?>_form.css" />
    <link rel="stylesheet" type="text/css" href="../_lib/css/<?php echo $this->Ini->str_schema_all ?>_form<?php echo $_SESSION['scriptcase']['reg_conf']['css_dir'] ?>.css" />
  <?php 
  if(isset($this->Ini->str_google_fonts) && !empty($this->Ini->str_google_fonts)) 
  { 
  ?> 
  <link href="<?php echo $this->Ini->str_google_fonts ?>" rel="stylesheet" /> 
  <?php 
  } 
  ?> 
 </head>
  <body class="scFormPage">
      <table class="scFormTabela" align="center"><tr><td>
<?php
      $varloc_btn_php = array();
      $nmgp_opcao_saida_php = "igual";
      $nmgp_opc_ant_saida_php = "";
      if ($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['opc_ant'] == "novo" || $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['opc_ant'] == "incluir")
      {
          $nmgp_opc_ant_saida_php = "novo";
          $nmgp_opcao_saida_php   = "recarga";
      }
      else
      {
          if (!isset($this->code_fp) && isset($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['dados_form']['code_fp']))
          {
              $varloc_btn_php['code_fp'] = $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['dados_form']['code_fp'];
          }
          if (!isset($this->resultat_array) && isset($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['dados_form']['resultat_array']))
          {
              $varloc_btn_php['resultat_array'] = $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['dados_form']['resultat_array'];
          }
          if (!isset($this->resultat_array) && isset($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['dados_form']['resultat_array']))
          {
              $varloc_btn_php['resultat_array'] = $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['dados_form']['resultat_array'];
          }
          if (!isset($this->resultat_array) && isset($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['dados_form']['resultat_array']))
          {
              $varloc_btn_php['resultat_array'] = $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['dados_form']['resultat_array'];
          }
      }
      $nm_f_saida = "recherche_fiche_ps_mob.php";
      foreach ($varloc_btn_php as $cmp => $val_cmp)
      {
          $this->$cmp = $val_cmp;
      }
      $_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  $c = $this->code_fp ;

$string_link = '#';



$_date = $_SESSION['recherche_fiche_ps_mob']['resultat_array']['sys']['date_declaration'];

$c_label = $c . ' - ' . date("d/m/Y H:i", strtotime($_date)); 




$_id =  $_SESSION['recherche_fiche_ps_mob']['resultat_array']['sys']['id'];


$_statut_maladie = $_SESSION['recherche_fiche_ps_mob']['resultat_array']['sys']['statut_maladie'];


if ($_statut_maladie=='S'){
	
	$_statut_maladie = 'Cas suspect';
	
}
elseif ($_statut_maladie=='C'){
	
	$_statut_maladie = 'Cas confirmé';
	
}
elseif ($_statut_maladie=='I'){
	
	$_statut_maladie = 'Cas infirmé';
	
}





 if (!isset($this->Campos_Mens_erro) || empty($this->Campos_Mens_erro))
 {
$this->nmgp_redireciona_form($this->Ini->path_link . "" . SC_dir_app_name('form_fiche_pro_sante_search_ro') . "/form_fiche_pro_sante_search_ro.php", $this->nm_location, "var_code_fiche?#?" . NM_encode_input($c) . "?@?" . "id_fiche_ps?#?" . NM_encode_input($_id) . "?@?" . "var_code_fp_label?#?" . NM_encode_input($c_label) . "?@?" . "var_maladie_label?#?" . NM_encode_input($_statut_maladie) . "?@?","_self", '', 440, 630);
 };
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off'; 
    echo ob_get_clean();
?>
      </td></tr><tr><td align="center">
      <form name="FPHP" method="post" 
                        action="<?php echo $nm_f_saida ?>" 
                        target="_self">
      <input type=hidden name="nmgp_opcao" value=""/>
      <input type=hidden name="script_case_init" value="<?php  echo $this->form_encode_input($this->Ini->sc_page); ?>"/>
      <input type=hidden name="nin" value="<?php echo $this->form_encode_input($this->nin) ?>"/>
      <input type=hidden name="nmgp_opcao" value="<?php echo $this->form_encode_input($nmgp_opcao_saida_php); ?>"/>
      <input type=hidden name="nmgp_opc_ant" value="<?php echo $this->form_encode_input($nmgp_opc_ant_saida_php); ?>"/>
      <input type=submit name="nmgp_bok" value="<?php echo $this->Ini->Nm_lang['lang_btns_cfrm'] ?>"/>
      </form>
      </td></tr></table>
      </body>
      </html>
<?php
       if (isset($this->redir_modal) && !empty($this->redir_modal))
       {
           echo "<script type=\"text/javascript\">" . $this->redir_modal . "</script>";
           $this->redir_modal = "";
       }
   }
//
//--------------------------------------------------------------------------------------
   function Formata_Erros($Campos_Crit, $Campos_Falta, $Campos_Erros, $mode = 3) 
   {
       switch ($mode)
       {
           case 1:
               $campos_erro = array();
               if (!empty($Campos_Crit))
               {
                   $campos_erro[] = $Campos_Crit;
               }
               if (!empty($Campos_Falta))
               {
                   $campos_erro[] = $this->Formata_Campos_Falta($Campos_Falta);
               }
               if (!empty($this->Campos_Mens_erro))
               {
                   $campos_erro[] = $this->Campos_Mens_erro;
               }
               return implode('<br />', $campos_erro);
               break;

           case 2:
               $campos_erro = array();
               if (!empty($Campos_Crit))
               {
                   $campos_erro[] = $Campos_Crit;
               }
               if (!empty($Campos_Falta))
               {
                   $campos_erro[] = $this->Formata_Campos_Falta($Campos_Falta, true);
               }
               if (!empty($this->Campos_Mens_erro))
               {
                   $campos_erro[] = $this->Campos_Mens_erro;
               }
               return implode('<br />', $campos_erro);
               break;

           case 3:
               $campos_erro = array();
               if (!empty($Campos_Erros))
               {
                   $campos_erro[] = $this->Formata_Campos_Erros($Campos_Erros);
               }
               if (!empty($this->Campos_Mens_erro))
               {
                   $campos_mens_erro = str_replace(array('<br />', '<br>', '<BR />'), array('<BR>', '<BR>', '<BR>'), $this->Campos_Mens_erro);
                   $campos_mens_erro = explode('<BR>', $campos_mens_erro);
                   foreach ($campos_mens_erro as $msg_erro)
                   {
                       if ('' != $msg_erro && !in_array($msg_erro, $campos_erro))
                       {
                           $campos_erro[] = $msg_erro;
                       }
                   }
               }
               return implode('<br />', $campos_erro);
               break;

           case 4:
               $campos_erro = array();
               if (!empty($Campos_Erros))
               {
                   $campos_erro[] = $this->Formata_Campos_Erros_SweetAlert($Campos_Erros);
               }
               if (!empty($this->Campos_Mens_erro))
               {
                   $campos_mens_erro = str_replace(array('<br />', '<br>', '<BR />'), array('<BR>', '<BR>', '<BR>'), $this->Campos_Mens_erro);
                   $campos_mens_erro = explode('<BR>', $campos_mens_erro);
                   foreach ($campos_mens_erro as $msg_erro)
                   {
                       if ('' != $msg_erro && !in_array($msg_erro, $campos_erro))
                       {
                           $campos_erro[] = $msg_erro;
                       }
                   }
               }
               return implode('<br />', $campos_erro);
               break;
       }
   }

   function Formata_Campos_Falta($Campos_Falta, $table = false) 
   {
       $Campos_Falta = array_unique($Campos_Falta);

       if (!$table)
       {
           return $this->Ini->Nm_lang['lang_errm_reqd'] . ' ' . implode('; ', $Campos_Falta);
       }

       $aCols  = array();
       $iTotal = sizeof($Campos_Falta);
       $iCols  = 6 > $iTotal ? 1 : (11 > $iTotal ? 2 : (16 > $iTotal ? 3 : 4));
       $iItems = ceil($iTotal / $iCols);
       $iNowC  = 0;
       $iNowI  = 0;

       foreach ($Campos_Falta as $campo)
       {
           $aCols[$iNowC][] = $campo;
           if ($iItems == ++$iNowI)
           {
               $iNowC++;
               $iNowI = 0;
           }
       }

       $sError  = '<table style="border-collapse: collapse; border-width: 0px">';
       $sError .= '<tr>';
       $sError .= '<td class="scFormErrorMessageFont" style="padding: 0; vertical-align: top; white-space: nowrap">' . $this->Ini->Nm_lang['lang_errm_reqd'] . '</td>';
       foreach ($aCols as $aCol)
       {
           $sError .= '<td class="scFormErrorMessageFont" style="padding: 0 6px; vertical-align: top; white-space: nowrap">' . implode('<br />', $aCol) . '</td>';
       }
       $sError .= '</tr>';
       $sError .= '</table>';

       return $sError;
   }

   function Formata_Campos_Crit($Campos_Crit, $table = false) 
   {
       $Campos_Crit = array_unique($Campos_Crit);

       if (!$table)
       {
           return $this->Ini->Nm_lang['lang_errm_flds'] . ' ' . implode('; ', $Campos_Crit);
       }

       $aCols  = array();
       $iTotal = sizeof($Campos_Crit);
       $iCols  = 6 > $iTotal ? 1 : (11 > $iTotal ? 2 : (16 > $iTotal ? 3 : 4));
       $iItems = ceil($iTotal / $iCols);
       $iNowC  = 0;
       $iNowI  = 0;

       foreach ($Campos_Crit as $campo)
       {
           $aCols[$iNowC][] = $campo;
           if ($iItems == ++$iNowI)
           {
               $iNowC++;
               $iNowI = 0;
           }
       }

       $sError  = '<table style="border-collapse: collapse; border-width: 0px">';
       $sError .= '<tr>';
       $sError .= '<td class="scFormErrorMessageFont" style="padding: 0; vertical-align: top; white-space: nowrap">' . $this->Ini->Nm_lang['lang_errm_flds'] . '</td>';
       foreach ($aCols as $aCol)
       {
           $sError .= '<td class="scFormErrorMessageFont" style="padding: 0 6px; vertical-align: top; white-space: nowrap">' . implode('<br />', $aCol) . '</td>';
       }
       $sError .= '</tr>';
       $sError .= '</table>';

       return $sError;
   }

   function Formata_Campos_Erros($Campos_Erros) 
   {
       $sError  = '<table style="border-collapse: collapse; border-width: 0px">';

       foreach ($Campos_Erros as $campo => $erros)
       {
           $sError .= '<tr>';
           $sError .= '<td class="scFormErrorMessageFont" style="padding: 0; vertical-align: top; white-space: nowrap">' . $this->Recupera_Nome_Campo($campo) . ':</td>';
           $sError .= '<td class="scFormErrorMessageFont" style="padding: 0 6px; vertical-align: top; white-space: nowrap">' . implode('<br />', array_unique($erros)) . '</td>';
           $sError .= '</tr>';
       }

       $sError .= '</table>';

       return $sError;
   }

   function Formata_Campos_Erros_SweetAlert($Campos_Erros) 
   {
       $sError  = '';

       foreach ($Campos_Erros as $campo => $erros)
       {
           $sError .= $this->Recupera_Nome_Campo($campo) . ': ' . implode('<br />', array_unique($erros)) . '<br />';
       }

       return $sError;
   }

   function Recupera_Nome_Campo($campo) 
   {
       switch($campo)
       {
           case 'info':
               return "info";
               break;
           case 'code_fp':
               return "Code Fiche";
               break;
           case 'nin':
               return "NIN";
               break;
           case 'resultat':
               return "resultat";
               break;
       }

       return $campo;
   }

   function dateDefaultFormat()
   {
       if (isset($this->Ini->Nm_conf_reg[$this->Ini->str_conf_reg]['data_format']))
       {
           $sDate = str_replace('yyyy', 'Y', $this->Ini->Nm_conf_reg[$this->Ini->str_conf_reg]['data_format']);
           $sDate = str_replace('mm',   'm', $sDate);
           $sDate = str_replace('dd',   'd', $sDate);
           return substr(chunk_split($sDate, 1, $this->Ini->Nm_conf_reg[$this->Ini->str_conf_reg]['data_sep']), 0, -1);
       }
       elseif ('en_us' == $this->Ini->str_lang)
       {
           return 'm/d/Y';
       }
       else
       {
           return 'd/m/Y';
       }
   } // dateDefaultFormat

//
//--------------------------------------------------------------------------------------
   function Valida_campos(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros, $filtro = '') 
   {
     global $nm_browser, $teste_validade;
     if (is_array($filtro) && empty($filtro)) {
         $filtro = '';
     }
//---------------------------------------------------------
     $this->scFormFocusErrorName = '';
     $this->sc_force_zero = array();

     if (!is_array($filtro) && '' == $filtro && isset($this->nm_form_submit) && '1' == $this->nm_form_submit && $this->scCsrfGetToken() != $this->csrf_token)
     {
          $this->Campos_Mens_erro .= (empty($this->Campos_Mens_erro)) ? "" : "<br />";
          $this->Campos_Mens_erro .= "CSRF: " . $this->Ini->Nm_lang['lang_errm_ajax_csrf'];
          if ($this->NM_ajax_flag)
          {
              if (!isset($this->NM_ajax_info['errList']['geral_recherche_fiche_ps_mob']) || !is_array($this->NM_ajax_info['errList']['geral_recherche_fiche_ps_mob']))
              {
                  $this->NM_ajax_info['errList']['geral_recherche_fiche_ps_mob'] = array();
              }
              $this->NM_ajax_info['errList']['geral_recherche_fiche_ps_mob'][] = "CSRF: " . $this->Ini->Nm_lang['lang_errm_ajax_csrf'];
          }
     }
      if ((!is_array($filtro) && ('' == $filtro || 'code_fp' == $filtro)) || (is_array($filtro) && in_array('code_fp', $filtro)))
        $this->ValidateField_code_fp($Campos_Crit, $Campos_Falta, $Campos_Erros);
      if ((!isset($this->scFormFocusErrorName) || '' == $this->scFormFocusErrorName) && ( !empty($Campos_Crit) || !empty($Campos_Falta) ))
          $this->scFormFocusErrorName = "code_fp";

      if ((!is_array($filtro) && ('' == $filtro || 'nin' == $filtro)) || (is_array($filtro) && in_array('nin', $filtro)))
        $this->ValidateField_nin($Campos_Crit, $Campos_Falta, $Campos_Erros);
      if ((!isset($this->scFormFocusErrorName) || '' == $this->scFormFocusErrorName) && ( !empty($Campos_Crit) || !empty($Campos_Falta) ))
          $this->scFormFocusErrorName = "nin";


      if (empty($Campos_Crit) && empty($Campos_Falta))
      {
      if (!isset($this->NM_ajax_flag) || 'validate_' != substr($this->NM_ajax_opcao, 0, 9))
      {
      $_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
if (isset($this->NM_ajax_flag) && $this->NM_ajax_flag)
{
    $original_code_fp = $this->code_fp;
    $original_nin = $this->nin;
}
  if (empty($this->code_fp  && empty($this->nin )) ){
	

	$error_message = 'Vous devez renseigner le code de la fiche à rechecher, ou le NIN du malade'; 

	
 if (!isset($this->Campos_Mens_erro)){$this->Campos_Mens_erro = "";}
 if (!empty($this->Campos_Mens_erro)){$this->Campos_Mens_erro .= "<br>";}$this->Campos_Mens_erro .= $error_message;
 if ('submit_form' == $this->NM_ajax_opcao || 'event_' == substr($this->NM_ajax_opcao, 0, 6) || (isset($this->wizard_action) && 'change_step' == $this->wizard_action))
 {
  if (isset($this->wizard_action) && 'change_step' == $this->wizard_action) {
   $sErrorIndex = 'geral_recherche_fiche_ps_mob';
  } elseif ('submit_form' == $this->NM_ajax_opcao) {
   $sErrorIndex = 'geral_recherche_fiche_ps_mob';
  } else {
   $sErrorIndex = substr(substr($this->NM_ajax_opcao, 0, strrpos($this->NM_ajax_opcao, '_')), 6);
  }
  $this->NM_ajax_info['errList'][$sErrorIndex][] = $error_message;
 }
;
	if (isset($this->Campos_Mens_erro) && !empty($this->Campos_Mens_erro))
{
    $_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
    return;
}
}

$_nin = $this->nin ;

if (strlen($_nin)!=0 && strlen($_nin)!=18){
	
	$error_message = "Le NIN doit être composé de 18 chiffres"; 

	
 if (!isset($this->Campos_Mens_erro)){$this->Campos_Mens_erro = "";}
 if (!empty($this->Campos_Mens_erro)){$this->Campos_Mens_erro .= "<br>";}$this->Campos_Mens_erro .= $error_message;
 if ('submit_form' == $this->NM_ajax_opcao || 'event_' == substr($this->NM_ajax_opcao, 0, 6) || (isset($this->wizard_action) && 'change_step' == $this->wizard_action))
 {
  if (isset($this->wizard_action) && 'change_step' == $this->wizard_action) {
   $sErrorIndex = 'geral_recherche_fiche_ps_mob';
  } elseif ('submit_form' == $this->NM_ajax_opcao) {
   $sErrorIndex = 'geral_recherche_fiche_ps_mob';
  } else {
   $sErrorIndex = substr(substr($this->NM_ajax_opcao, 0, strrpos($this->NM_ajax_opcao, '_')), 6);
  }
  $this->NM_ajax_info['errList'][$sErrorIndex][] = $error_message;
 }
;
	if (isset($this->Campos_Mens_erro) && !empty($this->Campos_Mens_erro))
{
    $_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
    return;
}
}
if (isset($this->NM_ajax_flag) && $this->NM_ajax_flag)
{
    if (($original_code_fp != $this->code_fp || (isset($bFlagRead_code_fp) && $bFlagRead_code_fp)))
    {
        $this->ajax_return_values_code_fp(true);
    }
    if (($original_nin != $this->nin || (isset($bFlagRead_nin) && $bFlagRead_nin)))
    {
        $this->ajax_return_values_nin(true);
    }
}
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off'; 
      }
      }
      if (!empty($Campos_Crit) || !empty($Campos_Falta) || !empty($this->Campos_Mens_erro))
      {
          if (!empty($this->sc_force_zero))
          {
              foreach ($this->sc_force_zero as $i_force_zero => $sc_force_zero_field)
              {
                  eval('$this->' . $sc_force_zero_field . ' = "";');
                  unset($this->sc_force_zero[$i_force_zero]);
              }
          }
      }

      if (empty($Campos_Crit) && empty($Campos_Falta) && empty($this->Campos_Mens_erro))
      {
          if (!isset($this->NM_ajax_flag) || 'validate_' != substr($this->NM_ajax_opcao, 0, 9))
          {
              $_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
if (isset($this->NM_ajax_flag) && $this->NM_ajax_flag)
{
    $original_code_fp = $this->code_fp;
    $original_nin = $this->nin;
    $original_resultat = $this->resultat;
}
  $_SESSION['recherche_fiche_ps_mob']['code_p'] = false;

if (!empty($this->code_fp )){
		
	
	$search = $this->search_by_code($this->code_fp );
	$this->resultat  = $search['message'];
	
	$_SESSION['recherche_fiche_ps_mob']['code_p'] = $search['exist'];
	
	
}
elseif (!empty($this->nin )){
	
	$search = $this->search_by_nin($this->nin );
	$this->resultat  = $search['message'];
	
	$_SESSION['recherche_fiche_ps_mob']['code_p'] = $search['exist'];
	
	
}




if (isset($search['exist']) && $search['exist']){
	
	$_SESSION['recherche_fiche_ps_mob']['code_v'] = $search['code'];
	
}
else{
	
	$_SESSION['recherche_fiche_ps_mob']['code_v'] = '';
}
if (isset($this->NM_ajax_flag) && $this->NM_ajax_flag)
{
    if (($original_code_fp != $this->code_fp || (isset($bFlagRead_code_fp) && $bFlagRead_code_fp)))
    {
        $this->ajax_return_values_code_fp(true);
    }
    if (($original_nin != $this->nin || (isset($bFlagRead_nin) && $bFlagRead_nin)))
    {
        $this->ajax_return_values_nin(true);
    }
    if (($original_resultat != $this->resultat || (isset($bFlagRead_resultat) && $bFlagRead_resultat)))
    {
        $this->ajax_return_values_resultat(true);
    }
}
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off'; 
          }
      }
   }

    function ValidateField_code_fp(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros)
    {
        global $teste_validade;
        $hasError = false;
      if (isset($this->Field_no_validate['code_fp'])) {
          return;
      }
      if ($this->nmgp_opcao != "excluir") 
      { 
          if (NM_utf8_strlen($this->code_fp) > 20) 
          { 
              $hasError = true;
              $Campos_Crit .= "Code Fiche " . $this->Ini->Nm_lang['lang_errm_mxch'] . " 20 " . $this->Ini->Nm_lang['lang_errm_nchr']; 
              if (!isset($Campos_Erros['code_fp']))
              {
                  $Campos_Erros['code_fp'] = array();
              }
              $Campos_Erros['code_fp'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 20 " . $this->Ini->Nm_lang['lang_errm_nchr'];
              if (!isset($this->NM_ajax_info['errList']['code_fp']) || !is_array($this->NM_ajax_info['errList']['code_fp']))
              {
                  $this->NM_ajax_info['errList']['code_fp'] = array();
              }
              $this->NM_ajax_info['errList']['code_fp'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 20 " . $this->Ini->Nm_lang['lang_errm_nchr'];
          } 
      } 
      $Teste_trab = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
      if ($_SESSION['scriptcase']['charset'] != "UTF-8")
      {
          $Teste_trab = NM_conv_charset($Teste_trab, $_SESSION['scriptcase']['charset'], "UTF-8");
      }
;
      $Teste_trab = $Teste_trab . chr(10) . chr(13) ; 
      $Teste_compara = $this->code_fp ; 
      if ($this->nmgp_opcao != "excluir") 
      { 
          $Teste_critica = 0 ; 
          for ($x = 0; $x < mb_strlen($this->code_fp, $_SESSION['scriptcase']['charset']); $x++) 
          { 
               for ($y = 0; $y < mb_strlen($Teste_trab, $_SESSION['scriptcase']['charset']); $y++) 
               { 
                    if (sc_substr($Teste_compara, $x, 1) == sc_substr($Teste_trab, $y, 1) ) 
                    { 
                        break ; 
                    } 
               } 
               if (sc_substr($Teste_compara, $x, 1) != sc_substr($Teste_trab, $y, 1) )  
               { 
                  $Teste_critica = 1 ; 
               } 
          } 
          if ($Teste_critica == 1) 
          { 
              $hasError = true;
              $Campos_Crit .= "Code Fiche " . $this->Ini->Nm_lang['lang_errm_ivch']; 
              if (!isset($Campos_Erros['code_fp']))
              {
                  $Campos_Erros['code_fp'] = array();
              }
              $Campos_Erros['code_fp'][] = $this->Ini->Nm_lang['lang_errm_ivch'];
              if (!isset($this->NM_ajax_info['errList']['code_fp']) || !is_array($this->NM_ajax_info['errList']['code_fp']))
              {
                  $this->NM_ajax_info['errList']['code_fp'] = array();
              }
              $this->NM_ajax_info['errList']['code_fp'][] = $this->Ini->Nm_lang['lang_errm_ivch'];
          } 
      } 
        if ($hasError) {
            global $sc_seq_vert;
            $fieldName = 'code_fp';
            if (isset($sc_seq_vert) && '' != $sc_seq_vert) {
                $fieldName .= $sc_seq_vert;
            }
            $this->NM_ajax_info['fieldsWithErrors'][] = $fieldName;
        }
    } // ValidateField_code_fp

    function ValidateField_nin(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros)
    {
        global $teste_validade;
        $hasError = false;
      if (isset($this->Field_no_validate['nin'])) {
          return;
      }
      if ($this->nmgp_opcao != "excluir") 
      { 
          if (NM_utf8_strlen($this->nin) > 18) 
          { 
              $hasError = true;
              $Campos_Crit .= "NIN " . $this->Ini->Nm_lang['lang_errm_mxch'] . " 18 " . $this->Ini->Nm_lang['lang_errm_nchr']; 
              if (!isset($Campos_Erros['nin']))
              {
                  $Campos_Erros['nin'] = array();
              }
              $Campos_Erros['nin'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 18 " . $this->Ini->Nm_lang['lang_errm_nchr'];
              if (!isset($this->NM_ajax_info['errList']['nin']) || !is_array($this->NM_ajax_info['errList']['nin']))
              {
                  $this->NM_ajax_info['errList']['nin'] = array();
              }
              $this->NM_ajax_info['errList']['nin'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 18 " . $this->Ini->Nm_lang['lang_errm_nchr'];
          } 
      } 
      $Teste_trab = "01234567890123456789";
      if ($_SESSION['scriptcase']['charset'] != "UTF-8")
      {
          $Teste_trab = NM_conv_charset($Teste_trab, $_SESSION['scriptcase']['charset'], "UTF-8");
      }
;
      $Teste_trab = $Teste_trab . chr(10) . chr(13) ; 
      $Teste_compara = $this->nin ; 
      if ($this->nmgp_opcao != "excluir") 
      { 
          $Teste_critica = 0 ; 
          for ($x = 0; $x < mb_strlen($this->nin, $_SESSION['scriptcase']['charset']); $x++) 
          { 
               for ($y = 0; $y < mb_strlen($Teste_trab, $_SESSION['scriptcase']['charset']); $y++) 
               { 
                    if (sc_substr($Teste_compara, $x, 1) == sc_substr($Teste_trab, $y, 1) ) 
                    { 
                        break ; 
                    } 
               } 
               if (sc_substr($Teste_compara, $x, 1) != sc_substr($Teste_trab, $y, 1) )  
               { 
                  $Teste_critica = 1 ; 
               } 
          } 
          if ($Teste_critica == 1) 
          { 
              $hasError = true;
              $Campos_Crit .= "NIN " . $this->Ini->Nm_lang['lang_errm_ivch']; 
              if (!isset($Campos_Erros['nin']))
              {
                  $Campos_Erros['nin'] = array();
              }
              $Campos_Erros['nin'][] = $this->Ini->Nm_lang['lang_errm_ivch'];
              if (!isset($this->NM_ajax_info['errList']['nin']) || !is_array($this->NM_ajax_info['errList']['nin']))
              {
                  $this->NM_ajax_info['errList']['nin'] = array();
              }
              $this->NM_ajax_info['errList']['nin'][] = $this->Ini->Nm_lang['lang_errm_ivch'];
          } 
      } 
        if ($hasError) {
            global $sc_seq_vert;
            $fieldName = 'nin';
            if (isset($sc_seq_vert) && '' != $sc_seq_vert) {
                $fieldName .= $sc_seq_vert;
            }
            $this->NM_ajax_info['fieldsWithErrors'][] = $fieldName;
        }
    } // ValidateField_nin

    function removeDuplicateDttmError($aErrDate, &$aErrTime)
    {
        if (empty($aErrDate) || empty($aErrTime))
        {
            return;
        }

        foreach ($aErrDate as $sErrDate)
        {
            foreach ($aErrTime as $iErrTime => $sErrTime)
            {
                if ($sErrDate == $sErrTime)
                {
                    unset($aErrTime[$iErrTime]);
                }
            }
        }
    } // removeDuplicateDttmError

   function nm_guardar_campos()
   {
    global
           $sc_seq_vert;
    $this->nmgp_dados_form['info'] = $this->info;
    $this->nmgp_dados_form['code_fp'] = $this->code_fp;
    $this->nmgp_dados_form['nin'] = $this->nin;
    $this->nmgp_dados_form['resultat'] = $this->resultat;
    $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['dados_form'] = $this->nmgp_dados_form;
   }
   function nm_tira_formatacao()
   {
      global $nm_form_submit;
         $this->Before_unformat = array();
         $this->formatado = false;
   }
   function sc_add_currency(&$value, $symbol, $pos)
   {
       if ('' == $value)
       {
           return;
       }
       $value = (1 == $pos || 3 == $pos) ? $symbol . ' ' . $value : $value . ' ' . $symbol;
   }
   function sc_remove_currency(&$value, $symbol_dec, $symbol_tho, $symbol_mon)
   {
       $value = preg_replace('~&#x0*([0-9a-f]+);~i', '', $value);
       $sNew  = str_replace($symbol_mon, '', $value);
       if ($sNew != $value)
       {
           $value = str_replace(' ', '', $sNew);
           return;
       }
       $aTest = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', $symbol_dec, $symbol_tho);
       $sNew  = '';
       for ($i = 0; $i < strlen($value); $i++)
       {
           if ($this->sc_test_currency_char($value[$i], $aTest))
           {
               $sNew .= $value[$i];
           }
       }
       $value = $sNew;
   }
   function sc_test_currency_char($char, $test)
   {
       $found = false;
       foreach ($test as $test_char)
       {
           if ($char === $test_char)
           {
               $found = true;
           }
       }
       return $found;
   }
   function nm_clear_val($Nome_Campo)
   {
   }
   function nm_formatar_campos($format_fields = array())
   {
      global $nm_form_submit;
     if (isset($this->formatado) && $this->formatado)
     {
         return;
     }
     $this->formatado = true;
   }
   function nm_gera_mask(&$nm_campo, $nm_mask)
   { 
      $trab_campo = $nm_campo;
      $trab_mask  = $nm_mask;
      $tam_campo  = strlen($nm_campo);
      $trab_saida = "";

      if (false !== strpos($nm_mask, '9') || false !== strpos($nm_mask, 'a') || false !== strpos($nm_mask, '*'))
      {
          $new_campo = '';
          $a_mask_ord  = array();
          $i_mask_size = -1;

          foreach (explode(';', $nm_mask) as $str_mask)
          {
              $a_mask_ord[ $this->nm_conta_mask_chars($str_mask) ] = $str_mask;
          }
          ksort($a_mask_ord);

          foreach ($a_mask_ord as $i_size => $s_mask)
          {
              if (-1 == $i_mask_size)
              {
                  $i_mask_size = $i_size;
              }
              elseif (strlen($nm_campo) >= $i_size && strlen($nm_campo) > $i_mask_size)
              {
                  $i_mask_size = $i_size;
              }
          }
          $nm_mask = $a_mask_ord[$i_mask_size];

          for ($i = 0; $i < strlen($nm_mask); $i++)
          {
              $test_mask = substr($nm_mask, $i, 1);
              
              if ('9' == $test_mask || 'a' == $test_mask || '*' == $test_mask)
              {
                  $new_campo .= substr($nm_campo, 0, 1);
                  $nm_campo   = substr($nm_campo, 1);
              }
              else
              {
                  $new_campo .= $test_mask;
              }
          }

                  $nm_campo = $new_campo;

          return;
      }

      $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 ($cont1 < $cont2 && $tam_campo <= $cont2 && $tam_campo > $cont1)
              {
                  $trab_mask = $ver_duas[1];
              }
              elseif ($cont1 > $cont2 && $tam_campo <= $cont2)
              {
                  $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;
   } 
   function nm_conta_mask_chars($sMask)
   {
       $iLength = 0;

       for ($i = 0; $i < strlen($sMask); $i++)
       {
           if (in_array($sMask[$i], array('9', 'a', '*')))
           {
               $iLength++;
           }
       }

       return $iLength;
   }
   function nm_tira_mask(&$nm_campo, $nm_mask, $nm_chars = '')
   { 
      $mask_dados = $nm_campo;
      $trab_mask  = $nm_mask;
      $tam_campo  = strlen($nm_campo);
      $tam_mask   = strlen($nm_mask);
      $trab_saida = "";

      if (false !== strpos($nm_mask, '9') || false !== strpos($nm_mask, 'a') || false !== strpos($nm_mask, '*'))
      {
          $raw_campo = $this->sc_clear_mask($nm_campo, $nm_chars);
          $raw_mask  = $this->sc_clear_mask($nm_mask, $nm_chars);
          $new_campo = '';

          $test_mask = substr($raw_mask, 0, 1);
          $raw_mask  = substr($raw_mask, 1);

          while ('' != $raw_campo)
          {
              $test_val  = substr($raw_campo, 0, 1);
              $raw_campo = substr($raw_campo, 1);
              $ord       = ord($test_val);
              $found     = false;

              switch ($test_mask)
              {
                  case '9':
                      if (48 <= $ord && 57 >= $ord)
                      {
                          $new_campo .= $test_val;
                          $found      = true;
                      }
                      break;

                  case 'a':
                      if ((65 <= $ord && 90 >= $ord) || (97 <= $ord && 122 >= $ord))
                      {
                          $new_campo .= $test_val;
                          $found      = true;
                      }
                      break;

                  case '*':
                      if ((48 <= $ord && 57 >= $ord) || (65 <= $ord && 90 >= $ord) || (97 <= $ord && 122 >= $ord))
                      {
                          $new_campo .= $test_val;
                          $found      = true;
                      }
                      break;
              }

              if ($found)
              {
                  $test_mask = substr($raw_mask, 0, 1);
                  $raw_mask  = substr($raw_mask, 1);
              }
          }

          $nm_campo = $new_campo;

          return;
      }

      $mask_num = false;
      for ($x=0; $x < strlen($trab_mask); $x++)
      {
          if (substr($trab_mask, $x, 1) == "#")
          {
              $mask_num = true;
              break;
          }
      }
      if ($mask_num )
      {
          for ($x=0; $x < strlen($mask_dados); $x++)
          {
              if (is_numeric(substr($mask_dados, $x, 1)))
              {
                  $trab_saida .= substr($mask_dados, $x, 1);
              }
          }
          $nm_campo = $trab_saida;
          return;
      }
      if ($tam_mask > $tam_campo)
      {
         $mask_desfaz = "";
         for ($mask_ind = 0; $tam_mask > $tam_campo; $mask_ind++)
         {
              $mask_char = substr($trab_mask, $mask_ind, 1);
              if ($mask_char == "z")
              {
                  $tam_mask--;
              }
              else
              {
                  $mask_desfaz .= $mask_char;
              }
              if ($mask_ind == $tam_campo)
              {
                  $tam_mask = $tam_campo;
              }
         }
         $trab_mask = $mask_desfaz . substr($trab_mask, $mask_ind);
      }
      $mask_saida = "";
      for ($mask_ind = strlen($trab_mask); $mask_ind > 0; $mask_ind--)
      {
          $mask_char = substr($trab_mask, $mask_ind - 1, 1);
          if ($mask_char == "x" || $mask_char == "z")
          {
              if ($tam_campo > 0)
              {
                  $mask_saida = substr($mask_dados, $tam_campo - 1, 1) . $mask_saida;
              }
          }
          else
          {
              if ($mask_char != substr($mask_dados, $tam_campo - 1, 1) && $tam_campo > 0)
              {
                  $mask_saida = substr($mask_dados, $tam_campo - 1, 1) . $mask_saida;
                  $mask_ind--;
              }
          }
          $tam_campo--;
      }
      if ($tam_campo > 0)
      {
         $mask_saida = substr($mask_dados, 0, $tam_campo) . $mask_saida;
      }
      $nm_campo = $mask_saida;
   }

   function sc_clear_mask($value, $chars)
   {
       $new = '';

       for ($i = 0; $i < strlen($value); $i++)
       {
           if (false === strpos($chars, $value[$i]))
           {
               $new .= $value[$i];
           }
       }

       return $new;
   }
//
   function nm_limpa_alfa(&$str)
   {
   }
   function nm_conv_data_db($dt_in, $form_in, $form_out, $replaces = array())
   {
       $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";
       }
       if (strtoupper($form_out) == "SC_FORMAT_REGION") {
           $this->nm_data->SetaData($dt_in, strtoupper($form_in));
           $prep_out  = (strpos(strtolower($form_in), "dd") !== false) ? "dd" : "";
           $prep_out .= (strpos(strtolower($form_in), "mm") !== false) ? "mm" : "";
           $prep_out .= (strpos(strtolower($form_in), "aa") !== false) ? "aaaa" : "";
           $prep_out .= (strpos(strtolower($form_in), "yy") !== false) ? "aaaa" : "";
           return $this->nm_data->FormataSaida($this->nm_data->FormatRegion("DT", $prep_out));
       }
       else {
           nm_conv_form_data($dt_out, $form_in, $form_out, $replaces);
           return $dt_out;
       }
   }

   function ajax_return_values()
   {
          $this->ajax_return_values_info();
          $this->ajax_return_values_code_fp();
          $this->ajax_return_values_nin();
          $this->ajax_return_values_resultat();
          if ('navigate_form' == $this->NM_ajax_opcao)
          {
              $this->NM_ajax_info['clearUpload']      = 'S';
              $this->NM_ajax_info['navStatus']['ret'] = $this->Nav_permite_ret ? 'S' : 'N';
              $this->NM_ajax_info['navStatus']['ava'] = $this->Nav_permite_ava ? 'S' : 'N';
          }
   } // ajax_return_values

          //----- info
   function ajax_return_values_info($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("info", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->info);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['info'] = array(
                       'row'    => '',
               'type'    => 'label',
               'valList' => array($sTmpValue),
              );
          }
   }

          //----- code_fp
   function ajax_return_values_code_fp($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("code_fp", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->code_fp);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['code_fp'] = array(
                       'row'    => '',
               'type'    => 'text',
               'valList' => array($this->form_encode_input($sTmpValue)),
              );
          }
   }

          //----- nin
   function ajax_return_values_nin($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("nin", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->nin);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['nin'] = array(
                       'row'    => '',
               'type'    => 'text',
               'valList' => array($this->form_encode_input($sTmpValue)),
              );
          }
   }

          //----- resultat
   function ajax_return_values_resultat($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("resultat", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->resultat);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['resultat'] = array(
                       'row'    => '',
               'type'    => 'label',
               'valList' => array($sTmpValue),
              );
          }
   }

    function fetchUniqueUploadName($originalName, $uploadDir, $fieldName)
    {
        $originalName = trim($originalName);
        if ('' == $originalName)
        {
            return $originalName;
        }
        if (!@is_dir($uploadDir))
        {
            return $originalName;
        }
        if (!isset($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['upload_dir'][$fieldName]))
        {
            $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['upload_dir'][$fieldName] = array();
            $resDir = @opendir($uploadDir);
            if (!$resDir)
            {
                return $originalName;
            }
            while (false !== ($fileName = @readdir($resDir)))
            {
                if (@is_file($uploadDir . $fileName))
                {
                    $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['upload_dir'][$fieldName][] = $fileName;
                }
            }
            @closedir($resDir);
        }
        if (!in_array($originalName, $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['upload_dir'][$fieldName]))
        {
            $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['upload_dir'][$fieldName][] = $originalName;
            return $originalName;
        }
        else
        {
            $newName = $this->fetchFileNextName($originalName, $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['upload_dir'][$fieldName]);
            $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['upload_dir'][$fieldName][] = $newName;
            return $newName;
        }
    } // fetchUniqueUploadName

    function fetchFileNextName($uniqueName, $uniqueList)
    {
        $aPathinfo     = pathinfo($uniqueName);
        $fileExtension = $aPathinfo['extension'];
        $fileName      = $aPathinfo['filename'];
        $foundName     = false;
        $nameIt        = 1;
        if ('' != $fileExtension)
        {
            $fileExtension = '.' . $fileExtension;
        }
        while (!$foundName)
        {
            $testName = $fileName . '(' . $nameIt . ')' . $fileExtension;
            if (in_array($testName, $uniqueList))
            {
                $nameIt++;
            }
            else
            {
                $foundName = true;
                return $testName;
            }
        }
    } // fetchFileNextName

   function ajax_add_parameters()
   {
   } // ajax_add_parameters
//
function search_by_code($_code)
{
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  
$check_sql = "SELECT nom_malade, prenom_malade, age_malade, sexe_nm_fk, wilaya, commune, date_declaration, id_fiche_ps, statut_maladie "
   . " FROM fiche_prof_sante";

$wsql =  " WHERE code_fiche = '" . $_code . "'  and deleted is distinct from 'O' limit 1";

$check_sql .= $wsql;

 
      $nm_select = $check_sql; 
      $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nm_select; 
      $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
      $this->rsx = array();
      if ($SCrx = $this->Db->Execute($nm_select)) 
      { 
          $SCy = 0; 
          $nm_count = $SCrx->FieldCount();
          while (!$SCrx->EOF)
          { 
                 for ($SCx = 0; $SCx < $nm_count; $SCx++)
                 { 
                      $this->rsx[$SCy] [$SCx] = $SCrx->fields[$SCx];
                 }
                 $SCy++; 
                 $SCrx->MoveNext();
          } 
          $SCrx->Close();
      } 
      elseif (isset($GLOBALS["NM_ERRO_IBASE"]) && $GLOBALS["NM_ERRO_IBASE"] != 1)  
      { 
          $this->rsx = false;
          $this->rsx_erro = $this->Db->ErrorMsg();
      } 


$individu_array = array();

$sys_array = array();

if (isset($this->rsx[0][0]))     
{
    $individu_array['nom_malade'] = '<b>Nom</b>:&nbsp;' . $this->rsx[0][0];
	$individu_array['prenom_malade'] = '<b>Prénom</b>:&nbsp;' . $this->rsx[0][1];
	$individu_array['age_malade'] = '<b>Age</b>:&nbsp;' . $this->rsx[0][2];
	$individu_array['sexe_malade'] = '<b>Sexe</b>:&nbsp;' . $this->get_nmc($this->rsx[0][3]);
	
	$individu_array['wilaya'] = '<b>Wilaya de résidence</b>:&nbsp;' . $this->get_nom_wilaya($this->rsx[0][4]);
	$individu_array['commune'] = '<b>Commune de résidence</b>:&nbsp;' . $this->get_nom_commune($this->rsx[0][5]);
	
	$individu_array['date_declaration'] = '<b>Date de déclaration</b>:&nbsp;' . $this->nm_conv_data_db($this->rsx[0][6], "db_format", "dd/mm/aaaa");
    
	
	$sys_array['id'] = $this->rsx[0][7];
	$sys_array['date_declaration'] = $this->rsx[0][6];
	
	$sys_array['statut_maladie'] = $this->rsx[0][8];
	
}



if (empty($individu_array)){
	
	
	$individu_string = "Aucun individu n’est associé à ce code.";
}
else{

	$individu_string = implode('<br>', $individu_array);

}



$result_array = array('message'=>$individu_string, 'data'=>$individu_array, 'exist'=>(empty($individu_array)?false:true), 'code'=>$_code, 'sys'=>$sys_array);

return $result_array;
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function search_by_nin($_nin)
{
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  
$check_sql = "SELECT nom_malade, prenom_malade, age_malade, sexe_nm_fk, wilaya, commune, date_declaration, id_fiche_ps, code_fiche, statut_maladie "
   . " FROM fiche_prof_sante  ";

$wsql =  " WHERE nin = '" . $_nin . "'  and deleted is distinct from 'O' limit 1";

$check_sql .= $wsql;


 
      $nm_select = $check_sql; 
      $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nm_select; 
      $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
      $this->rsx = array();
      if ($SCrx = $this->Db->Execute($nm_select)) 
      { 
          $SCy = 0; 
          $nm_count = $SCrx->FieldCount();
          while (!$SCrx->EOF)
          { 
                 for ($SCx = 0; $SCx < $nm_count; $SCx++)
                 { 
                      $this->rsx[$SCy] [$SCx] = $SCrx->fields[$SCx];
                 }
                 $SCy++; 
                 $SCrx->MoveNext();
          } 
          $SCrx->Close();
      } 
      elseif (isset($GLOBALS["NM_ERRO_IBASE"]) && $GLOBALS["NM_ERRO_IBASE"] != 1)  
      { 
          $this->rsx = false;
          $this->rsx_erro = $this->Db->ErrorMsg();
      } 


$individu_array = array();

$sys_array = array();

if (isset($this->rsx[0][0]))     
{
    $individu_array['nom_malade'] = '<b>Nom</b>:&nbsp;' . $this->rsx[0][0];
	$individu_array['prenom_malade'] = '<b>Prénom</b>:&nbsp;' . $this->rsx[0][1];
	$individu_array['age_malade'] = '<b>Age</b>:&nbsp;' . $this->rsx[0][2];
	$individu_array['sexe_malade'] = '<b>Sexe</b>:&nbsp;' . $this->get_nmc($this->rsx[0][3]);
	
	$individu_array['wilaya'] = '<b>Wilaya de résidence</b>:&nbsp;' . $this->get_nom_wilaya($this->rsx[0][4]);
	$individu_array['commune'] = '<b>Commune de résidence</b>:&nbsp;' . $this->get_nom_commune($this->rsx[0][5]);
	
	$individu_array['date_declaration'] = '<b>Date de déclaration</b>:&nbsp;' . $this->nm_conv_data_db($this->rsx[0][6], "db_format", "dd/mm/aaaa");
    
	
	$sys_array['id'] = $this->rsx[0][7];
	$sys_array['date_declaration'] = $this->rsx[0][6];
	$sys_array['code_fiche'] = $this->rsx[0][8];
	$sys_array['statut_maladie'] = $this->rsx[0][9];
}



if (empty($individu_array)){
	
	
	$individu_string = "Aucun individu n’est enregistré avec ce NIN.";
}
else{

	$individu_string = implode('<br>', $individu_array);

}



$result_array = array('message'=>$individu_string, 'data'=>$individu_array, 'exist'=>(empty($individu_array)?false:true), 'nin'=>$_nin, 'sys'=>$sys_array);

return $result_array;
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function scajaxbutton_recherche_fiche_onClick()
{
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  
$original_code_fp = $this->code_fp;
$original_nin = $this->nin;
$original_resultat = $this->resultat;

if (empty($this->code_fp ) && empty($this->nin )){
	

	$error_message = 'Vous devez renseigner le code de la fiche ou le NIN pour effectuer la recherche'; 

	$params = array(
	'title' => '',
	'type' => 'error',
	'timer' => '5000',
	'showConfirmButton' => false,
	'position' => 'center',
	'toast' => true
	);

	$this->nm_mens_alert[] = $error_message; $this->nm_params_alert[] = $params; if ($this->NM_ajax_flag) { $this->sc_ajax_alert($error_message, $params); }}
elseif (!empty($this->code_fp )){
	
	$search = $this->search_by_code($this->code_fp );
	
	$_SESSION['recherche_fiche_ps_mob']['resultat_array'] = $search;
	
		 
	$this->resultat  = $search['message'];

	$_SESSION['recherche_fiche_ps_mob']['code_p'] = $search['exist'];

	$this->Ini->nm_hidden_blocos[3] = 'on'; $this->NM_ajax_info['blockDisplay']['3'] = 'on';
	
	if (isset($search['exist']) && $search['exist']){

		$_SESSION['recherche_fiche_ps_mob']['code_v'] = $this->code_fp ;
		
		$this->NM_ajax_info['buttonDisplay']['fiche_patient'] = $this->nmgp_botoes["fiche_patient"] = 'on';;
		

	}
	else{

		$_SESSION['recherche_fiche_ps_mob']['code_v'] = '';
		
		$this->NM_ajax_info['buttonDisplay']['fiche_patient'] = $this->nmgp_botoes["fiche_patient"] = 'off';;
	}
	
}
elseif (!empty($this->nin )){
	
	$search = $this->search_by_nin($this->nin );
	
	$_SESSION['recherche_fiche_ps_mob']['resultat_array'] = $search;
	
		 
	$this->resultat  = $search['message'];

	$_SESSION['recherche_fiche_ps_mob']['code_p'] = $search['exist'];

	$this->Ini->nm_hidden_blocos[3] = 'on'; $this->NM_ajax_info['blockDisplay']['3'] = 'on';
	
	if (isset($search['exist']) && $search['exist']){

		$this->code_fp  = $search['sys']['code_fiche'];
		
		$_SESSION['recherche_fiche_ps_mob']['code_v'] = $this->code_fp ;
		
		$this->NM_ajax_info['buttonDisplay']['fiche_patient'] = $this->nmgp_botoes["fiche_patient"] = 'on';;
		

	}
	else{

		$_SESSION['recherche_fiche_ps_mob']['code_v'] = '';
		
		$this->NM_ajax_info['buttonDisplay']['fiche_patient'] = $this->nmgp_botoes["fiche_patient"] = 'off';;
	}
	
	
}


$modificado_code_fp = $this->code_fp;
$modificado_nin = $this->nin;
$modificado_resultat = $this->resultat;
$this->nm_formatar_campos('code_fp', 'nin', 'resultat');
if ($original_code_fp !== $modificado_code_fp || isset($this->nmgp_cmp_readonly['code_fp']) || (isset($bFlagRead_code_fp) && $bFlagRead_code_fp))
{
    $this->ajax_return_values_code_fp(true);
}
if ($original_nin !== $modificado_nin || isset($this->nmgp_cmp_readonly['nin']) || (isset($bFlagRead_nin) && $bFlagRead_nin))
{
    $this->ajax_return_values_nin(true);
}
if ($original_resultat !== $modificado_resultat || isset($this->nmgp_cmp_readonly['resultat']) || (isset($bFlagRead_resultat) && $bFlagRead_resultat))
{
    $this->ajax_return_values_resultat(true);
}
$this->NM_ajax_info['event_field'] = 'scajaxbutton';
recherche_fiche_ps_mob_pack_ajax_response();
exit;
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function push_api_log($_source, $_data){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  
	
		$d = date('Y-m-d H:i:s');
	
		$_data = pg_escape_string($_data);
			
			
	
		$insert_table  = 'public.api_log';      
		$insert_fields = array(   
					'source' => "'".$_source."'",
					'input' => "'".$_data."'",
					'dateheure' => "'".$d."'",
					
				 );

		$insert_sql = 'INSERT INTO ' . $insert_table
					. ' ('   . implode(', ', array_keys($insert_fields))   . ')'
					. ' VALUES ('    . implode(', ', array_values($insert_fields)) . ')';

		
     $nm_select = $insert_sql; 
         $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nm_select;
      $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
         $rf = $this->Db->Execute($nm_select);
         if ($rf === false)
         {
             $this->Erro->mensagem (__FILE__, __LINE__, "banco", $this->Ini->Nm_lang['lang_errm_dber'], $this->Db->ErrorMsg());
             $this->NM_rollback_db(); 
             if ($this->NM_ajax_flag)
             {
                recherche_fiche_ps_mob_pack_ajax_response();
             }
             exit;
         }
         $rf->Close();
      
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function get_setting($var_name){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  

		$check_sql = "SELECT set_value"
		   . " FROM sec_settings"
		   . " WHERE set_name = '" . $var_name . "'";
		 
      $nm_select = $check_sql; 
      $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nm_select; 
      $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
      $this->rs = array();
      if ($SCrx = $this->Db->Execute($nm_select)) 
      { 
          $SCy = 0; 
          $nm_count = $SCrx->FieldCount();
          while (!$SCrx->EOF)
          { 
                 for ($SCx = 0; $SCx < $nm_count; $SCx++)
                 { 
                      $this->rs[$SCy] [$SCx] = $SCrx->fields[$SCx];
                 }
                 $SCy++; 
                 $SCrx->MoveNext();
          } 
          $SCrx->Close();
      } 
      elseif (isset($GLOBALS["NM_ERRO_IBASE"]) && $GLOBALS["NM_ERRO_IBASE"] != 1)  
      { 
          $this->rs = false;
          $this->rs_erro = $this->Db->ErrorMsg();
      } 


		$val = '';

		if (isset($this->rs[0][0]))     
		{
		   $val = $this->rs[0][0];

		}

		return $val;
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function get_params($profil){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  
	
		
		$check_sql = 'SELECT geoserver_url, protocol, geoserver_user, geoserver_pwd, timeout_value, max_file_size, maintenance_mode, maintenance_message, admin_contact, geoserver_url_local, url_qr_code'
		   . ' FROM public.app_params'
		   . ' WHERE "profil" = ' ."'" . $profil. "'";
		
		 
      $nm_select = $check_sql; 
      $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nm_select; 
      $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
      $this->rs = array();
      if ($SCrx = $this->Db->Execute($nm_select)) 
      { 
          $SCy = 0; 
          $nm_count = $SCrx->FieldCount();
          while (!$SCrx->EOF)
          { 
                 for ($SCx = 0; $SCx < $nm_count; $SCx++)
                 { 
                      $this->rs[$SCy] [$SCx] = $SCrx->fields[$SCx];
                 }
                 $SCy++; 
                 $SCrx->MoveNext();
          } 
          $SCrx->Close();
      } 
      elseif (isset($GLOBALS["NM_ERRO_IBASE"]) && $GLOBALS["NM_ERRO_IBASE"] != 1)  
      { 
          $this->rs = false;
          $this->rs_erro = $this->Db->ErrorMsg();
      } 


		$_params = array();

		if (isset($this->rs[0][0]))     
		{
			$_params['geoserver_url'] = $this->rs[0][0];
			$_params['protocol'] = $this->rs[0][1];
			$_params['geoserver_user'] = $this->rs[0][2];
			$_params['geoserver_pwd'] = $this->rs[0][3];
			$_params['timeout_value'] = $this->rs[0][4];
			$_params['max_file_size'] = $this->rs[0][5];
			$_params['maintenance_mode'] = $this->rs[0][6];
			$_params['maintenance_message'] = $this->rs[0][7];
			$_params['admin_contact'] = $this->rs[0][8];
			$_params['geoserver_url_local'] = $this->rs[0][9];
			$_params['url_qr_code'] = $this->rs[0][10];
	
		}

		return $_params;
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function get_uuid_url($profil){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  
	
		
		$check_sql = 'SELECT url_uuid_ws'
		   . ' FROM public.app_params'
		   . ' WHERE "profil" = ' ."'" . $profil. "'";
		
		 
      $nm_select = $check_sql; 
      $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nm_select; 
      $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
      $this->rs = array();
      if ($SCrx = $this->Db->Execute($nm_select)) 
      { 
          $SCy = 0; 
          $nm_count = $SCrx->FieldCount();
          while (!$SCrx->EOF)
          { 
                 for ($SCx = 0; $SCx < $nm_count; $SCx++)
                 { 
                      $this->rs[$SCy] [$SCx] = $SCrx->fields[$SCx];
                 }
                 $SCy++; 
                 $SCrx->MoveNext();
          } 
          $SCrx->Close();
      } 
      elseif (isset($GLOBALS["NM_ERRO_IBASE"]) && $GLOBALS["NM_ERRO_IBASE"] != 1)  
      { 
          $this->rs = false;
          $this->rs_erro = $this->Db->ErrorMsg();
      } 


		$_url = '';

		if (isset($this->rs[0][0]))     
		{
			$_url = $this->rs[0][0];

		}

		return $_url;
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function get_device_mgm_url($profil){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  
	
		
		$check_sql = 'SELECT url_device_mgm_ws'
		   . ' FROM public.app_params'
		   . ' WHERE "profil" = ' ."'" . $profil. "'";
		
		 
      $nm_select = $check_sql; 
      $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nm_select; 
      $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
      $this->rs = array();
      if ($SCrx = $this->Db->Execute($nm_select)) 
      { 
          $SCy = 0; 
          $nm_count = $SCrx->FieldCount();
          while (!$SCrx->EOF)
          { 
                 for ($SCx = 0; $SCx < $nm_count; $SCx++)
                 { 
                      $this->rs[$SCy] [$SCx] = $SCrx->fields[$SCx];
                 }
                 $SCy++; 
                 $SCrx->MoveNext();
          } 
          $SCrx->Close();
      } 
      elseif (isset($GLOBALS["NM_ERRO_IBASE"]) && $GLOBALS["NM_ERRO_IBASE"] != 1)  
      { 
          $this->rs = false;
          $this->rs_erro = $this->Db->ErrorMsg();
      } 


		$_url = '';

		if (isset($this->rs[0][0]))     
		{
			$_url = $this->rs[0][0];

		}

		return $_url;
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function get_id($domain_code, $facility_code, $user_name){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  
	
			
			$url = $this->get_uuid_url('A');
		
			$ch = curl_init($url);


			$request_example = array(
				'name_space' => $domain_code,
				'facility_code' => $facility_code,
				'user_name' => $user_name,

			);

			

			$payload = json_encode(array("domain" => $request_example));

			curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);

			curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));

			curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

		
			$result = curl_exec($ch);

			$uuid_results = json_decode($result, true);
	
	
			
			curl_close($ch);
			
			
			
			return $uuid_results;
	
	
	
	
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function get_nmc($code_nmc){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  

		$check_sql = "SELECT nomenclature_item"
		   . " FROM ref_nomenclature_items"
		   . " WHERE nomenclature_item_code = '" . $code_nmc . "'";
		 
      $nm_select = $check_sql; 
      $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nm_select; 
      $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
      $this->rs = array();
      if ($SCrx = $this->Db->Execute($nm_select)) 
      { 
          $SCy = 0; 
          $nm_count = $SCrx->FieldCount();
          while (!$SCrx->EOF)
          { 
                 for ($SCx = 0; $SCx < $nm_count; $SCx++)
                 { 
                      $this->rs[$SCy] [$SCx] = $SCrx->fields[$SCx];
                 }
                 $SCy++; 
                 $SCrx->MoveNext();
          } 
          $SCrx->Close();
      } 
      elseif (isset($GLOBALS["NM_ERRO_IBASE"]) && $GLOBALS["NM_ERRO_IBASE"] != 1)  
      { 
          $this->rs = false;
          $this->rs_erro = $this->Db->ErrorMsg();
      } 


		$nmc = '';

		if (isset($this->rs[0][0]))     
		{
			$nmc = $this->rs[0][0];

		}


		return $nmc;
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function get_wilaya_of_facility($code_facility){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  

		$check_sql = "SELECT wilaya_structure"
		   . " FROM structures_sante"
		   . " WHERE code_structure = '" . $code_facility . "'";
		 
      $nm_select = $check_sql; 
      $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nm_select; 
      $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
      $this->rs = array();
      if ($SCrx = $this->Db->Execute($nm_select)) 
      { 
          $SCy = 0; 
          $nm_count = $SCrx->FieldCount();
          while (!$SCrx->EOF)
          { 
                 for ($SCx = 0; $SCx < $nm_count; $SCx++)
                 { 
                      $this->rs[$SCy] [$SCx] = $SCrx->fields[$SCx];
                 }
                 $SCy++; 
                 $SCrx->MoveNext();
          } 
          $SCrx->Close();
      } 
      elseif (isset($GLOBALS["NM_ERRO_IBASE"]) && $GLOBALS["NM_ERRO_IBASE"] != 1)  
      { 
          $this->rs = false;
          $this->rs_erro = $this->Db->ErrorMsg();
      } 


		$w = '';

		if (isset($this->rs[0][0]))     
		{
			$w = $this->rs[0][0];

		}


		return $w;
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function get_services_of_facility($facility){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  

		$check_sql = "SELECT code_service_sisdz, nom_service"
		   . " FROM structures_services"
		   . " WHERE code_etablissement_sisdz = '" . $facility . "' order by nom_service";
		 
      $nm_select = $check_sql; 
      $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nm_select; 
      $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
      if ($this->rsnmc = $this->Db->Execute($nm_select)) 
      { }
      elseif (isset($GLOBALS["NM_ERRO_IBASE"]) && $GLOBALS["NM_ERRO_IBASE"] != 1)  
      { 
          $this->rsnmc = false;
          $this->rsnmc_erro = $this->Db->ErrorMsg();
      } 


		$nmc = array();

				
		if (false == $this->rsnmc )     
		{
			$nmc[] = 'Error while accessing database (Services sante)';
		}
		else
		{
			$i=1;
		   while(!$this->rsnmc->EOF)
			{
				$nmc[$this->rsnmc->fields[0]] = $this->rsnmc->fields[1];
				$this->rsnmc->MoveNext();
			   
			}
			$this->rsnmc->Close();
		}


		return $nmc;
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function get_nmc_abrege($code_nmc){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  

		$check_sql = "SELECT nomenclature_item_abrege"
		   . " FROM ref_nomenclature_items"
		   . " WHERE nomenclature_item_code = '" . $code_nmc . "'";
		 
      $nm_select = $check_sql; 
      $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nm_select; 
      $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
      $this->rs = array();
      if ($SCrx = $this->Db->Execute($nm_select)) 
      { 
          $SCy = 0; 
          $nm_count = $SCrx->FieldCount();
          while (!$SCrx->EOF)
          { 
                 for ($SCx = 0; $SCx < $nm_count; $SCx++)
                 { 
                      $this->rs[$SCy] [$SCx] = $SCrx->fields[$SCx];
                 }
                 $SCy++; 
                 $SCrx->MoveNext();
          } 
          $SCrx->Close();
      } 
      elseif (isset($GLOBALS["NM_ERRO_IBASE"]) && $GLOBALS["NM_ERRO_IBASE"] != 1)  
      { 
          $this->rs = false;
          $this->rs_erro = $this->Db->ErrorMsg();
      } 


		$nmc = '';

		if (isset($this->rs[0][0]))     
		{
			$nmc = $this->rs[0][0];

		}


		return $nmc;
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function get_items_of_nmc($code_nmc){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  

		$check_sql = "SELECT nomenclature_item_code, nomenclature_item"
		   . " FROM ref_nomenclature_items"
		   . " WHERE nomenclature_fk = '" . $code_nmc . "' order by nomenclature_item_order";
		 
      $nm_select = $check_sql; 
      $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nm_select; 
      $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
      if ($this->rsnmc = $this->Db->Execute($nm_select)) 
      { }
      elseif (isset($GLOBALS["NM_ERRO_IBASE"]) && $GLOBALS["NM_ERRO_IBASE"] != 1)  
      { 
          $this->rsnmc = false;
          $this->rsnmc_erro = $this->Db->ErrorMsg();
      } 


		$nmc = array();

				
		if (false == $this->rsnmc )     
		{
			$nmc[] = 'Error while accessing database (ref_nomenclatures)';
		}
		else
		{
			$i=1;
		   while(!$this->rsnmc->EOF)
			{
				$nmc[$this->rsnmc->fields[0]] = $this->rsnmc->fields[1];
				$this->rsnmc->MoveNext();
			   
			}
			$this->rsnmc->Close();
		}


		return $nmc;
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function is_nmc_secured($code_nmc){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  


		$check_table = 'ref_nomenclatures';    
		$check_where = "nomenclature_code = '".$code_nmc."' and nc_secured='O'"; 

		$check_sql = 'SELECT *'
		   . ' FROM '  . $check_table
		   . ' WHERE ' . $check_where;
		
		 
      $nm_select = $check_sql; 
      $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nm_select; 
      $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
      if ($this->dataset = $this->Db->Execute($nm_select)) 
      { }
      elseif (isset($GLOBALS["NM_ERRO_IBASE"]) && $GLOBALS["NM_ERRO_IBASE"] != 1)  
      { 
          $this->dataset = false;
          $this->dataset_erro = $this->Db->ErrorMsg();
      } 


		if (false == $this->dataset )
		{
			return false;
		}
		elseif ($this->dataset->EOF)
		{
			return false;
		}
		else
		{
			return true;
		}
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function is_nmc_exist($code_nmc){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  


		$check_table = 'ref_nomenclatures';    
		$check_where = "nomenclature_code = '".$code_nmc."'"; 

		$check_sql = 'SELECT *'
		   . ' FROM '  . $check_table
		   . ' WHERE ' . $check_where;
		
		 
      $nm_select = $check_sql; 
      $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nm_select; 
      $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
      if ($this->dataset = $this->Db->Execute($nm_select)) 
      { }
      elseif (isset($GLOBALS["NM_ERRO_IBASE"]) && $GLOBALS["NM_ERRO_IBASE"] != 1)  
      { 
          $this->dataset = false;
          $this->dataset_erro = $this->Db->ErrorMsg();
      } 


		if (false == $this->dataset )
		{
			return false;
		}
		elseif ($this->dataset->EOF)
		{
			return false;
		}
		else
		{
			return true;
		}
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function is_item_nmc_exists($code_item, $code_nmc=''){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  


		$check_table = 'ref_nomenclature_items';    
		
		if (empty($code_nmc)){
			$check_where = "nomenclature_item_code = '".$code_item."'"; 
		}
		else{
			
			$check_where = "nomenclature_item_code = '".$code_item."' and nomenclature_fk ='".$code_nmc."'"; 
		}

		$check_sql = 'SELECT *'
		   . ' FROM '  . $check_table
		   . ' WHERE ' . $check_where;
		
		 
      $nm_select = $check_sql; 
      $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nm_select; 
      $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
      if ($this->dataset = $this->Db->Execute($nm_select)) 
      { }
      elseif (isset($GLOBALS["NM_ERRO_IBASE"]) && $GLOBALS["NM_ERRO_IBASE"] != 1)  
      { 
          $this->dataset = false;
          $this->dataset_erro = $this->Db->ErrorMsg();
      } 


		if (false == $this->dataset )
		{
			return false;
		}
		elseif ($this->dataset->EOF)
		{
			return false;
		}
		else
		{
			return true;
		}
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function get_communes_of_wilaya($wil){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  
		
		$check_sql = "SELECT code_commune, nom_commune"
			   . " FROM commune"
			   . " WHERE code_wilaya='".$wil."'"
			   . " ORDER BY code_commune";
			 
      $nm_select = $check_sql; 
      $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nm_select; 
      $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
      if ($this->rscom = $this->Db->Execute($nm_select)) 
      { }
      elseif (isset($GLOBALS["NM_ERRO_IBASE"]) && $GLOBALS["NM_ERRO_IBASE"] != 1)  
      { 
          $this->rscom = false;
          $this->rscom_erro = $this->Db->ErrorMsg();
      } 


			$communes = array();


			if (false == $this->rscom )     
			{
				$communes[] = 'Error while accessing database (commune)';
			}
			else
			{
				
				
				$i=1;
			   while(!$this->rscom->EOF)
				{
					$communes[$this->rscom->fields[0]] = $this->rscom->fields[1];
				    
					$this->rscom->MoveNext();

				}
				$this->rscom->Close();
			}


			return $communes;
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function get_all_wilayas(){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  
		
		$check_sql = "SELECT code_wilaya, nom_wilaya"
			   . " FROM wilaya"
			   . " ORDER BY code_wilaya";
			 
      $nm_select = $check_sql; 
      $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nm_select; 
      $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
      if ($this->rswil = $this->Db->Execute($nm_select)) 
      { }
      elseif (isset($GLOBALS["NM_ERRO_IBASE"]) && $GLOBALS["NM_ERRO_IBASE"] != 1)  
      { 
          $this->rswil = false;
          $this->rswil_erro = $this->Db->ErrorMsg();
      } 


			$wilayas = array();


			if (false == $this->rswil )     
			{
				$wilayas[] = 'Error while accessing database (ref_nomenclatures)';
			}
			else
			{
				$i=1;
			   while(!$this->rswil->EOF)
				{
					$wilayas[$this->rswil->fields[0]]['name'] = $this->rswil->fields[1];
				    $wilayas[$this->rswil->fields[0]]['communes'] = $this->get_communes_of_wilaya($this->rswil->fields[0]);
					$this->rswil->MoveNext();

				}
				$this->rswil->Close();
			}


			return $wilayas;
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function is_wilaya_exists($_wilaya){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  
		
		$check_table = 'wilaya';    
		$check_where = "code_wilaya = '".$_wilaya."'"; 

		$check_sql = 'SELECT *'
		   . ' FROM '  . $check_table
		   . ' WHERE ' . $check_where;
		
		 
      $nm_select = $check_sql; 
      $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nm_select; 
      $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
      if ($this->dataset = $this->Db->Execute($nm_select)) 
      { }
      elseif (isset($GLOBALS["NM_ERRO_IBASE"]) && $GLOBALS["NM_ERRO_IBASE"] != 1)  
      { 
          $this->dataset = false;
          $this->dataset_erro = $this->Db->ErrorMsg();
      } 


		if (false == $this->dataset )
		{
			return false;
		}
		elseif ($this->dataset->EOF)
		{
			return false;
		}
		else
		{
			return true;
		}
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function get_facilities_by_wilaya($_wilaya){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  
		
		$check_sql = "SELECT code_structure, nom_structure, wilaya_structure, type_structure, longitude, latitude"
			   . " FROM structures_sante"
			   . " WHERE wilaya_structure = '" .$_wilaya. "'"
			   . " ORDER BY wilaya_structure, type_structure";
			 
      $nm_select = $check_sql; 
      $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nm_select; 
      $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
      if ($this->rswil = $this->Db->Execute($nm_select)) 
      { }
      elseif (isset($GLOBALS["NM_ERRO_IBASE"]) && $GLOBALS["NM_ERRO_IBASE"] != 1)  
      { 
          $this->rswil = false;
          $this->rswil_erro = $this->Db->ErrorMsg();
      } 


			$structures = array();


			if (false == $this->rswil )     
			{
				$structures[] = 'Error while accessing database (structures_sante)';
			}
			else
			{
				$i=1;
			   while(!$this->rswil->EOF)
				{
					$structures[$this->rswil->fields[0]]['name'] = $this->rswil->fields[1] . " - " . $this->get_nom_wilaya($this->rswil->fields[2]);
				    $structures[$this->rswil->fields[0]]['wilaya'] = $this->rswil->fields[2];
				    $structures[$this->rswil->fields[0]]['type'] = $this->rswil->fields[3];
				    $structures[$this->rswil->fields[0]]['lng'] = $this->rswil->fields[4];
				    $structures[$this->rswil->fields[0]]['lat'] = $this->rswil->fields[5];
					$this->rswil->MoveNext();

				}
				$this->rswil->Close();
			}


			return $structures;
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function get_all_facilities($_details=false){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  
		
			$d_sql = '';
			if ($_details){
				$d_sql = ', type_structure, longitude, latitude';
				
			}
				
			
		
			$check_sql = "SELECT code_structure, nom_structure, wilaya_structure" . $d_sql
			   . " FROM structures_sante"
			   . " ORDER BY wilaya_structure, type_structure";
			 
      $nm_select = $check_sql; 
      $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nm_select; 
      $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
      if ($this->rswil = $this->Db->Execute($nm_select)) 
      { }
      elseif (isset($GLOBALS["NM_ERRO_IBASE"]) && $GLOBALS["NM_ERRO_IBASE"] != 1)  
      { 
          $this->rswil = false;
          $this->rswil_erro = $this->Db->ErrorMsg();
      } 


			$structures = array();


			if (false == $this->rswil )     
			{
				$structures[] = 'Error while accessing database (structures_sante)';
			}
			else
			{
				$i=1;
			   while(!$this->rswil->EOF)
				{
					
				    if ($d_sql){
						$structures[$this->rswil->fields[0]]['name'] = $this->rswil->fields[1] . " - " . $this->get_nom_wilaya($this->rswil->fields[2]);
						$structures[$this->rswil->fields[0]]['wilaya'] = $this->rswil->fields[2];
						$structures[$this->rswil->fields[0]]['type'] = $this->rswil->fields[3];
						$structures[$this->rswil->fields[0]]['lng'] = $this->rswil->fields[4];
						$structures[$this->rswil->fields[0]]['lat'] = $this->rswil->fields[5];
					}
				    else{
						$structures[$this->rswil->fields[0]] = $this->rswil->fields[1] . " - " . $this->get_nom_wilaya($this->rswil->fields[2]);
						
					}
					$this->rswil->MoveNext();

				}
				$this->rswil->Close();
			}


			return $structures;
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function get_sended_icon_url($var_status){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  
        
               
        switch ($var_status){
            
            case 'TERMINATED':
                
                $icon_url = sc_url_library('sys', 'images_ressources', 'img_messages/sended-1.png');
                $_text = $this->get_nmc('TERMINATED');
                
                break;    
			
			
				
            case 'SCHEDULED':
                
                $icon_url = sc_url_library('sys', 'images_ressources', 'img_messages/waiting-1.png');
                $_text = $this->get_nmc('SCHEDULED');
                
                break;
				
			 case 'INPROGRESS':
                
                $icon_url = sc_url_library('sys', 'images_ressources', 'img_messages/ongoing.png');
                $_text = $this->get_nmc('INPROGRESS');
                
                break;
				
			case 'STOPED':
                
                $icon_url = sc_url_library('sys', 'images_ressources', 'img_messages/not_sended.png');
                $_text = $this->get_nmc('STOPED');
                
                break;
				
				
			case 'RESTARTED':
                
                $icon_url = sc_url_library('sys', 'images_ressources', 'img_messages/returned.png');
                $_text = $this->get_nmc('RESTARTED');
                
                break;
			
		
				
			           
            default:
                
                $icon_url = sc_url_library('sys', 'images_ressources', 'img_messages/not_sended.png');
                $_text = $this->get_nmc('STOPED');
        }        
        
        
        $_icon = '<img  width="32" height="32" style="vertical-align:middle;" title="'.$_text.'" src="'.$icon_url.'" />';
        
        return $_icon;        
        
    
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function get_state_icon_url($var_state){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  
        
               
        switch ($var_state){
            
            case 'V':
                
                $icon_url = sc_url_library('sys', 'images_ressources', 'imgmap/check_24.png');
                $_text = $this->get_nmc('VALIDE');
                
                break;    
			
			
				
            case 'I':
                
                $icon_url = sc_url_library('sys', 'images_ressources', 'imgmap/circle-24_red.png');
                $_text = $this->get_nmc('ERRONE');
                
                break;
			
			
				
			           
            default:
                
                $icon_url = sc_url_library('sys', 'images_ressources', 'imgmap/circle-24_orange.png');
                $_text = $this->get_nmc('ATTENTE');
        }        
        
        
        $_icon = '<img  width="20" height="20" style="vertical-align:middle;" title="'.$_text.'" src="'.$icon_url.'" />';
        
        return $_icon;        
        
    
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function is_valid_email($email){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  

		if (filter_var($email, FILTER_VALIDATE_EMAIL)) {

			return true;
		}
		else{

			return false;

		}

	
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function is_valid_tel($phone){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  

		if(preg_match('/^[0-9]{10}+$/', $phone)) {
			return true;
		} 
		else {
			return false;
		}


	
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function get_state_confirmation_icon_url($var_state){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  
	
	
		switch ($var_state){
            
            case 'C':
                
                $icon_url = sc_url_library('sys', 'images_ressources', 'imgmap/check_24.png');
                $_text = 'Cas confirmé';
                
                break;    
			
							
            case 'I':
                
                $icon_url = sc_url_library('sys', 'images_ressources', 'imgmap/circle-24_blue.png');
                $_text = 'Cas infirmé';
                
                break;
			
			case 'D':
                
                $icon_url = sc_url_library('sys', 'images_ressources', 'imgmap/delete_24.png');
                $_text = 'Résultat indeterminé';
                
                break;	
			
			case 'S':
                
                $icon_url = sc_url_library('sys', 'images_ressources', 'imgmap/circle-24_orange.png');
                $_text = 'Cas suspect - Déclaration en attente de confirmation';
                
                break;					
		
			           
            default:
                
                $icon_url = sc_url_library('sys', 'images_ressources', 'imgmap/circle-24_orange.png');
                $_text = 'Déclaration en attente de confirmation';
		}
		
		$_icon = '<img  width="24" height="24" title="'.$_text.'" src="'.$icon_url.'" />';
        
        return $_icon;
		
	
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function get_suspect_state_icon_url($var_state){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  
        
               
        
        if ($var_state == 'R'){    
 
			$icon_url = sc_url_library('sys', 'images_ressources', 'img/lock_open_24.png');
			$_text = $this->get_nmc('EFRAP');
 			
		}
		elseif ($var_state == 'L'){
			
			
			
			$icon_url = sc_url_library('sys', 'images_ressources', 'img/lock_ok_24.png');
  			$_text = $this->get_nmc('EFLAB');
			
		}
		elseif ($var_state == 'S'){
			
					
			$icon_url = sc_url_library('sys', 'images_ressources', 'img/lock_ok_24.png');
  			$_text = $this->get_nmc('EFSEM');
			
		}
       
        $_icon = "<img  width='24' height='24' title='".$_text."' src='".$icon_url."' style='vertical-align:middle' />";
        
        return $_icon;        
        
    
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function get_suspect_state_flag_icon_url($var_state){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  
        
               
        
        if ($var_state == 'R'){    
 
			$icon_url = sc_url_library('sys', 'images_ressources', 'img/signal_flag_white_24.png');
			$_text = $this->get_nmc('EFRAP');
 			
		}
		elseif ($var_state == 'L'){
			
			
			
			$icon_url = sc_url_library('sys', 'images_ressources', 'img/signal_flag_blue_24.png');
  			$_text = $this->get_nmc('EFLAB');
			
		}
		elseif ($var_state == 'S'){
			
					
			$icon_url = sc_url_library('sys', 'images_ressources', 'img/signal_flag_green_24.png');
  			$_text = $this->get_nmc('EFSEM');
			
		}
       
        $_icon = "<img  width='24' height='24' title='".$_text."' src='".$icon_url."' style='vertical-align:middle' />";
        
        return $_icon;        
        
    
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function getProtocol() {
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  
    if (
        (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ||
        (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 443) ||
        (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https')
    ) {
        return 'https';
    }
    return 'http';

$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function is_group_exists($_group){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  
	
	$slogin = $this->Db->qstr($_group);
	

	$check_table = 'sec_groups';    
	$check_where = "group_id = ".$_group; 

	$check_sql = 'SELECT *'
	   . ' FROM '  . $check_table
	   . ' WHERE ' . $check_where;
	 
      $nm_select = $check_sql; 
      $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nm_select; 
      $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
      if ($this->dataset = $this->Db->Execute($nm_select)) 
      { }
      elseif (isset($GLOBALS["NM_ERRO_IBASE"]) && $GLOBALS["NM_ERRO_IBASE"] != 1)  
      { 
          $this->dataset = false;
          $this->dataset_erro = $this->Db->ErrorMsg();
      } 


	if (false == $this->dataset )
	{
		return false;
	}
	elseif ($this->dataset->EOF)
	{
		return false;
	}
	else
	{
		return true;
	}
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function is_login_exists($_login){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  
	
	
	
	
	$slogin = $this->Db->qstr($_login);
	

	$check_table = 'sec_users';    
	$check_where = "login = ".$slogin; 

	$check_sql = 'SELECT *'
	   . ' FROM '  . $check_table
	   . ' WHERE ' . $check_where;
	 
      $nm_select = $check_sql; 
      $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nm_select; 
      $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
      if ($this->dataset = $this->Db->Execute($nm_select)) 
      { }
      elseif (isset($GLOBALS["NM_ERRO_IBASE"]) && $GLOBALS["NM_ERRO_IBASE"] != 1)  
      { 
          $this->dataset = false;
          $this->dataset_erro = $this->Db->ErrorMsg();
      } 


	if (false == $this->dataset )
	{
		return false;
	}
	elseif ($this->dataset->EOF)
	{
		return false;
	}
	else
	{
		return true;
	}
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function get_groups_of_wilaya($_wilaya){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  

	$check_sql = 'SELECT group_id, description ' 
		       . 'FROM sec_groups WHERE "structure" in (select code_structure from structures_sante where wilaya_structure = '."'$_wilaya') and ".'"role"' . "= 'R' and mobile='O' and profile = 'N'";
	 
      $nm_select = $check_sql; 
      $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nm_select; 
      $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
      if ($this->rsgx = $this->Db->Execute($nm_select)) 
      { }
      elseif (isset($GLOBALS["NM_ERRO_IBASE"]) && $GLOBALS["NM_ERRO_IBASE"] != 1)  
      { 
          $this->rsgx = false;
          $this->rsgx_erro = $this->Db->ErrorMsg();
      } 


	$_groups = array();
	if (false == $this->rsgx )     
	{
		$_groups[0] = 'Error while accessing database (groups of wilaya)';
	}
	else
	{
	   while(!$this->rsgx->EOF)
		{
			$_groups[$this->rsgx->fields[0]] = $this->rsgx->fields[1];
			$this->rsgx->MoveNext();
		}
		$this->rsgx->Close();
	}


	return $_groups;
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function check_token($token){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  
	
	$JWT = sc_url_library('sys', 'JWT_03', 'classes/JWT.php'); 
	$KEY = sc_url_library('sys', 'JWT_03', 'includes/config.php');

	require_once($JWT);
	require_once($KEY);

	$jwt = new JWT();
	
	$_check_array = array();

	if(!$jwt->isValid($token)){
		$_check_array['message'] = 'Token invalide';
		$_check_array['http_response'] = 401;
		$_check_array['error'] = '3';
		$_check_array['valid'] = false;
		
	}
	else if (!$jwt->check($token, SECRET)){
		$_check_array['message'] = 'Token invalide';
		$_check_array['http_response'] = 401;
		$_check_array['error'] = '4';
		$_check_array['valid'] = false;
	}
	else if ($jwt->isExpired($token)){
		$_check_array['message'] = 'Le token a expiré';
		$_check_array['http_response'] = 401;
		$_check_array['error'] = '5';
		$_check_array['valid'] = false;
	}
	else{
		
		$_check_array['message'] = '';
		$_check_array['http_response'] = 200;
		$_check_array['error'] = '0';
		$_check_array['valid'] = true;
		$_check_array['payload'] = $jwt->getPayload($token);
		
		
	}
	
	return $_check_array;
	
	

$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function get_group($var_group_id){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  



	$check_sql = "SELECT description, structure, mobile, role, profile, profile_group, scope, default_app "
	   . " FROM sec_groups"
	   . " WHERE group_id = '" . $var_group_id . "'";
	 
      $nm_select = $check_sql; 
      $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nm_select; 
      $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
      $this->rsg = array();
      if ($SCrx = $this->Db->Execute($nm_select)) 
      { 
          $SCy = 0; 
          $nm_count = $SCrx->FieldCount();
          while (!$SCrx->EOF)
          { 
                 for ($SCx = 0; $SCx < $nm_count; $SCx++)
                 { 
                      $this->rsg[$SCy] [$SCx] = $SCrx->fields[$SCx];
                 }
                 $SCy++; 
                 $SCrx->MoveNext();
          } 
          $SCrx->Close();
      } 
      elseif (isset($GLOBALS["NM_ERRO_IBASE"]) && $GLOBALS["NM_ERRO_IBASE"] != 1)  
      { 
          $this->rsg = false;
          $this->rsg_erro = $this->Db->ErrorMsg();
      } 



	$_gdx = array();

	if (isset($this->rsg[0][0]))     
	{
		$_gdx['group_desc'] = $this->rsg[0][0];
		$_gdx['structure'] = $this->rsg[0][1];
		$_gdx['mobile'] = $this->rsg[0][2];
		$_gdx['role'] = $this->rsg[0][3];
		$_gdx['profile'] = $this->rsg[0][4];
		$_gdx['profile_group'] = $this->rsg[0][5];
		$_gdx['scope'] = $this->rsg[0][6];
		$_gdx['default_app'] = $this->rsg[0][7];

	}



	return $_gdx;
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function get_structure_from_group($var_group_id){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  

	

	$check_sql = "SELECT nom_structure, code_structure"
	   . " FROM structures_sante where code_structure in (select structure from sec_groups where group_id='".$var_group_id."')";

	 
      $nm_select = $check_sql; 
      $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nm_select; 
      $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
      $this->rss = array();
      if ($SCrx = $this->Db->Execute($nm_select)) 
      { 
          $SCy = 0; 
          $nm_count = $SCrx->FieldCount();
          while (!$SCrx->EOF)
          { 
                 for ($SCx = 0; $SCx < $nm_count; $SCx++)
                 { 
                      $this->rss[$SCy] [$SCx] = $SCrx->fields[$SCx];
                 }
                 $SCy++; 
                 $SCrx->MoveNext();
          } 
          $SCrx->Close();
      } 
      elseif (isset($GLOBALS["NM_ERRO_IBASE"]) && $GLOBALS["NM_ERRO_IBASE"] != 1)  
      { 
          $this->rss = false;
          $this->rss_erro = $this->Db->ErrorMsg();
      } 



	$_struc = array();

	if (isset($this->rss[0][0]))     
	{
		$_struc['name']  = $this->rss[0][0];
		$_struc['code'] = $this->rss[0][1];
	}

	return $_struc;
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function get_user_details($var_username){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  

		
		
		$slogin = $this->Db->qstr($var_username);
	
		$check_sql = "SELECT \"name\", email, active, mfa, group_id, reset, priv_admin, tel, profession_nm_fk"
		   . " FROM sec_users"
		   . " WHERE login = " . $slogin ;
		 
      $nm_select = $check_sql; 
      $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nm_select; 
      $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
      $this->rs = array();
      if ($SCrx = $this->Db->Execute($nm_select)) 
      { 
          $SCy = 0; 
          $nm_count = $SCrx->FieldCount();
          while (!$SCrx->EOF)
          { 
                 for ($SCx = 0; $SCx < $nm_count; $SCx++)
                 { 
                      $this->rs[$SCy] [$SCx] = $SCrx->fields[$SCx];
                 }
                 $SCy++; 
                 $SCrx->MoveNext();
          } 
          $SCrx->Close();
      } 
      elseif (isset($GLOBALS["NM_ERRO_IBASE"]) && $GLOBALS["NM_ERRO_IBASE"] != 1)  
      { 
          $this->rs = false;
          $this->rs_erro = $this->Db->ErrorMsg();
      } 


		$_ud= array();

		 $_ud['login'] = $var_username;

		if (isset($this->rs[0][0]))     
		{
			$_ud['name'] = $this->rs[0][0];
			$_ud['email'] = $this->rs[0][1];
			$_ud['active'] = $this->rs[0][2];
			$_ud['mfa'] = $this->rs[0][3];
			$_ud['group'] = $this->rs[0][4];
			$_ud['reset'] = $this->rs[0][5];
			$_ud['admin'] = $this->rs[0][6];
			$_ud['tel'] = $this->rs[0][7];
			$_ud['profession'] = $this->rs[0][8];
			
			
		}

		$_g = $_ud['group'];



		if (isset($_g) && !empty($_g)){


			$_gdetails = $this->get_group($_g);


			if (isset($_gdetails)){

					$_ud['group_name'] = $_gdetails['group_desc'];
					$_ud['mobile'] = $_gdetails['mobile'];
				    $_ud['code_structure'] = $_gdetails['structure'];
					$_ud['role'] = $_gdetails['role'];
				    $_ud['scope'] = $_gdetails['scope'];

					$_struc = $this->get_structure_from_group($_g);


					if (isset($_struc)){

						$_ud['name_structure'] = $_struc['name'];
						$_ud['code_structure'] = $_struc['code'];

					}
			}

		}


	
	return $_ud;
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function get_facility_status($facilitycode){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  
	
	$check_sql = "SELECT statut_structure_nm_fk"
	   . " FROM public.structures_sante"
	   . " WHERE code_structure = '" . $facilitycode . "'";
	 
      $nm_select = $check_sql; 
      $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nm_select; 
      $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
      $this->rs = array();
      if ($SCrx = $this->Db->Execute($nm_select)) 
      { 
          $SCy = 0; 
          $nm_count = $SCrx->FieldCount();
          while (!$SCrx->EOF)
          { 
                 for ($SCx = 0; $SCx < $nm_count; $SCx++)
                 { 
                      $this->rs[$SCy] [$SCx] = $SCrx->fields[$SCx];
                 }
                 $SCy++; 
                 $SCrx->MoveNext();
          } 
          $SCrx->Close();
      } 
      elseif (isset($GLOBALS["NM_ERRO_IBASE"]) && $GLOBALS["NM_ERRO_IBASE"] != 1)  
      { 
          $this->rs = false;
          $this->rs_erro = $this->Db->ErrorMsg();
      } 


	$inst = '';

	if (isset($this->rs[0][0]))     
	{
		$inst = $this->rs[0][0];

	}


	return $inst;
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function check_user($var_user, $var_pwd){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  
	
	
	
	
	$slogin = $this->Db->qstr($var_user);
	$spswd  = $this->Db->qstr($var_pwd);

	$check_table = 'sec_users';    
	$check_where = "login = ".$slogin." and pswd=".$spswd; 

	$check_sql = 'SELECT *'
	   . ' FROM '  . $check_table
	   . ' WHERE ' . $check_where;
	 
      $nm_select = $check_sql; 
      $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nm_select; 
      $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
      if ($this->dataset = $this->Db->Execute($nm_select)) 
      { }
      elseif (isset($GLOBALS["NM_ERRO_IBASE"]) && $GLOBALS["NM_ERRO_IBASE"] != 1)  
      { 
          $this->dataset = false;
          $this->dataset_erro = $this->Db->ErrorMsg();
      } 


	if (false == $this->dataset )
	{
		return false;
	}
	elseif ($this->dataset->EOF)
	{
		return false;
	}
	else
	{
		return true;
	}
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function get_name_of_user($user){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  


	$check_sql = 'SELECT name'
	   . ' FROM public.sec_users'
	   . " WHERE login = '" . $user. "'";

	 
      $nm_select = $check_sql; 
      $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nm_select; 
      $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
      $this->rs = array();
      if ($SCrx = $this->Db->Execute($nm_select)) 
      { 
          $SCy = 0; 
          $nm_count = $SCrx->FieldCount();
          while (!$SCrx->EOF)
          { 
                 for ($SCx = 0; $SCx < $nm_count; $SCx++)
                 { 
                      $this->rs[$SCy] [$SCx] = $SCrx->fields[$SCx];
                 }
                 $SCy++; 
                 $SCrx->MoveNext();
          } 
          $SCrx->Close();
      } 
      elseif (isset($GLOBALS["NM_ERRO_IBASE"]) && $GLOBALS["NM_ERRO_IBASE"] != 1)  
      { 
          $this->rs = false;
          $this->rs_erro = $this->Db->ErrorMsg();
      } 


	$nuser = '';

	if (isset($this->rs[0][0]))     
	{
		$nuser = $this->rs[0][0];

	}

	return $nuser;
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function get_name_of_group($group){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  


	$check_sql = 'SELECT description'
	   . ' FROM public.sec_groups'
	   . " WHERE group_id = '" . $group. "'";

	 
      $nm_select = $check_sql; 
      $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nm_select; 
      $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
      $this->rs = array();
      if ($SCrx = $this->Db->Execute($nm_select)) 
      { 
          $SCy = 0; 
          $nm_count = $SCrx->FieldCount();
          while (!$SCrx->EOF)
          { 
                 for ($SCx = 0; $SCx < $nm_count; $SCx++)
                 { 
                      $this->rs[$SCy] [$SCx] = $SCrx->fields[$SCx];
                 }
                 $SCy++; 
                 $SCrx->MoveNext();
          } 
          $SCrx->Close();
      } 
      elseif (isset($GLOBALS["NM_ERRO_IBASE"]) && $GLOBALS["NM_ERRO_IBASE"] != 1)  
      { 
          $this->rs = false;
          $this->rs_erro = $this->Db->ErrorMsg();
      } 


	$ngroup = '';

	if (isset($this->rs[0][0]))     
	{
		$ngroup = $this->rs[0][0];

	}

	return $ngroup;
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function get_default_app_of_group($group){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  


	$check_sql = 'SELECT default_app'
	   . ' FROM public.sec_groups'
	   . " WHERE group_id = '" . $group. "'";

	 
      $nm_select = $check_sql; 
      $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nm_select; 
      $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
      $this->rs = array();
      if ($SCrx = $this->Db->Execute($nm_select)) 
      { 
          $SCy = 0; 
          $nm_count = $SCrx->FieldCount();
          while (!$SCrx->EOF)
          { 
                 for ($SCx = 0; $SCx < $nm_count; $SCx++)
                 { 
                      $this->rs[$SCy] [$SCx] = $SCrx->fields[$SCx];
                 }
                 $SCy++; 
                 $SCrx->MoveNext();
          } 
          $SCrx->Close();
      } 
      elseif (isset($GLOBALS["NM_ERRO_IBASE"]) && $GLOBALS["NM_ERRO_IBASE"] != 1)  
      { 
          $this->rs = false;
          $this->rs_erro = $this->Db->ErrorMsg();
      } 


	$ngroup = '';

	if (isset($this->rs[0][0]))     
	{
		$ngroup = $this->rs[0][0];

	}

	return $ngroup;
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function is_validator($group){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  


	$check_sql = 'SELECT role'
	   . ' FROM public.sec_groups'
	   . " WHERE group_id = '" . $group. "'";

	 
      $nm_select = $check_sql; 
      $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nm_select; 
      $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
      $this->rs = array();
      if ($SCrx = $this->Db->Execute($nm_select)) 
      { 
          $SCy = 0; 
          $nm_count = $SCrx->FieldCount();
          while (!$SCrx->EOF)
          { 
                 for ($SCx = 0; $SCx < $nm_count; $SCx++)
                 { 
                      $this->rs[$SCy] [$SCx] = $SCrx->fields[$SCx];
                 }
                 $SCy++; 
                 $SCrx->MoveNext();
          } 
          $SCrx->Close();
      } 
      elseif (isset($GLOBALS["NM_ERRO_IBASE"]) && $GLOBALS["NM_ERRO_IBASE"] != 1)  
      { 
          $this->rs = false;
          $this->rs_erro = $this->Db->ErrorMsg();
      } 


	$v = false;

	if (isset($this->rs[0][0]))     
	{
		$vgroup = $this->rs[0][0];
		if ($vgroup=='V'){

			$v = true;
		}


	}

	return $v;
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function is_mobilegroup($group){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  


	$check_sql = 'SELECT mobile'
	   . ' FROM public.sec_groups'
	   . " WHERE group_id = '" . $group. "'";

	 
      $nm_select = $check_sql; 
      $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nm_select; 
      $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
      $this->rs = array();
      if ($SCrx = $this->Db->Execute($nm_select)) 
      { 
          $SCy = 0; 
          $nm_count = $SCrx->FieldCount();
          while (!$SCrx->EOF)
          { 
                 for ($SCx = 0; $SCx < $nm_count; $SCx++)
                 { 
                      $this->rs[$SCy] [$SCx] = $SCrx->fields[$SCx];
                 }
                 $SCy++; 
                 $SCrx->MoveNext();
          } 
          $SCrx->Close();
      } 
      elseif (isset($GLOBALS["NM_ERRO_IBASE"]) && $GLOBALS["NM_ERRO_IBASE"] != 1)  
      { 
          $this->rs = false;
          $this->rs_erro = $this->Db->ErrorMsg();
      } 


	$v = false;

	if (isset($this->rs[0][0]))     
	{
		$vgroup = $this->rs[0][0];
		if ($vgroup=='O'){

			$v = true;
		}


	}

	return $v;
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function is_profilegroup($group){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  


	$check_sql = 'SELECT profile'
	   . ' FROM public.sec_groups'
	   . " WHERE group_id = '" . $group. "'";

	 
      $nm_select = $check_sql; 
      $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nm_select; 
      $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
      $this->rs = array();
      if ($SCrx = $this->Db->Execute($nm_select)) 
      { 
          $SCy = 0; 
          $nm_count = $SCrx->FieldCount();
          while (!$SCrx->EOF)
          { 
                 for ($SCx = 0; $SCx < $nm_count; $SCx++)
                 { 
                      $this->rs[$SCy] [$SCx] = $SCrx->fields[$SCx];
                 }
                 $SCy++; 
                 $SCrx->MoveNext();
          } 
          $SCrx->Close();
      } 
      elseif (isset($GLOBALS["NM_ERRO_IBASE"]) && $GLOBALS["NM_ERRO_IBASE"] != 1)  
      { 
          $this->rs = false;
          $this->rs_erro = $this->Db->ErrorMsg();
      } 


	$v = false;

	if (isset($this->rs[0][0]))     
	{
		$vgroup = $this->rs[0][0];
		if ($vgroup=='O'){

			$v = true;
		}


	}

	return $v;
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function is_group_of_role($group, $role){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  


	$check_sql = 'SELECT role'
	   . ' FROM public.sec_groups'
	   . " WHERE group_id = '" . $group. "'";

	 
      $nm_select = $check_sql; 
      $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nm_select; 
      $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
      $this->rs = array();
      if ($SCrx = $this->Db->Execute($nm_select)) 
      { 
          $SCy = 0; 
          $nm_count = $SCrx->FieldCount();
          while (!$SCrx->EOF)
          { 
                 for ($SCx = 0; $SCx < $nm_count; $SCx++)
                 { 
                      $this->rs[$SCy] [$SCx] = $SCrx->fields[$SCx];
                 }
                 $SCy++; 
                 $SCrx->MoveNext();
          } 
          $SCrx->Close();
      } 
      elseif (isset($GLOBALS["NM_ERRO_IBASE"]) && $GLOBALS["NM_ERRO_IBASE"] != 1)  
      { 
          $this->rs = false;
          $this->rs_erro = $this->Db->ErrorMsg();
      } 


	$v = false;

	if (isset($this->rs[0][0]))     
	{
		$vgrouprole = $this->rs[0][0];
		if ($vgrouprole==$role){

			$v = true;
		}


	}

	return $v;
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function get_profile_of_group($group){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  


	$check_sql = 'SELECT profile_group'
	   . ' FROM public.sec_groups'
	   . " WHERE group_id = '" . $group. "'";

	 
      $nm_select = $check_sql; 
      $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nm_select; 
      $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
      $this->rs = array();
      if ($SCrx = $this->Db->Execute($nm_select)) 
      { 
          $SCy = 0; 
          $nm_count = $SCrx->FieldCount();
          while (!$SCrx->EOF)
          { 
                 for ($SCx = 0; $SCx < $nm_count; $SCx++)
                 { 
                      $this->rs[$SCy] [$SCx] = $SCrx->fields[$SCx];
                 }
                 $SCy++; 
                 $SCrx->MoveNext();
          } 
          $SCrx->Close();
      } 
      elseif (isset($GLOBALS["NM_ERRO_IBASE"]) && $GLOBALS["NM_ERRO_IBASE"] != 1)  
      { 
          $this->rs = false;
          $this->rs_erro = $this->Db->ErrorMsg();
      } 


	$rgroup = '';

	if (isset($this->rs[0][0]))     
	{
		$rgroup = $this->rs[0][0];

	}

	return $rgroup;
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function get_groups_of_user($username){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  

	/**
	 * Récupérer les groupes de l'utiliateur
	 */

	$check_sql = 'SELECT group_id'
	   . ' FROM public.sec_users_groups'
	   . " WHERE login = '" . $username. "'";
	 
      $nm_select = $check_sql; 
      $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nm_select; 
      $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
      if ($this->rs = $this->Db->Execute($nm_select)) 
      { }
      elseif (isset($GLOBALS["NM_ERRO_IBASE"]) && $GLOBALS["NM_ERRO_IBASE"] != 1)  
      { 
          $this->rs = false;
          $this->rs_erro = $this->Db->ErrorMsg();
      } 


	$_groups = array();
	if (false == $this->rs)     // Error while accessing database
	{
		
 if (!isset($this->Campos_Mens_erro)){$this->Campos_Mens_erro = "";}
 if (!empty($this->Campos_Mens_erro)){$this->Campos_Mens_erro .= "<br>";}$this->Campos_Mens_erro .= 'Error while accessing database (groups of user)';
 if ('submit_form' == $this->NM_ajax_opcao || 'event_' == substr($this->NM_ajax_opcao, 0, 6) || (isset($this->wizard_action) && 'change_step' == $this->wizard_action))
 {
  if (isset($this->wizard_action) && 'change_step' == $this->wizard_action) {
   $sErrorIndex = 'geral_recherche_fiche_ps_mob';
  } elseif ('submit_form' == $this->NM_ajax_opcao) {
   $sErrorIndex = 'geral_recherche_fiche_ps_mob';
  } else {
   $sErrorIndex = substr(substr($this->NM_ajax_opcao, 0, strrpos($this->NM_ajax_opcao, '_')), 6);
  }
  $this->NM_ajax_info['errList'][$sErrorIndex][] = 'Error while accessing database (groups of user)';
 }
;
	}
	else
	{
	   while(!$this->rs->EOF)
		{
			$_groups[] = $this->rs->fields[0];
			$this->rs->MoveNext();
		}
		$this->rs->Close();
	}


	return $_groups;
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function get_code_facility_of_group($group){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  

	$check_sql = "SELECT structure"
	   . " FROM public.sec_groups"
	   . " WHERE group_id = '" . $group . "'";
	 
      $nm_select = $check_sql; 
      $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nm_select; 
      $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
      $this->rs = array();
      if ($SCrx = $this->Db->Execute($nm_select)) 
      { 
          $SCy = 0; 
          $nm_count = $SCrx->FieldCount();
          while (!$SCrx->EOF)
          { 
                 for ($SCx = 0; $SCx < $nm_count; $SCx++)
                 { 
                      $this->rs[$SCy] [$SCx] = $SCrx->fields[$SCx];
                 }
                 $SCy++; 
                 $SCrx->MoveNext();
          } 
          $SCrx->Close();
      } 
      elseif (isset($GLOBALS["NM_ERRO_IBASE"]) && $GLOBALS["NM_ERRO_IBASE"] != 1)  
      { 
          $this->rs = false;
          $this->rs_erro = $this->Db->ErrorMsg();
      } 


	$inst = '';

	if (isset($this->rs[0][0]))     // Row found
	{
		$inst = $this->rs[0][0];

	}

	return $inst;
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function get_name_of_facility($facilitycode){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  

	$check_sql = "SELECT nom_structure"
	   . " FROM public.structures_sante"
	   . " WHERE code_structure = '" . $facilitycode . "'";
	 
      $nm_select = $check_sql; 
      $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nm_select; 
      $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
      $this->rs = array();
      if ($SCrx = $this->Db->Execute($nm_select)) 
      { 
          $SCy = 0; 
          $nm_count = $SCrx->FieldCount();
          while (!$SCrx->EOF)
          { 
                 for ($SCx = 0; $SCx < $nm_count; $SCx++)
                 { 
                      $this->rs[$SCy] [$SCx] = $SCrx->fields[$SCx];
                 }
                 $SCy++; 
                 $SCrx->MoveNext();
          } 
          $SCrx->Close();
      } 
      elseif (isset($GLOBALS["NM_ERRO_IBASE"]) && $GLOBALS["NM_ERRO_IBASE"] != 1)  
      { 
          $this->rs = false;
          $this->rs_erro = $this->Db->ErrorMsg();
      } 


	$inst = '';

	if (isset($this->rs[0][0]))     // Row found
	{
		$inst = $this->rs[0][0];

	}


	return $inst;
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function get_type_of_facility($facilitycode){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  

	$check_sql = "SELECT type_structure"
	   . " FROM public.structures_sante"
	   . " WHERE code_structure = '" . $facilitycode . "'";
	 
      $nm_select = $check_sql; 
      $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nm_select; 
      $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
      $this->rs = array();
      if ($SCrx = $this->Db->Execute($nm_select)) 
      { 
          $SCy = 0; 
          $nm_count = $SCrx->FieldCount();
          while (!$SCrx->EOF)
          { 
                 for ($SCx = 0; $SCx < $nm_count; $SCx++)
                 { 
                      $this->rs[$SCy] [$SCx] = $SCrx->fields[$SCx];
                 }
                 $SCy++; 
                 $SCrx->MoveNext();
          } 
          $SCrx->Close();
      } 
      elseif (isset($GLOBALS["NM_ERRO_IBASE"]) && $GLOBALS["NM_ERRO_IBASE"] != 1)  
      { 
          $this->rs = false;
          $this->rs_erro = $this->Db->ErrorMsg();
      } 


	$inst = '';

	if (isset($this->rs[0][0]))     // Row found
	{
		$inst = $this->rs[0][0];

	}


	return $inst;
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function is_facility_contain_labo($facilitycode){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  

	$check_sql = "SELECT *"
	   . " FROM public.structures_sante"
	   . " WHERE code_structure = '" . $facilitycode . "' and role_labo='O'";
		
	 
      $nm_select = $check_sql; 
      $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nm_select; 
      $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
      if ($this->dataset = $this->Db->Execute($nm_select)) 
      { }
      elseif (isset($GLOBALS["NM_ERRO_IBASE"]) && $GLOBALS["NM_ERRO_IBASE"] != 1)  
      { 
          $this->dataset = false;
          $this->dataset_erro = $this->Db->ErrorMsg();
      } 


	if (false == $this->dataset )
	{
		return false;
	}
	elseif ($this->dataset->EOF)
	{
		return false;
	}
	else
	{
		return true;
	}
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function get_wilaya_of_group($group){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  

	$check_sql = "SELECT wilaya_structure"
	   . " FROM public.structures_sante"
	   . " WHERE code_structure in (select structure from sec_groups where group_id = '" . $group . "')";
	 
      $nm_select = $check_sql; 
      $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nm_select; 
      $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
      if ($this->rs = $this->Db->Execute($nm_select)) 
      { }
      elseif (isset($GLOBALS["NM_ERRO_IBASE"]) && $GLOBALS["NM_ERRO_IBASE"] != 1)  
      { 
          $this->rs = false;
          $this->rs_erro = $this->Db->ErrorMsg();
      } 


	$_wils = array();

	if (false == $this->rs)     // Error while accessing database
	{
		
 if (!isset($this->Campos_Mens_erro)){$this->Campos_Mens_erro = "";}
 if (!empty($this->Campos_Mens_erro)){$this->Campos_Mens_erro .= "<br>";}$this->Campos_Mens_erro .= 'Error while accessing database (wilayas of groups)';
 if ('submit_form' == $this->NM_ajax_opcao || 'event_' == substr($this->NM_ajax_opcao, 0, 6) || (isset($this->wizard_action) && 'change_step' == $this->wizard_action))
 {
  if (isset($this->wizard_action) && 'change_step' == $this->wizard_action) {
   $sErrorIndex = 'geral_recherche_fiche_ps_mob';
  } elseif ('submit_form' == $this->NM_ajax_opcao) {
   $sErrorIndex = 'geral_recherche_fiche_ps_mob';
  } else {
   $sErrorIndex = substr(substr($this->NM_ajax_opcao, 0, strrpos($this->NM_ajax_opcao, '_')), 6);
  }
  $this->NM_ajax_info['errList'][$sErrorIndex][] = 'Error while accessing database (wilayas of groups)';
 }
;
	}
	else
	{
	   while(!$this->rs->EOF)
		{
			$_wils[] = $this->rs->fields[0];
			$this->rs->MoveNext();
		}
		$this->rs->Close();
	}


	return $_wils;
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function get_wilayas_of_group($groupcode){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  

		$check_sql = "SELECT wilaya_fk"
		   . " FROM public.sec_groups_wilayas"
		   . " WHERE group_fk = '" . $groupcode . "'";
		 
      $nm_select = $check_sql; 
      $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nm_select; 
      $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
      if ($this->rs = $this->Db->Execute($nm_select)) 
      { }
      elseif (isset($GLOBALS["NM_ERRO_IBASE"]) && $GLOBALS["NM_ERRO_IBASE"] != 1)  
      { 
          $this->rs = false;
          $this->rs_erro = $this->Db->ErrorMsg();
      } 


		$_wils = array();

		if (false == $this->rs)     // Error while accessing database
		{
			
 if (!isset($this->Campos_Mens_erro)){$this->Campos_Mens_erro = "";}
 if (!empty($this->Campos_Mens_erro)){$this->Campos_Mens_erro .= "<br>";}$this->Campos_Mens_erro .= 'Error while accessing database (wilayas of groups)';
 if ('submit_form' == $this->NM_ajax_opcao || 'event_' == substr($this->NM_ajax_opcao, 0, 6) || (isset($this->wizard_action) && 'change_step' == $this->wizard_action))
 {
  if (isset($this->wizard_action) && 'change_step' == $this->wizard_action) {
   $sErrorIndex = 'geral_recherche_fiche_ps_mob';
  } elseif ('submit_form' == $this->NM_ajax_opcao) {
   $sErrorIndex = 'geral_recherche_fiche_ps_mob';
  } else {
   $sErrorIndex = substr(substr($this->NM_ajax_opcao, 0, strrpos($this->NM_ajax_opcao, '_')), 6);
  }
  $this->NM_ajax_info['errList'][$sErrorIndex][] = 'Error while accessing database (wilayas of groups)';
 }
;
		}
		else
		{
		   while(!$this->rs->EOF)
			{
				$_wils[] = $this->rs->fields[0];
				$this->rs->MoveNext();
			}
			$this->rs->Close();
		}


		return $_wils;
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function get_communes_of_epsp($epsp_code){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  

	$check_sql = "SELECT code_commune"
	   . " FROM public.commune"
	   . " WHERE code_epsp = '" . $epsp_code . "'";
	 
      $nm_select = $check_sql; 
      $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nm_select; 
      $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
      if ($this->rs = $this->Db->Execute($nm_select)) 
      { }
      elseif (isset($GLOBALS["NM_ERRO_IBASE"]) && $GLOBALS["NM_ERRO_IBASE"] != 1)  
      { 
          $this->rs = false;
          $this->rs_erro = $this->Db->ErrorMsg();
      } 


	$_coms = array();

	if (false == $this->rs)     // Error while accessing database
	{
		
 if (!isset($this->Campos_Mens_erro)){$this->Campos_Mens_erro = "";}
 if (!empty($this->Campos_Mens_erro)){$this->Campos_Mens_erro .= "<br>";}$this->Campos_Mens_erro .= 'Error while accessing database (communes of groups)';
 if ('submit_form' == $this->NM_ajax_opcao || 'event_' == substr($this->NM_ajax_opcao, 0, 6) || (isset($this->wizard_action) && 'change_step' == $this->wizard_action))
 {
  if (isset($this->wizard_action) && 'change_step' == $this->wizard_action) {
   $sErrorIndex = 'geral_recherche_fiche_ps_mob';
  } elseif ('submit_form' == $this->NM_ajax_opcao) {
   $sErrorIndex = 'geral_recherche_fiche_ps_mob';
  } else {
   $sErrorIndex = substr(substr($this->NM_ajax_opcao, 0, strrpos($this->NM_ajax_opcao, '_')), 6);
  }
  $this->NM_ajax_info['errList'][$sErrorIndex][] = 'Error while accessing database (communes of groups)';
 }
;
	}
	else
	{
	   while(!$this->rs->EOF)
		{
			$_coms[] = $this->rs->fields[0];
			$this->rs->MoveNext();
		}
		$this->rs->Close();
	}


	return $_coms;
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function get_semep_users_of_facility($facility){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  
	
	$check_sql = "SELECT login from sec_users where group_id in (select group_id from sec_groups where structure = '$facility' and role='S')";
	   
	 
      $nm_select = $check_sql; 
      $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nm_select; 
      $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
      if ($this->rs = $this->Db->Execute($nm_select)) 
      { }
      elseif (isset($GLOBALS["NM_ERRO_IBASE"]) && $GLOBALS["NM_ERRO_IBASE"] != 1)  
      { 
          $this->rs = false;
          $this->rs_erro = $this->Db->ErrorMsg();
      } 


	$_users = array();

	if (false == $this->rs)     // Error while accessing database
	{
		
 if (!isset($this->Campos_Mens_erro)){$this->Campos_Mens_erro = "";}
 if (!empty($this->Campos_Mens_erro)){$this->Campos_Mens_erro .= "<br>";}$this->Campos_Mens_erro .= 'Error while accessing database (communes of groups)';
 if ('submit_form' == $this->NM_ajax_opcao || 'event_' == substr($this->NM_ajax_opcao, 0, 6) || (isset($this->wizard_action) && 'change_step' == $this->wizard_action))
 {
  if (isset($this->wizard_action) && 'change_step' == $this->wizard_action) {
   $sErrorIndex = 'geral_recherche_fiche_ps_mob';
  } elseif ('submit_form' == $this->NM_ajax_opcao) {
   $sErrorIndex = 'geral_recherche_fiche_ps_mob';
  } else {
   $sErrorIndex = substr(substr($this->NM_ajax_opcao, 0, strrpos($this->NM_ajax_opcao, '_')), 6);
  }
  $this->NM_ajax_info['errList'][$sErrorIndex][] = 'Error while accessing database (communes of groups)';
 }
;
	}
	else
	{
	   while(!$this->rs->EOF)
		{
			$_users[] = $this->rs->fields[0];
			$this->rs->MoveNext();
		}
		$this->rs->Close();
	}


	return $_users;
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function get_rap_users_of_facility($facility){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  
	
	$check_sql = "SELECT login from sec_users where group_id in (select group_id from sec_groups where structure = '$facility' and role='R')";
	   
	 
      $nm_select = $check_sql; 
      $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nm_select; 
      $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
      if ($this->rs = $this->Db->Execute($nm_select)) 
      { }
      elseif (isset($GLOBALS["NM_ERRO_IBASE"]) && $GLOBALS["NM_ERRO_IBASE"] != 1)  
      { 
          $this->rs = false;
          $this->rs_erro = $this->Db->ErrorMsg();
      } 


	$_users = array();

	if (false == $this->rs)     // Error while accessing database
	{
		
 if (!isset($this->Campos_Mens_erro)){$this->Campos_Mens_erro = "";}
 if (!empty($this->Campos_Mens_erro)){$this->Campos_Mens_erro .= "<br>";}$this->Campos_Mens_erro .= 'Error while accessing database (communes of groups)';
 if ('submit_form' == $this->NM_ajax_opcao || 'event_' == substr($this->NM_ajax_opcao, 0, 6) || (isset($this->wizard_action) && 'change_step' == $this->wizard_action))
 {
  if (isset($this->wizard_action) && 'change_step' == $this->wizard_action) {
   $sErrorIndex = 'geral_recherche_fiche_ps_mob';
  } elseif ('submit_form' == $this->NM_ajax_opcao) {
   $sErrorIndex = 'geral_recherche_fiche_ps_mob';
  } else {
   $sErrorIndex = substr(substr($this->NM_ajax_opcao, 0, strrpos($this->NM_ajax_opcao, '_')), 6);
  }
  $this->NM_ajax_info['errList'][$sErrorIndex][] = 'Error while accessing database (communes of groups)';
 }
;
	}
	else
	{
	   while(!$this->rs->EOF)
		{
			$_users[] = $this->rs->fields[0];
			$this->rs->MoveNext();
		}
		$this->rs->Close();
	}


	return $_users;
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function is_semep_of_epsp($facilitycode){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  

	$check_sql = "SELECT code_commune"
	   . " FROM public.commune"
	   . " WHERE code_epsp = '" . $facilitycode . "'";
		
	 
      $nm_select = $check_sql; 
      $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nm_select; 
      $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
      if ($this->dataset = $this->Db->Execute($nm_select)) 
      { }
      elseif (isset($GLOBALS["NM_ERRO_IBASE"]) && $GLOBALS["NM_ERRO_IBASE"] != 1)  
      { 
          $this->dataset = false;
          $this->dataset_erro = $this->Db->ErrorMsg();
      } 


	if (false == $this->dataset )
	{
		return false;
	}
	elseif ($this->dataset->EOF)
	{
		return false;
	}
	else
	{
		return true;
	}
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function get_communes_of_group($groupcode){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  

	$check_sql = "SELECT commune_structure"
	   . " FROM public.structures_sante"
	   . " WHERE code_structure in (select structure from sec_groups where group_id = '" . $groupcode . "')";
	 
      $nm_select = $check_sql; 
      $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nm_select; 
      $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
      if ($this->rs = $this->Db->Execute($nm_select)) 
      { }
      elseif (isset($GLOBALS["NM_ERRO_IBASE"]) && $GLOBALS["NM_ERRO_IBASE"] != 1)  
      { 
          $this->rs = false;
          $this->rs_erro = $this->Db->ErrorMsg();
      } 


	$_coms = array();

	if (false == $this->rs)     // Error while accessing database
	{
		
 if (!isset($this->Campos_Mens_erro)){$this->Campos_Mens_erro = "";}
 if (!empty($this->Campos_Mens_erro)){$this->Campos_Mens_erro .= "<br>";}$this->Campos_Mens_erro .= 'Error while accessing database (communes of groups)';
 if ('submit_form' == $this->NM_ajax_opcao || 'event_' == substr($this->NM_ajax_opcao, 0, 6) || (isset($this->wizard_action) && 'change_step' == $this->wizard_action))
 {
  if (isset($this->wizard_action) && 'change_step' == $this->wizard_action) {
   $sErrorIndex = 'geral_recherche_fiche_ps_mob';
  } elseif ('submit_form' == $this->NM_ajax_opcao) {
   $sErrorIndex = 'geral_recherche_fiche_ps_mob';
  } else {
   $sErrorIndex = substr(substr($this->NM_ajax_opcao, 0, strrpos($this->NM_ajax_opcao, '_')), 6);
  }
  $this->NM_ajax_info['errList'][$sErrorIndex][] = 'Error while accessing database (communes of groups)';
 }
;
	}
	else
	{
	   while(!$this->rs->EOF)
		{
			$_coms[] = $this->rs->fields[0];
			$this->rs->MoveNext();
		}
		$this->rs->Close();
	}


	return $_coms;
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function get_nom_wilaya($wil){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  

	$check_sql = "SELECT nom_wilaya"
	   . " FROM wilaya"
	   . " WHERE code_wilaya = '" . $wil . "'";
	 
      $nm_select = $check_sql; 
      $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nm_select; 
      $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
      $this->rs = array();
      if ($SCrx = $this->Db->Execute($nm_select)) 
      { 
          $SCy = 0; 
          $nm_count = $SCrx->FieldCount();
          while (!$SCrx->EOF)
          { 
                 for ($SCx = 0; $SCx < $nm_count; $SCx++)
                 { 
                      $this->rs[$SCy] [$SCx] = $SCrx->fields[$SCx];
                 }
                 $SCy++; 
                 $SCrx->MoveNext();
          } 
          $SCrx->Close();
      } 
      elseif (isset($GLOBALS["NM_ERRO_IBASE"]) && $GLOBALS["NM_ERRO_IBASE"] != 1)  
      { 
          $this->rs = false;
          $this->rs_erro = $this->Db->ErrorMsg();
      } 


	$nwil = '';

	if (isset($this->rs[0][0]))     // Row found
	{
		$nwil = $this->rs[0][0];

	}


	return $nwil;
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function get_nom_commune($com){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  

	$check_sql = "SELECT nom_commune"
	   . " FROM commune"
	   . " WHERE code_commune = '" . $com . "'";
	 
      $nm_select = $check_sql; 
      $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nm_select; 
      $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
      $this->rs = array();
      if ($SCrx = $this->Db->Execute($nm_select)) 
      { 
          $SCy = 0; 
          $nm_count = $SCrx->FieldCount();
          while (!$SCrx->EOF)
          { 
                 for ($SCx = 0; $SCx < $nm_count; $SCx++)
                 { 
                      $this->rs[$SCy] [$SCx] = $SCrx->fields[$SCx];
                 }
                 $SCy++; 
                 $SCrx->MoveNext();
          } 
          $SCrx->Close();
      } 
      elseif (isset($GLOBALS["NM_ERRO_IBASE"]) && $GLOBALS["NM_ERRO_IBASE"] != 1)  
      { 
          $this->rs = false;
          $this->rs_erro = $this->Db->ErrorMsg();
      } 


	$ncom = '';

	if (isset($this->rs[0][0]))     // Row found
	{
		$ncom = $this->rs[0][0];

	}


	return $ncom;
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function get_photo_of_user($user){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  


			$check_sql = "SELECT encode(picture, 'base64')"
			   . ' FROM public.sec_users'
			   . " WHERE login = '" . $user. "'";

			 
      $nm_select = $check_sql; 
      $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nm_select; 
      $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
      if ($this->rsp = $this->Db->Execute($nm_select)) 
      { }
      elseif (isset($GLOBALS["NM_ERRO_IBASE"]) && $GLOBALS["NM_ERRO_IBASE"] != 1)  
      { 
          $this->rsp = false;
          $this->rsp_erro = $this->Db->ErrorMsg();
      } 

			
			$_photo = array();
			if (false === $this->rsp )     // Error while accessing database
			{
				
 if (!isset($this->Campos_Mens_erro)){$this->Campos_Mens_erro = "";}
 if (!empty($this->Campos_Mens_erro)){$this->Campos_Mens_erro .= "<br>";}$this->Campos_Mens_erro .= 'Error while accessing database (photo of user)';
 if ('submit_form' == $this->NM_ajax_opcao || 'event_' == substr($this->NM_ajax_opcao, 0, 6) || (isset($this->wizard_action) && 'change_step' == $this->wizard_action))
 {
  if (isset($this->wizard_action) && 'change_step' == $this->wizard_action) {
   $sErrorIndex = 'geral_recherche_fiche_ps_mob';
  } elseif ('submit_form' == $this->NM_ajax_opcao) {
   $sErrorIndex = 'geral_recherche_fiche_ps_mob';
  } else {
   $sErrorIndex = substr(substr($this->NM_ajax_opcao, 0, strrpos($this->NM_ajax_opcao, '_')), 6);
  }
  $this->NM_ajax_info['errList'][$sErrorIndex][] = 'Error while accessing database (photo of user)';
 }
;
			}
			else
			{
			   while(!$this->rsp->EOF)
				{
					$_photo[] = $this->rsp->fields[0];
					$this->rsp->MoveNext();
				}
				$this->rsp->Close();
			}




			if (!empty($_photo[0])){
				return '<img width="50" height="50" style="border-radius: 50%; border: 2px solid #ccc; padding:1px;margin:10px;" src="data:image/png;base64,'.$_photo[0].'" />';
			}
			else{
				return '<img width="50" height="50" style="border-radius: 50%; border: 2px solid #ccc; padding:1px;margin:10px;" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADwAAAA8CAYAAAA6/NlyAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAqESURBVGhD1ZprjBVnGcf/M+e2twPLLrvLtrSABUoBpQkGStFWadIq1tYajcYvjTHWlCYmfjDR9IN+Nq0fjMaPNRqTxsaSNPFDFdtCQRAoYIF2YYFdYK+wZ9mzu+d+zozP87zvOTNnzv1CUn5n57zP887MO89/3uvMWePZ1w/aaBHbtpEvxNAW5ymj8KXzivfnU8O29KFOvvKtgm9wyh85hjb5Uylju45VO9UOKYs3+piS0wKqIMVnXSzTkmBVkOJeEMv5TQtWBSnuFbH8aUqwKkhxL4nltGHBqiDFvSaW8xsSrApS3ItimboFq4IU95xYlSP765qHVUGKpsRmUsDcDdjRWSCxBDubpj0kLRACOnuAnj7YK4dghLrpbPrky5E/lTJNi9X7yagtWBWkaFgsCbXHzsKeHAGsnORVJdwPe3gT7IF15PDVqBxVFJXZuli2qwpWBTlICHIyIYmyCwXm7XQc1sxV2BMkNLEo+Q3RGYa1cRfs8Gpx2yWW7Yp9WBXkUK9Ye+oycv95C/boyebEMtTszQvvA5GbVGb7xLJdVrAqyKF+sZdgffohkMtKXkuQUN+Vk7CTy851dAxyLd70tTlfbEm1TxsZRTanJYJVQQ51N2MKzLp8Qvy2QTcuM3oa2XSSLyJZKj710RnKllT7cqzO07ZKPdOSKsyhbrGEdfNie2rWQ2csgvnp68iQaBWfOyblq1T7sk/naTt/PKcFweyobEUjYuXc2zfEdrOmP4ztn1ujvebguTuYXERkdgLpZMIVE8dLtqTal306T9tFMdImgsWRbEWjYqVmXQOUzzRx4IU9eOOX38VvDuzHN/c+ovc0RygTpy5t4c7tSRFNF+UIdUpwKvHoPG27Y8zbpjhiKhoWy+R4IeHw8guP4bkvbYVhGDBpe+Xbj+PVF5/CYC8tMpogkKWFC8HXi85NI5WMs6PDy8dLm8t2x+jYNBBuevp7vxaPaEaswSktKuwbF8Tfsm4QP/3OXrHdrBvqxbN7t2JwVQ+WEinML7qap4vujiB2b31A7GiMBivCNkwsd/WJzaTiMfgCAfj9ASc2SvO2O0bH5umNFh77X3tbcpoVyx9kM7A+/Kvk/fwHT+KpnRvFrkY8mcboRATTkSUkUhmEAn7cP7AC2zYMwe8zEaP9L792ELfuLCPrC2JqYLM+06Gntx+hzi4OqBCnO0bHVmIZ6cMtiWXf9FEGNV/TwK5HVO3UootqcsfGYXxt92a88MQ27N/zsPgsluGa3v/YFrErsbwQodp25ml3jI7tiGUoxBbFEvJNooeouYa76IGgTWx6QC0tqUYqshy9g2RBtIrRsYvF8sAng5byCl/6BLftpCVixSfoyWe4f4XktYu+cKeklkEtqArxpSiJjontxFsqlvep9iP5joBi20krid26Cnj9x/sw2NfcKFyJzo4ANq1djd8deAYrO/w6tzyJ5UUkYktiVxLLmCpfC5BU2y5RTMWapXTXkIlt6wfx/X07ZF+74H786ov7sP3BfuxcG9a5lUnGlqV5U1Aqg3CLZaiGtQCPGHdaTSx90UCg8nll1U54PFjTp8r00WhTDzxlFZq3RyyjVloeMe60llj2p5bVvrvJ+Lyak+shnUhIbXvFWrReMFsVy/f9zG1aeHD+XWJmKY2rEVpdNUA6mUSKhOdhsRwv9WFHjDutVyznzsQsHJ1s/5NSnr98NANLhdEQmZQSnRfLqCbtEsU0IjZ/zh/+l8b1RR4d28v7V+6I4GZh0VzbeQrzcE2x8q0EesXysZGkhZcOxTFPabs4NHoHrxy8jGwz1esim06TcPUAUlTDVcWyTVs5sfmjOK52Nu33SHC7yIsu1HCrYtVhFv59I6P8FolnLPxzdF577YFFSw23SyxzMZLFWLSOd9A1+MenEcTTrZfjhdYMOnAtpBWxci75b47UP2eWI0eF/OnUtPbaS8k8rC3Ja1SsMix8fLu1fvzOxQjG5p05tJ0UzcPaYkf8ZsQy3P9a4eykegi4GxRGaRWyqBC/WbHsJ7I67zOI6yWeqJCAWxHLn3SOF+2S1RSZbPsHqzzUhxlRIQG3KpbWcXjyoSHYZvXn12o8s+tRBKz2TG9eqEmLCgm4VbFGMoaOy8fw/BfWwwyqtxXN8NVdO7EdUfSkmvwxrgoyaLUsljZfZAKdI0dgxhbg9/thrHmUJngutTGMFffB6FmDkN/EwOIkVi9NUzNU12oH0odbrVnfwjRC42cLvy0tLi6qwNd9GfDX/1LP6HsIxoN7pdxoNCp54eQCBpamxG4H8h5Bwq5bbA6+dBzBxVn03B5F3/XTWDmlXsLnmZyclNQID8Pc/HUSspEcmRDK09ELY8NXYNz/RTkuEokg6XrCCWfjeCQ1jQcy8+jPLaPL4iWijqdBZOFRS6xJArtnL6P3+imsHj2CvrETWDl9EV13JhBILdM4Vdzkrl27pi3CFyIhO2E+/A0YA1uoMNdg1jMEY/0TMDc9Tc14SGd6zic4vgDd6FW5OO7PLGBj+ha2JSexOTUjNyFs1b+yc72mLS/WR4J6x0+SuBsIJKIwyvyvRqEMzcjIiLZcBLpgD3weqf69iC3aSIU2kNgnpRVQtapjNN7zveUzfEaHnZWbsCE9R6l6j1UL1c4qiOXfjMITH8PMVZ8ivAHNzc1hZqb4oX3h5gL+9sM38fbP/oV3fp/B27+6hL//5C1cerf05pw/f15binKCvaylmg/RDaiFGqXLiOWLdFCT9adr37lyAZ07d05bfN8sHP/jMeQyxa0jtZTCR38+jVsjt3QOkEwky7aQWqL5F5RhEl0L9fDAeMTyD9Fd8+Pi16JcMGfOnNEWcOW9UcyPlX+2tS0bp944KSlz/sJ5ZLPNPXysoL7cWWPBopt0sViGR2FT/oGsNmVr+OxZ5HKqRhduLCA8HKbxqnikZn94x31Y//h6ejhXIk+fPi1pCTVqOA+P4tWQ0d0rlufZjmhrz6NLy8v45OInYu/60W4899tvYfdLe8TPM7hlEPt+8RS2Pb8dgQ71W++JE6X/GMM/rHvGtYr00iBWbcqiUbpUrEE1G4zX/z4pFAohGAzKCsvN8ePHtaVY9eAqbSksz8u58fFx3Lrl9Gcur7u7Gz09PSS6yjzugsWuyFV+lpZS3GKZYGyOHbHrgWuA52Jv3zvx3+LaSkaLA4lOqNVUHu8N4vISiQQymYwTYx1wX66Eax52ajoYa+zlGQdVbqCZnp7G1atXtUeCF4sDSS0lkaQtz7Gjx7TlwDeSV12NDGThXLJiD9CDlqtZNyHY25TdHD16VFtcw547T5fL1/LU1BSujRWvsNxUu4YXHywarcsPuNTkHbH84ZWVaTU2LVQV/GEVwUR0Qs2d7hvjxefzqYGrAbot9eLdS6EPy4dSXj42SjXBE5MT1KyviO3tw0xe8AcfHJa0HIFAQFv101NJsFssE0g2/tDNd79aUIcPH5HU24cZbtI3b97EWIXmzGU30pzz8BNVOUqelpoRzASrCD5y5Ihco2yTnozSDalSuyS20ebMcD8OlllbFz0tgfquP1MaVD2Y1M/8tJVjdnZW1sfx+dLfeLnWD717SHulBGh+b5bSWgb+D9iXSRNe3sfQAAAAAElFTkSuQmCC" />';
			}
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function random_string($_length){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  
	
	
    $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ?#!.;@],_';
    $charactersLength = strlen($characters);
    $randomString = '';
    for ($i = 0; $i < $_length; $i++) {
        $randomString .= $characters[random_int(0, $charactersLength - 1)];
    }
    return $randomString;
	
	

$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function delete_from_all_groups($_login){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  
	
	/**
	 * Delete a record on another table
	 */

	$delete_table  = 'sec_users_groups';      // Table name
	$delete_where  = "login = '".$_login."'"; // Where clause

	$delete_sql = 'DELETE FROM ' . $delete_table
		. ' WHERE '      . $delete_where;
	
     $nm_select = $delete_sql; 
         $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nm_select;
      $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
         $rf = $this->Db->Execute($nm_select);
         if ($rf === false)
         {
             $this->Erro->mensagem (__FILE__, __LINE__, "banco", $this->Ini->Nm_lang['lang_errm_dber'], $this->Db->ErrorMsg());
             $this->NM_rollback_db(); 
             if ($this->NM_ajax_flag)
             {
                recherche_fiche_ps_mob_pack_ajax_response();
             }
             exit;
         }
         $rf->Close();
      
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function add_user_to_group($user_login, $group_login){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  	
	
	
	/**
	 * Insert a record on another table
	 */

	$insert_table  = 'sec_users_groups';      // Table name
	$insert_fields = array(   // Field list, add as many as needed
		 'login' => "'".$user_login."'",
		 'group_id' => "'".$group_login."'",
	 );



	$insert_sql = 'INSERT INTO ' . $insert_table
		. ' ('   . implode(', ', array_keys($insert_fields))   . ')'
		. ' VALUES ('    . implode(', ', array_values($insert_fields)) . ')';



	
     $nm_select = $insert_sql; 
         $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nm_select;
      $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
         $rf = $this->Db->Execute($nm_select);
         if ($rf === false)
         {
             $this->Erro->mensagem (__FILE__, __LINE__, "banco", $this->Ini->Nm_lang['lang_errm_dber'], $this->Db->ErrorMsg());
             $this->NM_rollback_db(); 
             if ($this->NM_ajax_flag)
             {
                recherche_fiche_ps_mob_pack_ajax_response();
             }
             exit;
         }
         $rf->Close();
      
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function delete_links($_group_id){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  

	$sql = "DELETE FROM sec_groups_apps  where  group_id = '". $_group_id."'";
	
     $nm_select = $sql; 
         $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nm_select;
      $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
         $rf = $this->Db->Execute($nm_select);
         if ($rf === false)
         {
             $this->Erro->mensagem (__FILE__, __LINE__, "banco", $this->Ini->Nm_lang['lang_errm_dber'], $this->Db->ErrorMsg());
             $this->NM_rollback_db(); 
             if ($this->NM_ajax_flag)
             {
                recherche_fiche_ps_mob_pack_ajax_response();
             }
             exit;
         }
         $rf->Close();
      
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function delete_rights($_group_id){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  
	
	$sql = "UPDATE sec_groups_apps set priv_access='N', priv_insert='N', priv_delete='N', priv_update='N', "
		   . "priv_export='N', priv_print='N' " . " where group_id = " . $_group_id;

	
     $nm_select = $sql; 
         $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nm_select;
      $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
         $rf = $this->Db->Execute($nm_select);
         if ($rf === false)
         {
             $this->Erro->mensagem (__FILE__, __LINE__, "banco", $this->Ini->Nm_lang['lang_errm_dber'], $this->Db->ErrorMsg());
             $this->NM_rollback_db(); 
             if ($this->NM_ajax_flag)
             {
                recherche_fiche_ps_mob_pack_ajax_response();
             }
             exit;
         }
         $rf->Close();
      
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function delete_scope($_table, $_group_id){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  
	
	$delete_table  = $_table;      // Table name
	$delete_where  = "group_fk = $_group_id"; // Where clause

	$delete_sql = 'DELETE FROM ' . $delete_table
		. ' WHERE '      . $delete_where;
	
     $nm_select = $delete_sql; 
         $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nm_select;
      $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
         $rf = $this->Db->Execute($nm_select);
         if ($rf === false)
         {
             $this->Erro->mensagem (__FILE__, __LINE__, "banco", $this->Ini->Nm_lang['lang_errm_dber'], $this->Db->ErrorMsg());
             $this->NM_rollback_db(); 
             if ($this->NM_ajax_flag)
             {
                recherche_fiche_ps_mob_pack_ajax_response();
             }
             exit;
         }
         $rf->Close();
      
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function set_rights($_group_id){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  

	$sql = "INSERT INTO sec_groups_apps(group_id, app_name)
			 SELECT '". $_group_id."', app_name FROM sec_apps ";
	
     $nm_select = $sql; 
         $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nm_select;
      $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
         $rf = $this->Db->Execute($nm_select);
         if ($rf === false)
         {
             $this->Erro->mensagem (__FILE__, __LINE__, "banco", $this->Ini->Nm_lang['lang_errm_dber'], $this->Db->ErrorMsg());
             $this->NM_rollback_db(); 
             if ($this->NM_ajax_flag)
             {
                recherche_fiche_ps_mob_pack_ajax_response();
             }
             exit;
         }
         $rf->Close();
      
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function set_rights_from_template($_group_id, $_template, $_reset){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  

	$sql = '';

	if ($_reset=='O'){


		$this->delete_links($_group_id);

		$sql =    "INSERT INTO sec_groups_apps(group_id, app_name, priv_access, priv_insert, priv_delete, priv_update, "
		   .  "priv_export, priv_print) "
		   .  " SELECT '". $_group_id."', app_name, priv_access, priv_insert, priv_delete, priv_update, priv_export, priv_print"
		   .  " FROM sec_groups_apps where group_id = '".$_template."'";


	}
	else{

		$sql =    "INSERT INTO sec_groups_apps(group_id, app_name, priv_access, priv_insert, priv_delete, priv_update, "
		   .  "priv_export, priv_print) "
		   .  " SELECT '". $_group_id."', app_name, priv_access, priv_insert, priv_delete, priv_update, priv_export, priv_print"
		   .  " FROM sec_groups_apps where group_id = '".$_template."'"
		   .  "ON Conflict (group_id, app_name) DO "
		   .  "UPDATE SET priv_access = excluded.priv_access, priv_insert=excluded.priv_insert, priv_delete=excluded.priv_delete, priv_update=excluded.priv_update, priv_export=excluded.priv_export, priv_print=excluded.priv_print WHERE sec_groups_apps.priv_access is distinct from 'Y'";




	}



	
     $nm_select = $sql; 
         $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nm_select;
      $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
         $rf = $this->Db->Execute($nm_select);
         if ($rf === false)
         {
             $this->Erro->mensagem (__FILE__, __LINE__, "banco", $this->Ini->Nm_lang['lang_errm_dber'], $this->Db->ErrorMsg());
             $this->NM_rollback_db(); 
             if ($this->NM_ajax_flag)
             {
                recherche_fiche_ps_mob_pack_ajax_response();
             }
             exit;
         }
         $rf->Close();
      
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
function users_exists($_group_id){
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  

	/**
	 * Check for an existing record
	 */

	$check_table = 'sec_users_groups';    // Table name
	$check_where = "group_id = $_group_id"; // Where clause

	$check_sql = 'SELECT *'
	   . ' FROM '  . $check_table
	   . ' WHERE ' . $check_where;
	 
      $nm_select = $check_sql; 
      $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nm_select; 
      $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
      if ($this->dataset = $this->Db->Execute($nm_select)) 
      { }
      elseif (isset($GLOBALS["NM_ERRO_IBASE"]) && $GLOBALS["NM_ERRO_IBASE"] != 1)  
      { 
          $this->dataset = false;
          $this->dataset_erro = $this->Db->ErrorMsg();
      } 


	if (false == $this->dataset )
	{
		return true;
	}
	elseif ($this->dataset->EOF)
	{
		return false;
	}
	else
	{
		return true;
	}
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off';
}
//
 function nm_gera_html()
 {
    global
           $nm_url_saida, $nmgp_url_saida, $nm_saida_global, $nm_apl_dependente, $glo_subst, $sc_check_excl, $sc_check_incl, $nmgp_num_form, $NM_run_iframe;
     if ($this->Embutida_proc)
     {
         return;
     }
     if ($this->nmgp_form_show == 'off')
     {
         exit;
     }
      if (isset($NM_run_iframe) && $NM_run_iframe == 1)
      {
          $this->nmgp_botoes['exit'] = "off";
      }
     $HTTP_REFERER = (isset($_SERVER['HTTP_REFERER'])) ? $_SERVER['HTTP_REFERER'] : ""; 
     $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
     $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['botoes'] = $this->nmgp_botoes;
     if ($this->nmgp_opcao != "recarga" && $this->nmgp_opcao != "muda_form")
     {
         $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['opc_ant'] = $this->nmgp_opcao;
     }
     else
     {
         $this->nmgp_opcao = $this->nmgp_opc_ant;
     }
     if (!empty($this->Campos_Mens_erro)) 
     {
         $this->Erro->mensagem(__FILE__, __LINE__, "critica", $this->Campos_Mens_erro); 
         $this->Campos_Mens_erro = "";
     }
     if (($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['run_iframe'] == "F" || $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['run_iframe'] == "R") && $this->nm_flag_iframe && empty($this->nm_todas_criticas))
     {
          if (isset($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['run_iframe_ajax']))
          {
              $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['retorno_edit'] = array("edit", "");
          }
          else
          {
              $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['retorno_edit'] .= "&nmgp_opcao=edit";
          }
          if ($this->sc_evento == "insert" && $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['run_iframe'] == "F")
          {
              if (isset($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['run_iframe_ajax']))
              {
                  $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['retorno_edit'] = array("edit", "fim");
              }
              else
              {
                  $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['retorno_edit'] .= "&rec=fim";
              }
          }
          $this->NM_close_db(); 
          $sJsParent = '';
          if ($this->NM_ajax_flag && isset($this->NM_ajax_info['param']['buffer_output']) && $this->NM_ajax_info['param']['buffer_output'])
          {
              if (isset($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['run_iframe_ajax']))
              {
                  $this->NM_ajax_info['ajaxJavascript'][] = array("parent.ajax_navigate", $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['retorno_edit']);
              }
              else
              {
                  $sJsParent .= 'parent';
                  $this->NM_ajax_info['redir']['metodo'] = 'location';
                  $this->NM_ajax_info['redir']['action'] = $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['retorno_edit'];
                  $this->NM_ajax_info['redir']['target'] = $sJsParent;
              }
              recherche_fiche_ps_mob_pack_ajax_response();
              exit;
          }
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
            "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">

         <html><body>
         <script type="text/javascript">
<?php
    
    if (isset($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['run_iframe_ajax']))
    {
        $opc = ($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['run_iframe'] == "F" && $this->sc_evento == "insert") ? "fim" : "";
        echo "parent.ajax_navigate('edit', '" .$opc . "');";
    }
    else
    {
        echo $sJsParent . "parent.location = '" . $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['retorno_edit'] . "';";
    }
?>
         </script>
         </body></html>
<?php
         exit;
     }
      if (isset($_SESSION['scriptcase']['nm_sc_retorno']) && !empty($_SESSION['scriptcase']['nm_sc_retorno']) && $nm_apl_dependente != 1) 
      { 
          $nm_saida_global = $_SESSION['scriptcase']['nm_sc_retorno']; 
      } 
    if (!$this->NM_ajax_flag || !isset($this->nmgp_refresh_fields)) {
    $_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'on';
  

$this->NM_ajax_info['buttonDisplay']['fiche_patient'] = $this->nmgp_botoes["fiche_patient"] = 'off';;

$this->Ini->nm_hidden_blocos[3] = 'off'; $this->NM_ajax_info['blockDisplay']['3'] = 'off';
$_SESSION['scriptcase']['recherche_fiche_ps_mob']['contr_erro'] = 'off'; 
    }
    if (!empty($this->Campos_Mens_erro)) 
    {
        $this->Erro->mensagem(__FILE__, __LINE__, "critica", $this->Campos_Mens_erro); 
    }
    $this->nm_guardar_campos();
    $this->nm_formatar_campos();
        $this->initFormPages();
    include_once("recherche_fiche_ps_mob_form0.php");
        $this->hideFormPages();
 }

        function initFormPages() {
        } // initFormPages

        function hideFormPages() {
        } // hideFormPages

    function form_format_readonly($field, $value)
    {
        $result = $value;

        $this->form_highlight_search($result, $field, $value);

        return $result;
    }

    function form_highlight_search(&$result, $field, $value)
    {
        if ($this->proc_fast_search) {
            $this->form_highlight_search_quicksearch($result, $field, $value);
        }
    }

    function form_highlight_search_quicksearch(&$result, $field, $value)
    {
        $searchOk = false;
        if ('SC_all_Cmp' == $this->nmgp_fast_search && in_array($field, array(""))) {
            $searchOk = true;
        }
        elseif ($field == $this->nmgp_fast_search && in_array($field, array(""))) {
            $searchOk = true;
        }

        if (!$searchOk || '' == $this->nmgp_arg_fast_search) {
            return;
        }

        $htmlIni = '<div class="highlight" style="background-color: #fafaca; display: inline-block">';
        $htmlFim = '</div>';

        if ('qp' == $this->nmgp_cond_fast_search) {
            $keywords = preg_quote($this->nmgp_arg_fast_search, '/');
            $result = preg_replace('/'. $keywords .'/i', $htmlIni . '$0' . $htmlFim, $result);
        } elseif ('eq' == $this->nmgp_cond_fast_search) {
            if (strcasecmp($this->nmgp_arg_fast_search, $value) == 0) {
                $result = $htmlIni. $result .$htmlFim;
            }
        }
    }


    function form_encode_input($string)
    {
        if (isset($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['table_refresh']) && $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['table_refresh'])
        {
            return NM_encode_input(NM_encode_input($string));
        }
        else
        {
            return NM_encode_input($string);
        }
    } // form_encode_input


    function scCsrfGetToken()
    {
        if (!isset($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['csrf_token']))
        {
            $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['csrf_token'] = $this->scCsrfGenerateToken();
        }

        return $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['csrf_token'];
    }

    function scCsrfGenerateToken()
    {
        $aSources = array(
            'abcdefghijklmnopqrstuvwxyz',
            'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
            '1234567890',
            '!@$*()-_[]{},.;:'
        );

        $sRandom = '';

        $aSourcesSizes = array();
        $iSourceSize   = sizeof($aSources) - 1;
        for ($i = 0; $i <= $iSourceSize; $i++)
        {
            $aSourcesSizes[$i] = strlen($aSources[$i]) - 1;
        }

        for ($i = 0; $i < 64; $i++)
        {
            $iSource = $this->scCsrfRandom(0, $iSourceSize);
            $sRandom .= substr($aSources[$iSource], $this->scCsrfRandom(0, $aSourcesSizes[$iSource]), 1);
        }

        return $sRandom;
    }

    function scCsrfRandom($iMin, $iMax)
    {
        return mt_rand($iMin, $iMax);
    }

        function addUrlParam($url, $param, $value) {
                $urlParts  = explode('?', $url);
                $urlParams = isset($urlParts[1]) ? explode('&', $urlParts[1]) : array();
                $objParams = array();
                foreach ($urlParams as $paramInfo) {
                        $paramParts = explode('=', $paramInfo);
                        $objParams[ $paramParts[0] ] = isset($paramParts[1]) ? $paramParts[1] : '';
                }
                $objParams[$param] = $value;
                $urlParams = array();
                foreach ($objParams as $paramName => $paramValue) {
                        $urlParams[] = $paramName . '=' . $paramValue;
                }
                return $urlParts[0] . '?' . implode('&', $urlParams);
        }
 function allowedCharsCharset($charlist)
 {
     if ($_SESSION['scriptcase']['charset'] != 'UTF-8')
     {
         $charlist = NM_conv_charset($charlist, $_SESSION['scriptcase']['charset'], 'UTF-8');
     }
     return str_replace("'", "\'", $charlist);
 }

function sc_file_size($file, $format = false)
{
    if ('' == $file) {
        return '';
    }
    if (!@is_file($file)) {
        return '';
    }
    $fileSize = @filesize($file);
    if ($format) {
        $suffix = '';
        if (1024 >= $fileSize) {
            $fileSize /= 1024;
            $suffix    = ' KB';
        }
        if (1024 >= $fileSize) {
            $fileSize /= 1024;
            $suffix    = ' MB';
        }
        if (1024 >= $fileSize) {
            $fileSize /= 1024;
            $suffix    = ' GB';
        }
        $fileSize = $fileSize . $suffix;
    }
    return $fileSize;
}


 function new_date_format($type, $field)
 {
     $new_date_format_out = '';

     if ('DT' == $type)
     {
         $date_format  = $this->field_config[$field]['date_format'];
         $date_sep     = $this->field_config[$field]['date_sep'];
         $date_display = $this->field_config[$field]['date_display'];
         $time_format  = '';
         $time_sep     = '';
         $time_display = '';
     }
     elseif ('DH' == $type)
     {
         $date_format  = false !== strpos($this->field_config[$field]['date_format'] , ';') ? substr($this->field_config[$field]['date_format'] , 0, strpos($this->field_config[$field]['date_format'] , ';')) : $this->field_config[$field]['date_format'];
         $date_sep     = $this->field_config[$field]['date_sep'];
         $date_display = false !== strpos($this->field_config[$field]['date_display'], ';') ? substr($this->field_config[$field]['date_display'], 0, strpos($this->field_config[$field]['date_display'], ';')) : $this->field_config[$field]['date_display'];
         $time_format  = false !== strpos($this->field_config[$field]['date_format'] , ';') ? substr($this->field_config[$field]['date_format'] , strpos($this->field_config[$field]['date_format'] , ';') + 1) : '';
         $time_sep     = $this->field_config[$field]['time_sep'];
         $time_display = false !== strpos($this->field_config[$field]['date_display'], ';') ? substr($this->field_config[$field]['date_display'], strpos($this->field_config[$field]['date_display'], ';') + 1) : '';
     }
     elseif ('HH' == $type)
     {
         $date_format  = '';
         $date_sep     = '';
         $date_display = '';
         $time_format  = $this->field_config[$field]['date_format'];
         $time_sep     = $this->field_config[$field]['time_sep'];
         $time_display = $this->field_config[$field]['date_display'];
     }

     if ('DT' == $type || 'DH' == $type)
     {
         $date_array = array();
         $date_index = 0;
         $date_ult   = '';
         for ($i = 0; $i < strlen($date_format); $i++)
         {
             $char = strtolower(substr($date_format, $i, 1));
             if (in_array($char, array('d', 'm', 'y', 'a')))
             {
                 if ('a' == $char)
                 {
                     $char = 'y';
                 }
                 if ($char == $date_ult)
                 {
                     $date_array[$date_index] .= $char;
                 }
                 else
                 {
                     if ('' != $date_ult)
                     {
                         $date_index++;
                     }
                     $date_array[$date_index] = $char;
                 }
             }
             $date_ult = $char;
         }

         $disp_array = array();
         $date_index = 0;
         $date_ult   = '';
         for ($i = 0; $i < strlen($date_display); $i++)
         {
             $char = strtolower(substr($date_display, $i, 1));
             if (in_array($char, array('d', 'm', 'y', 'a')))
             {
                 if ('a' == $char)
                 {
                     $char = 'y';
                 }
                 if ($char == $date_ult)
                 {
                     $disp_array[$date_index] .= $char;
                 }
                 else
                 {
                     if ('' != $date_ult)
                     {
                         $date_index++;
                     }
                     $disp_array[$date_index] = $char;
                 }
             }
             $date_ult = $char;
         }

         $date_final = array();
         foreach ($date_array as $date_part)
         {
             if (in_array($date_part, $disp_array))
             {
                 $date_final[] = $date_part;
             }
         }

         $date_format = implode($date_sep, $date_final);
     }
     if ('HH' == $type || 'DH' == $type)
     {
         $time_array = array();
         $time_index = 0;
         $time_ult   = '';
         for ($i = 0; $i < strlen($time_format); $i++)
         {
             $char = strtolower(substr($time_format, $i, 1));
             if (in_array($char, array('h', 'i', 's')))
             {
                 if ($char == $time_ult)
                 {
                     $time_array[$time_index] .= $char;
                 }
                 else
                 {
                     if ('' != $time_ult)
                     {
                         $time_index++;
                     }
                     $time_array[$time_index] = $char;
                 }
             }
             $time_ult = $char;
         }

         $disp_array = array();
         $time_index = 0;
         $time_ult   = '';
         for ($i = 0; $i < strlen($time_display); $i++)
         {
             $char = strtolower(substr($time_display, $i, 1));
             if (in_array($char, array('h', 'i', 's')))
             {
                 if ($char == $time_ult)
                 {
                     $disp_array[$time_index] .= $char;
                 }
                 else
                 {
                     if ('' != $time_ult)
                     {
                         $time_index++;
                     }
                     $disp_array[$time_index] = $char;
                 }
             }
             $time_ult = $char;
         }

         $time_final = array();
         foreach ($time_array as $time_part)
         {
             if (in_array($time_part, $disp_array))
             {
                 $time_final[] = $time_part;
             }
         }

         $time_format = implode($time_sep, $time_final);
     }

     if ('DT' == $type)
     {
         $old_date_format = $date_format;
     }
     elseif ('DH' == $type)
     {
         $old_date_format = $date_format . ';' . $time_format;
     }
     elseif ('HH' == $type)
     {
         $old_date_format = $time_format;
     }

     for ($i = 0; $i < strlen($old_date_format); $i++)
     {
         $char = substr($old_date_format, $i, 1);
         if ('/' == $char)
         {
             $new_date_format_out .= $date_sep;
         }
         elseif (':' == $char)
         {
             $new_date_format_out .= $time_sep;
         }
         else
         {
             $new_date_format_out .= $char;
         }
     }

     $this->field_config[$field]['date_format'] = $new_date_format_out;
     if ('DH' == $type)
     {
         $new_date_format_out                                  = explode(';', $new_date_format_out);
         $this->field_config[$field]['date_format_js']        = $new_date_format_out[0];
         $this->field_config[$field . '_hora']['date_format'] = $new_date_format_out[1];
         $this->field_config[$field . '_hora']['time_sep']    = $this->field_config[$field]['time_sep'];
     }
 } // new_date_format

function nmgp_redireciona($tipo=0)
{
   global $nm_apl_dependente;
   if (isset($_SESSION['scriptcase']['nm_sc_retorno']) && !empty($_SESSION['scriptcase']['nm_sc_retorno']) && $_SESSION['scriptcase']['sc_tp_saida'] != "D" && $nm_apl_dependente != 1) 
   {
       $nmgp_saida_form = $_SESSION['scriptcase']['nm_sc_retorno'];
   }
   else
   {
       $nmgp_saida_form = $_SESSION['scriptcase']['sc_url_saida'][$this->Ini->sc_page];
   }
   if ($tipo == 2)
   {
       $nmgp_saida_form = "recherche_fiche_ps_mob_fim.php";
   }
   if (isset($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['redir']) && $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['redir'] == 'redir')
   {
       unset($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']);
   }
   unset($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['opc_ant']);
   if ($tipo == 2 && isset($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['nm_run_menu']) && $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['nm_run_menu'] == 1)
   {
       $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['nm_run_menu'] = 2;
       $nmgp_saida_form = "recherche_fiche_ps_mob_fim.php";
   }
   $diretorio = explode("/", $nmgp_saida_form);
   $cont = count($diretorio);
   $apl = $diretorio[$cont - 1];
   $apl = str_replace(".php", "", $apl);
   $pos = strpos($apl, "?");
   if ($pos !== false)
   {
       $apl = substr($apl, 0, $pos);
   }
   if ($tipo != 1 && $tipo != 2)
   {
       unset($_SESSION['sc_session'][$this->Ini->sc_page][$apl]['where_orig']);
   }
   if ($this->NM_ajax_flag)
   {
       $sTarget = '_self';
       $this->NM_ajax_info['redir']['metodo']              = 'post';
       $this->NM_ajax_info['redir']['action']              = $nmgp_saida_form;
       $this->NM_ajax_info['redir']['target']              = $sTarget;
       $this->NM_ajax_info['redir']['script_case_init']    = $this->Ini->sc_page;
       if (0 == $tipo)
       {
           $this->NM_ajax_info['redir']['nmgp_url_saida'] = $this->nm_location;
       }
       recherche_fiche_ps_mob_pack_ajax_response();
       exit;
   }
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
            "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">

   <HTML>
   <HEAD>
    <META http-equiv="Content-Type" content="text/html; charset=<?php echo $_SESSION['scriptcase']['charset_html'] ?>" />
<?php

   if (isset($_SESSION['scriptcase']['device_mobile']) && $_SESSION['scriptcase']['device_mobile'] && $_SESSION['scriptcase']['display_mobile'])
   {
?>
     <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
<?php
   }

?>
    <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="shortcut icon" href="../_lib/img/sys__NM__img__NM__emergency_2785811.png">
   </HEAD>
   <BODY>
   <FORM name="form_ok" method="POST" action="<?php echo $this->form_encode_input($nmgp_saida_form); ?>" target="_self">
<?php
   if ($tipo == 0)
   {
?>
     <INPUT type="hidden" name="nmgp_url_saida" value="<?php echo $this->form_encode_input($this->nm_location); ?>"> 
<?php
   }
?>
     <INPUT type="hidden" name="script_case_init" value="<?php echo $this->form_encode_input($this->Ini->sc_page); ?>"> 
   </FORM>
   <SCRIPT type="text/javascript">
      bLigEditLookupCall = <?php if ($this->lig_edit_lookup_call) { ?>true<?php } else { ?>false<?php } ?>;
      function scLigEditLookupCall()
      {
<?php
   if ($this->lig_edit_lookup && isset($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['sc_modal']) && $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['sc_modal'])
   {
?>
        parent.<?php echo $this->lig_edit_lookup_cb; ?>(<?php echo $this->lig_edit_lookup_row; ?>);
<?php
   }
   elseif ($this->lig_edit_lookup)
   {
?>
        opener.<?php echo $this->lig_edit_lookup_cb; ?>(<?php echo $this->lig_edit_lookup_row; ?>);
<?php
   }
?>
      }
      if (bLigEditLookupCall)
      {
        scLigEditLookupCall();
      }
<?php
if ($tipo == 2 && isset($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['masterValue']))
{
    if (isset($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['dashboard_info']['under_dashboard']) && $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['dashboard_info']['under_dashboard']) {
?>
var dbParentFrame = $(parent.document).find("[name='<?php echo $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['dashboard_info']['parent_widget']; ?>']");
if (dbParentFrame && dbParentFrame[0] && dbParentFrame[0].contentWindow.scAjaxDetailValue)
{
<?php
        foreach ($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['masterValue'] as $cmp_master => $val_master)
        {
?>
    dbParentFrame[0].contentWindow.scAjaxDetailValue('<?php echo $cmp_master ?>', '<?php echo $val_master ?>');
<?php
        }
        unset($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['masterValue']);
?>
}
<?php
    }
    else {
?>
if (parent && parent.scAjaxDetailValue)
{
<?php
        foreach ($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['masterValue'] as $cmp_master => $val_master)
        {
?>
    parent.scAjaxDetailValue('<?php echo $cmp_master ?>', '<?php echo $val_master ?>');
<?php
        }
        unset($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['masterValue']);
?>
}
<?php
    }
}
?>
      document.form_ok.submit();
   </SCRIPT>
   </BODY>
   </HTML>
<?php
  exit;
}
function nmgp_redireciona_form($nm_apl_dest, $nm_apl_retorno, $nm_apl_parms, $nm_target="", $opc="", $alt_modal=430, $larg_modal=630)
{
   if (isset($this->NM_is_redirected) && $this->NM_is_redirected)
   {
       return;
   }
   if (is_array($nm_apl_parms))
   {
       $tmp_parms = "";
       foreach ($nm_apl_parms as $par => $val)
       {
           $par = trim($par);
           $val = trim($val);
           $tmp_parms .= str_replace(".", "_", $par) . "?#?";
           if (substr($val, 0, 1) == "$")
           {
               $tmp_parms .= $$val;
           }
           elseif (substr($val, 0, 1) == "{")
           {
               $val        = substr($val, 1, -1);
               $tmp_parms .= $this->$val;
           }
           elseif (substr($val, 0, 1) == "[")
           {
               $tmp_parms .= $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob'][substr($val, 1, -1)];
           }
           else
           {
               $tmp_parms .= $val;
           }
           $tmp_parms .= "?@?";
       }
       $nm_apl_parms = $tmp_parms;
   }
   if (empty($opc))
   {
       $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['opcao'] = "";
       $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['opc_ant'] = "";
       $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['retorno_edit'] = "";
   }
   $nm_target_form = (empty($nm_target)) ? "_self" : $nm_target;
   if (strtolower(substr($nm_apl_dest, -4)) != ".php" && (strtolower(substr($nm_apl_dest, 0, 7)) == "http://" || strtolower(substr($nm_apl_dest, 0, 8)) == "https://" || strtolower(substr($nm_apl_dest, 0, 3)) == "../"))
   {
       if ($this->NM_ajax_flag)
       {
           $this->NM_ajax_info['redir']['metodo'] = 'location';
           $this->NM_ajax_info['redir']['action'] = $nm_apl_dest;
           $this->NM_ajax_info['redir']['target'] = $nm_target_form;
           recherche_fiche_ps_mob_pack_ajax_response();
           exit;
       }
       echo "<SCRIPT language=\"javascript\">";
       if (strtolower($nm_target) == "_blank")
       {
           echo "window.open ('" . $nm_apl_dest . "');";
           echo "</SCRIPT>";
           return;
       }
       else
       {
           echo "window.location='" . $nm_apl_dest . "';";
           echo "</SCRIPT>";
           $this->NM_close_db();
           exit;
       }
   }
   $dir = explode("/", $nm_apl_dest);
   if (count($dir) == 1)
   {
       $nm_apl_dest = str_replace(".php", "", $nm_apl_dest);
       $nm_apl_dest = $this->Ini->path_link . SC_dir_app_name($nm_apl_dest) . "/" . $nm_apl_dest . ".php";
   }
   if ($this->NM_ajax_flag)
   {
       $nm_apl_parms = str_replace("?#?", "*scin", NM_charset_to_utf8($nm_apl_parms));
       $nm_apl_parms = str_replace("?@?", "*scout", $nm_apl_parms);
       $this->NM_ajax_info['redir']['metodo']     = 'post';
       $this->NM_ajax_info['redir']['action']     = $nm_apl_dest;
       $this->NM_ajax_info['redir']['nmgp_parms'] = $nm_apl_parms;
       $this->NM_ajax_info['redir']['target']     = $nm_target_form;
       $this->NM_ajax_info['redir']['h_modal']    = $alt_modal;
       $this->NM_ajax_info['redir']['w_modal']    = $larg_modal;
       if ($nm_target_form == "_blank")
       {
           $this->NM_ajax_info['redir']['nmgp_outra_jan'] = 'true';
       }
       else
       {
           $this->NM_ajax_info['redir']['nmgp_url_saida']      = $nm_apl_retorno;
           $this->NM_ajax_info['redir']['script_case_init']    = $this->Ini->sc_page;
       }
       recherche_fiche_ps_mob_pack_ajax_response();
       exit;
   }
   if ($nm_target == "modal")
   {
       if (!empty($nm_apl_parms))
       {
           $nm_apl_parms = str_replace("?#?", "*scin", $nm_apl_parms);
           $nm_apl_parms = str_replace("?@?", "*scout", $nm_apl_parms);
           $nm_apl_parms = "nmgp_parms=" . $nm_apl_parms . "&";
       }
       $par_modal = "?script_case_init=" . $this->Ini->sc_page . "&nmgp_outra_jan=true&nmgp_url_saida=modal&NMSC_modal=ok&";
       $this->redir_modal = "$(function() { tb_show('', '" . $nm_apl_dest . $par_modal . $nm_apl_parms . "TB_iframe=true&modal=true&height=" . $alt_modal . "&width=" . $larg_modal . "', '') })";
       $this->NM_is_redirected = true;
       return;
   }
   if ($nm_target == "_blank")
   {
?>
<form name="Fredir" method="post" target="_blank" action="<?php echo $nm_apl_dest; ?>">
  <input type="hidden" name="nmgp_parms" value="<?php echo $this->form_encode_input($nm_apl_parms); ?>"/>
</form>
<script type="text/javascript">
setTimeout(function() { document.Fredir.submit(); }, 250);
</script>
<?php
    return;
   }
?>
<?php
   if ($nm_target_form != "_blank" && $nm_target_form != "modal")
   {
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
            "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">

   <HTML>
   <HEAD>
    <META http-equiv="Content-Type" content="text/html; charset=<?php echo $_SESSION['scriptcase']['charset_html'] ?>" />
<?php

   if (isset($_SESSION['scriptcase']['device_mobile']) && $_SESSION['scriptcase']['device_mobile'] && $_SESSION['scriptcase']['display_mobile'])
   {
?>
     <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
<?php
   }

?>
    <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="shortcut icon" href="../_lib/img/sys__NM__img__NM__emergency_2785811.png">
    <SCRIPT type="text/javascript" src="<?php echo $this->Ini->url_third; ?>jquery/js/jquery.js"></SCRIPT>
   </HEAD>
   <BODY>
<?php
   }
?>
<form name="Fredir" method="post" 
                  target="_self"> 
  <input type="hidden" name="nmgp_parms" value="<?php echo $this->form_encode_input($nm_apl_parms); ?>"/>
<?php
   if ($nm_target_form == "_blank")
   {
?>
  <input type="hidden" name="nmgp_outra_jan" value="true"/> 
<?php
   }
   else
   {
?>
  <input type="hidden" name="nmgp_url_saida" value="<?php echo $this->form_encode_input($nm_apl_retorno) ?>">
  <input type="hidden" name="script_case_init" value="<?php echo $this->form_encode_input($this->Ini->sc_page); ?>"/> 
<?php
   }
?>
</form> 
   <SCRIPT type="text/javascript">
<?php
   if ($nm_target_form == "modal")
   {
?>
       $(document).ready(function(){
           tb_show('', '<?php echo $nm_apl_dest ?>?script_case_init=<?php echo $this->Ini->sc_page; ?>&nmgp_url_saida=modal&nmgp_parms=<?php echo $this->form_encode_input($nm_apl_parms); ?>&nmgp_outra_jan=true&TB_iframe=true&height=<?php echo $alt_modal; ?>&width=<?php echo $larg_modal; ?>&modal=true', '');
       });
<?php
   }
   else
   {
?>
    $(function() {
       document.Fredir.target = "<?php echo $nm_target_form ?>"; 
       document.Fredir.action = "<?php echo $nm_apl_dest ?>";
       document.Fredir.submit();
    });
<?php
   }
?>
   </SCRIPT>
<?php
   if ($nm_target_form != "_blank" && $nm_target_form != "modal")
   {
?>
   </BODY>
   </HTML>
<?php
   }
?>
<?php
   if ($nm_target_form != "_blank" && $nm_target_form != "modal")
   {
       $this->NM_close_db();
       exit;
   }
}
    function sc_ajax_alert($sMessage, $params = array())
    {
        if ($this->NM_ajax_flag)
        {
            $this->NM_ajax_info['ajaxAlert']['message'] = NM_charset_to_utf8($sMessage);
            $this->NM_ajax_info['ajaxAlert']['params']  = $this->sc_ajax_alert_params($params);
        }
    } // sc_ajax_alert

    function sc_ajax_alert_params($params)
    {
        $paramList = array();
        foreach ($params as $paramName => $paramValue)
        {
            if (in_array($paramName, array('title', 'timer', 'confirmButtonText', 'confirmButtonFA', 'confirmButtonFAPos', 'cancelButtonText', 'cancelButtonFA', 'cancelButtonFAPos', 'footer', 'width', 'padding', 'position')))
            {
                $paramList[$paramName] = NM_charset_to_utf8($paramValue);
            }
            elseif (in_array($paramName, array('showConfirmButton', 'showCancelButton', 'toast')) && in_array($paramValue, array(true, false)))
            {
                $paramList[$paramName] = NM_charset_to_utf8($paramValue);
            }
            elseif ('position' == $paramName && in_array($paramValue, array('top', 'top-start', 'top-end', 'center', 'center-start', 'center-end', 'bottom', 'bottom-start', 'bottom-end')))
            {
                $paramList[$paramName] = NM_charset_to_utf8($paramValue);
            }
            elseif ('type' == $paramName && in_array($paramValue, array('warning', 'error', 'success', 'info', 'question')))
            {
                $paramList[$paramName] = NM_charset_to_utf8($paramValue);
            }
            elseif ('background' == $paramName)
            {
                $paramList[$paramName] = $this->sc_ajax_alert_image(NM_charset_to_utf8($paramValue));
            }
        }
        return $paramList;
    } // sc_ajax_alert_params

    function sc_ajax_alert_image($background)
    {
        $image_param = $background;
        preg_match_all('/url\(([\s])?(["|\'])?(.*?)(["|\'])?([\s])?\)/i', $background, $matches, PREG_PATTERN_ORDER);
        if (isset($matches[3])) {
            foreach ($matches[3] as $match) {
                if ('http:' != substr($match, 0, 5) && 'https:' != substr($match, 0, 6) && '/' != substr($match, 0, 1)) {
                    $image_param = str_replace($match, "{$this->Ini->path_img_global}/{$match}", $image_param);
                }
            }
        }
        return $image_param;
    } // sc_ajax_alert_image
    function getButtonIds($buttonName) {
        switch ($buttonName) {
            case "recherche_fiche":
                return array("sc_recherche_fiche_bot.");
                break;
            case "fiche_patient":
                return array("sc_fiche_patient_bot.");
                break;
            case "ok":
                return array("sub_form_b.sc-unique-btn-1");
                break;
            case "help":
                return array("sc_b_hlp_b");
                break;
            case "exit":
                return array("Bsair_b.sc-unique-btn-2", "Bsair_b.sc-unique-btn-3");
                break;
        }

        return array($buttonName);
    } // getButtonIds

    function displayAppHeader()
    {
        if ($this->Embutida_call) {
            return;
        }
        if (isset($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps']['mostra_cab']) && $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps']['mostra_cab'] == "N") {
            return;
        }
        if ($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['dashboard_info']['under_dashboard'] && $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['dashboard_info']['compact_mode'] && !$_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['dashboard_info']['maximized']) {
            return;
        }
        if (isset($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['link_info']['compact_mode']) && $_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['link_info']['compact_mode']) {
            return;
        }
?>
    <tr><td class="sc-app-header">
<style>
    .scMenuTHeaderFont img, .scGridHeaderFont img , .scFormHeaderFont img , .scTabHeaderFont img , .scContainerHeaderFont img , .scFilterHeaderFont img { height:23px;}
</style>
<div class="scFormHeader" style="height: 54px; padding: 17px 15px; box-sizing: border-box;margin: -1px 0px 0px 0px;width: 100%;">
    <div class="scFormHeaderFont" style="float: left; text-transform: uppercase;"><?php if ($this->nmgp_opcao == "novo") { echo "" . $this->Ini->Nm_lang['lang_othr_frmi_titl'] . ""; } else { echo "Rechercher une fiche de malade"; } ?></div>
    <div class="scFormHeaderFont" style="float: right;"></div>
</div>
    </td></tr>
<?php
    }

    function displayAppFooter()
    {
    }

    function displayAppToolbars()
    {
        return true;
    } // displayAppToolbars

    function displayTopToolbar()
    {
        if (!$this->displayAppToolbars()) {
            return;
        }
    } // displayTopToolbar

    function displayBottomToolbar()
    {
        if (!$this->displayAppToolbars()) {
            return;
        }
    } // displayBottomToolbar

    function scGetColumnOrderRule($fieldName, &$orderColName, &$orderColOrient, &$orderColRule)
    {
        $sortRule = 'nosort';
        if ($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['ordem_cmp'] == $fieldName) {
            $orderColName = $fieldName;
            if ($_SESSION['sc_session'][$this->Ini->sc_page]['recherche_fiche_ps_mob']['ordem_ord'] == " desc") {
                $orderColOrient = $nome_img = $this->Ini->Label_sort_desc;
                $orderColRule = $sortRule = 'desc';
            } else {
                $orderColOrient = $nome_img = $this->Ini->Label_sort_asc;
                $orderColRule = $sortRule = 'asc';
            }
        }
        return $sortRule;
    }

    function scGetColumnOrderIcon($fieldName, $sortRule)
    {        if ($this->scIsFieldNumeric($fieldName)) {
            $defaultOffIcon = 'asc' == $this->scGetDefaultFieldOrder($fieldName) ? "fas fa-sort-numeric-down" : "fas fa-sort-numeric-down-alt";
            if ('desc' == $sortRule) {
                return "<span class=\"fas fa-sort-numeric-down-alt sc-form-order-icon\"></span>";
            } elseif ('asc' == $sortRule) {
                return "<span class=\"fas fa-sort-numeric-down sc-form-order-icon\"></span>";
            } else {
                return "<span class=\"" . $defaultOffIcon . " sc-form-order-icon sc-form-order-icon-unused\"></span>";
            }
        } else {
            $defaultOffIcon = 'asc' == $this->scGetDefaultFieldOrder($fieldName) ? "fas fa-sort-alpha-down" : "fas fa-sort-alpha-down-alt";
            if ('desc' == $sortRule) {
                return "<span class=\"fas fa-sort-alpha-down-alt sc-form-order-icon\"></span>";
            } elseif ('asc' == $sortRule) {
                return "<span class=\"fas fa-sort-alpha-down sc-form-order-icon\"></span>";
            } else {
                return "<span class=\"" . $defaultOffIcon . " sc-form-order-icon sc-form-order-icon-unused\"></span>";
            }
        }
    }

    function scIsFieldNumeric($fieldName)
    {
        switch ($fieldName) {
            default:
                return false;
        }
        return false;
    }

    function scGetDefaultFieldOrder($fieldName)
    {
        switch ($fieldName) {
            default:
                return 'asc';
        }
        return 'asc';
    }
}
?>
