Login   Register  
PHP Classes
elePHPant
Icontem

File: functions.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of saulo hernandez  >  DBGridMx  >  functions.php  >  Download  
File: functions.php
Role: Auxiliary script
Content type: text/plain
Description: system functions
Class: DBGridMx
Show and manipulate MySQL records in a table grid
Author: By
Last change:
Date: 2 years ago
Size: 29,990 bytes
 

Contents

Class file image Download
<?php
@define("EW_USE_DEFAULT_LOCALE", FALSE, TRUE);
@define("DEFAULT_DECIMAL_POINT", ".", TRUE);
@define("DEFAULT_THOUSANDS_SEP", ",", TRUE);
@define("DEFAULT_CURRENCY_SYMBOL", "$", TRUE);
@define("DEFAULT_MON_DECIMAL_POINT", ".", TRUE);
@define("DEFAULT_MON_THOUSANDS_SEP", ",", TRUE);
@define("DEFAULT_POSITIVE_SIGN", "", TRUE);
@define("DEFAULT_NEGATIVE_SIGN", "-", TRUE);
@define("DEFAULT_FRAC_DIGITS", 2, TRUE);
@define("DEFAULT_P_CS_PRECEDES", TRUE, TRUE);
@define("DEFAULT_P_SEP_BY_SPACE", FALSE, TRUE);
@define("DEFAULT_N_CS_PRECEDES", TRUE, TRUE);
@define("DEFAULT_N_SEP_BY_SPACE", FALSE, TRUE);
@define("DEFAULT_P_SIGN_POSN", 3, TRUE);
@define("DEFAULT_N_SIGN_POSN", 3, TRUE);
@define("REGADD",1,TRUE);
@define("REGDEL",2,TRUE);
@define("REGUPD",4,TRUE);
@define("REGLST",8,TRUE);
@define("REGVIW",32,TRUE);
@define("REGSRC",64,TRUE);
@define("REGPRN",128,TRUE);
@define("FILE_FIELD_SETTINGS_DETAILS","FileFieldSettingsDetails",TRUE);
@define("FILE_FIELD_SETTINGS","FileFieldSettings",TRUE);
@define("FIELD_SETTINGS_DETAILS","FieldSettingsDetails");
@define("OPEN_DEFAULT",1,TRUE);
@define("OPEN_LIST",2,TRUE);
@define("OPEN_ADD_NEW",3,TRUE);
@define("OPEN_UPDATE",4,TRUE);
@define("OPEN_DELETE",5,TRUE);
@define("OPEN_MASTER_DETAIL",6,TRUE);
@define("OPEN_VIEW",7,TRUE);
@define("BTN_ADD_NEW","AddNew",TRUE);
@define("BTN_SEARCH","Search",TRUE);
@define("BUTTON","Button",TRUE);
@define("FRM_ACTION","FrmAction",TRUE);
@define("FRM_ACTION_VIEW","View",TRUE);
@define("FRM_ACTION_DELETE","Delete",TRUE);
@define("FRM_ACTION_UPDATE","Update",TRUE);
@define("RELATION","Relation",TRUE);
@define("DATE","Date",TRUE);
@define("LIST","List",TRUE);
@define("RADIO","Radio",TRUE);
@define("CHECK","Check",TRUE);
@define("IMAGE","Image",TRUE);
@define("FILE","File",TRUE);
@define("PASSWORD","Password",TRUE);
@define("MONEY","Money",TRUE);
@define("FLOAT","Float",TRUE);
@define("TEXTAREA","TextArea",TRUE);
@define("RECORD_DELETE","Borrar",TRUE);
@define("RECORD_INSERT","Insertar",TRUE);
@define("RECORD_UPDATE","Modificar",TRUE);
@define("FORM_DELETE","delete",TRUE);
@define("FORM_INSERT","insert",TRUE);
@define("FORM_UPDATE","update",TRUE);
@define("FORM_VIEW","view",TRUE);
@define("FORM_UPDATE_DETAIL","updatedetail",TRUE);
@define("FORM_DELETE_DETAIL","deletedetail",TRUE);
@define("FORM_MASTER_DETAIL","masterdetail",TRUE);

include "sysconfig.php";

  class Button
  {
      private $Link;
      private $Label;
      private $Icon;  
      private $Type;
      private $Visible;
      private $Name;
      private $parameters;

      function __construct($nm,$Lnk,$lbl,$icn,$tpy,$vis)
      {   $this->Name=$nm;
          $this->Link=$Lnk;
          $this->Label=$lbl;
          $this->Type=$tpy;
          $this->Icon=$icn;          
          $this->Visible=$vis;
      }
      function __get($property)
      {
          return $this->$property;
      }
      function __set($property,$value)
      {
          $this->$property=$value;
      }
  }

  //clase que define una valor de una lista de valores de una campo de bases de datos
  class Value
  {
      private $Val;
      private $Label;

      function __construct($v,$l)
      {
          $this->Val=$v;
          $this->Label=$l;
      }
      function __get($parameter)
      {
          return $this->$parameter;
      }
      function __set($parameter,$v)
      {
        $this->$parameter=$v;  
      }
  }
  //clase que define las configuarciones posibles de un campo de base de datos
  class FieldSettings
  {
    private $FieldName;
    private $PK=false;
    private $AI=false;
    private $Type="Text";
    private $SubType="";
    private $Long=1;
    private $Format="";
    private $UseCombo=false;
    private $UseCalendar=false;
    private $UseEditor=false;
    private $TableRel="";
    private $FieldRel="";
    private $FieldDisplay="";
    private $Values="";
    private $ShowPasswordInView=false;
    private $PackingType="";
    private $Label="";
    private $ShowInList=true;
    private $ShowInAddNew=true;
    private $ShowInUpdate=true;
    private $ShowInDetails=true;
    private $Icon_YES="";
    private $Icon_NO="";
    private $IconValues="";
    private $FilledFromTable="";
    private $FilledFrom="";
    private $FilledFromField="";
    private $ParentField="";
    private $AutoComplete=true;

    function __construct($FName,$PrK,$AIn,$Typ,$Lng,$Lbl,$ShwL=True)
    {
     $this->FieldName=$FName;
     $this->PK=$PrK;
     $this->AI=$AIn;
     $this->Type=$Typ;
     $this->Long=$Lng;
     $this->Label=$Lbl;
     $this->ShowInList=$ShwL;   
    }
    function  __get($property) 
    {
        return $this->$property;
    }
    function __set($property,$value)
    {
        $this->$property=$value;
    }  }
  //clase que define una tabla de  detalle y sus configuraciones
  class TableDetail
  {
      private $TableName;
      private $QryList;
      private $QryUpdate;
      private $QryAddNew;
      private $FileNameDetails;
      private $MasterFieldRel;
      private $DetailFieldRel;
      private $FieldSettingsDetails;
      private $FileSettingsDetails;
      private $SectionLabel;
      private $AllowUpdate;
      private $AllowAddNew;
      private $AllowDelete;
      private $IconDetail; //ShowIcon
      private $CountColumn;
      private $CountColumnFmt;
      private $CountColumnLabel;
      private $SumColumn;
      private $sumColumnFmt;
      private $SumColumnLabel;
      private $AvgColumn;
      private $AvgColumnFmt;     
      private $AvgColumnLabel;
   
    function __construct($TblName,$QL,$fnd,$MFR,$DFR,$SL,$IcnD)
    {
     $this->TableName=$TblName;
     $this->QryList=$QL;
     $this->FileNameDetails=$fnd;
     $this->MasterFieldRel=$MFR;
     $this->DetailFieldRel=$DFR;
     $this->SectionLabel=$SL;
     $this->IconDetail=$IcnD;
     $this->FieldSettingsDetails=new Collection();   
    }
    function destruct()
    {
        
    }
    function  __get($property) 
    {
        return $this->$property;
    }
    function __set($property,$value)
    {
        $this->$property=$value;
    }
    
    function AddFieldSetting($FieldSetting)
    {
     $this->FieldSettingsDetails->Add($FieldSetting);
    }
    
    function LoadFileSettings()
    {
       $Det=Array();
       if (!$this->FileSettingsDetails==Null)
        {
            $Det=parse_ini_file($this->FileSettingsDetails);
            
             foreach($Det as $fldname => $Dflds)
             {   $Fldsett= new FieldSettings("","","","","","","");
                 $Fldsett->__set("FieldName",$fldname);
                 foreach ($Dflds as $Sett=>$va)
                  {$Fldsett__set($Sett,$va);}
                 $this->FieldSettingsDetails->Add($Fldsett); 
             }
        }
    }
  }

// clase que define el funcionamiento de una collección de items o valores
  class Collection
  {
      private $collectionValues=Array();
      function __construct()
      {
      }
      function countitems()
      {
          return count($this->collectionValues);
      }
      function Add($item)
      {
        $this->collectionValues[]=$item;
      }

      function Get($inx)
      {
        return $this->collectionValues[$inx];
      }
      
      function Pop()
      {
        return array_pop($this->collectionValues);
      }
      
      function Push($item)
      {
          array_push($this->collectionValues,$item);
      }
      function Update($item)
      {                -
          $itemfound=in_array($item,$this->collectionValues);
          if (!$itemfound==Null)
          {   
             $this->collectionValues[$itemfound]=$item; 
          }
      }
      function search($key,$value)
      {
          for ($i=0;$i<$this->countitems();$i++)
           {
               $item=$this->collectionValues[$i];
               if ($item->__get($key)==$value)
               return $i;
           }
      }
  }


 function get_userpriv($userlevel,$formid)
{  if ((int)$userlevel==1)
      {
          return 255;
      } 
   else
   {
    $conn=mysql_connect(CONN_HOST,CONN_USER,CONN_PASS);
    $rs=mysql_query("select * from userlevelpermissions where userlevelid=$userlevel and formname = '$formid'",$conn);
    if ($rs)
      { $fila=mysql_fetch_assoc($rs);
        {
            return $fila["permission"];
        }
      }  
       else
        {return 0;}
   }
     
}

  //regresa un valor relacionado con un campo llave foranea de una tabla
  function getRelationValue($Tbl,$FieldRel,$idRelvalue,$DisplayRelvalue)
  { $result=Null;
    if ($idRelvalue!=Null)
    {
     if (is_string($idRelvalue))
       $result=mysql_query("Select $DisplayRelvalue from $Tbl where $FieldRel = '$idRelvalue'"); 
     else if  (is_int($idRelvalue))
           $result=mysql_query("Select $DisplayRelvalue from $Tbl where $FieldRel = $idRelvalue");
     while ($fila=mysql_fetch_row($result))
        { return $fila[0];   
        }
    }   
  }
  
//**** Populate DropDown******
//Muestra en HTML un combobox (SELECT) relacionado con una tabla


function PopulateSelectTag($table,$selectname,$id,$desc,$options,$def)
{$resultado=Null; 
$package_result = mysql_query("select distinct $id,$desc FROM " .$table);
$resultado .="<select name=\"" .$selectname ."\" id=\"" .$selectname ."\"" .$options .">";
//echo "</OPTION>";
if ($options=='distinct')
  $resultado .=  "<option value=\"\" selected=\"selected\">Seleccione ".$desc ."</option>";
else
 $resultado .=  "<option value=\"\" selected=\"selected\">Seleccione " .$table ."</option>";
 
while ($row_item = mysql_fetch_array($package_result)){
$pname = $row_item[$id];
$label = $row_item[$desc];
if ($pname==$def)
  $resultado .=  "<OPTION value=\"" .$pname ."\" selected=\"true\">". $label ."</OPTION>";
else $resultado .=  "<OPTION value=\"" .$pname ."\">". $label ."</OPTION>";
}
$resultado .=  "</select>";
return $resultado;
}
//Radio Butons de una BD

function PopulateRadioTag($table,$radioname,$id,$desc,$options,$def)
{ $Resultado=Null;
$package_result = mysql_query("select distinct $id,$desc FROM " .$table);
//$resultado .="<select name=\"" .$selectname ."\"" .$options .">";
//echo "</OPTION>";
/*if ($options=='distinct')
  $resultado .=  "<option value=\"\" selected=\"selected\">Seleccione ".$desc ."</option>";
else
 $resultado .=  "<option value=\"\" selected=\"selected\">Seleccione " .$table ."</option>";
*/ 
while ($row_item = mysql_fetch_array($package_result)){
$pname = $row_item[$id];
$label = $row_item[$desc];
if ($pname==$def)
          $Resultado .=  "<input Type=\"radio\" name=\"$radioname\" id=\"$radioname\"  checked value=\"$pname\">$label&nbsp;&nbsp;";
        else
          $Resultado .=  "<input Type=\"radio\" name=\"$radioname\" id=\"$radioname\"  value=\"$pname\">$label&nbsp;&nbsp;";  
}
//$resultado .=  "</select>";
return $resultado;
}


/**/

  function TokenValues($values,$TokenSeparator,$closechar)
  { $tok=Null;
    $ArrValues=array();
    $j=0;
    $tok=strtok($values,$TokenSeparator);
    if ($tok!==false)
      {
          if ($closechar!="")
          {
           $t1=str_replace($closechar[0],"",$tok);
           $t1=str_replace($closechar[1],"",$t1);
           $ArrValues[$j]=$t1;
          }
         else 
          $ArrValues[$j]=$tok;

      }
    while ($tok!==false)
    {
          if ($closechar!="")
          {
           $t1=str_replace($closechar[0],"",$tok);
           $t1=str_replace($closechar[1],"",$t1);
           $ArrValues[$j]=$t1;
          }
         else 
          $ArrValues[$j]=$tok;
       $tok=strtok($TokenSeparator);
      $j++;
    }
    return $ArrValues;
    
  }


function PopulateSelectTagFromValues($values,$TokenSeparator,$closechar,$selectname,$desc,$options,$default)
{
 $resultado=Null;
 $resultado .="<select name=\"" .$selectname ."\" id=\"$selectname\"" .$options .">";
 $resultado .=  "<option value=\"\" selected=\"selected\">Seleccione " .$desc ."</option>";
 $A=array(); 
 $A=TokenValues($values,$TokenSeparator,$closechar);
 //sacamos los valores de $A
 $B=Null;
 foreach ($A as $t)
   {
       $B=TokenValues($t,":","");
       $pname=$B[0];
       $label=$B[1];
   
       if ($pname==$default)
        $resultado .=  "<OPTION value=\"" .$pname ."\" selected=\"true\">". $label ."</OPTION>";
       else 
         $resultado .=  "<OPTION value=\"" .$pname ."\">". $label ."</OPTION>";
    }
  $resultado .=  "</select>";
return $resultado;
}

//echo RadioTag("[0:No],[1:Si]","Activo","0",",","[]");

function RadioTag($values=array(),$radioname,$default,$TokenSeparator,$closechar)
{ 
 $Resultado=Null;
 $A=array(); 
 $A=TokenValues($values,$TokenSeparator,$closechar);
 $B=Null;   
 foreach ($A as $t)
   {
      $B=TokenValues($t,":","");  
        if ($B[0]==$default)
          $Resultado .=  "<input Type=\"radio\" name=\"$radioname\" id=\"$radioname\"  checked value=\"$B[0]\">$B[1] &nbsp;&nbsp;";
        else
          $Resultado .=  "<input Type=\"radio\" name=\"$radioname\" id=\"$radioname\"  value=\"$B[0]\">$B[1] &nbsp;&nbsp;";  
          
        
        
   }
  return $Resultado;
}

function CheckTag($values=array(),$checkname,$default,$TokenSeparator,$closechar)
{
 $Resultado=Null;
 $A=array(); 
 $A=TokenValues($values,$TokenSeparator,$closechar);
    
 foreach ($A as $t)
   {
      $B=TokenValues($t,":","");  
        if ($B[0]==$default)
          $Resultado .=  "<input Type=\"checkbox\" name=\"$checkname" ."[]" ."\" id=\"$checkname" ."[]" ."\"  checked value=\"$B[0]\">$B[1] &nbsp;&nbsp;";
        else
          $Resultado .=  "<input Type=\"checkbox\" name=\"$checkname" ."[]" ."\" id=\"$checkname" ."[]" ."\" value=\"$B[0]\">$B[1] &nbsp;&nbsp;";  
          
        
        
   }
  return $Resultado;
}
function Display_Checks_Sumarized($values=array(),$checkname,$valores,$TokenSeparator,$closechar,$ro="")
{
 $A=array(); 
 $A=TokenValues($values,$TokenSeparator,$closechar);
 $B=Null;
 $R="";
 $i=0;
 for($j=0;$j<count($A);$j++)
   {
      $B=TokenValues($A[$j],":","");  
      if (((int)$B[0] & (int)$valores)==(int)$B[0])
        {
          $Resultado .=  "<input Type=\"checkbox\" name=\"$checkname" ."[]" ."\" id=\"$checkname" ."[]" ."\"  $ro checked value=\"$B[0]\">$B[1] &nbsp;&nbsp;";
        }  
        else
        {
          $Resultado .=  "<input Type=\"checkbox\" name=\"$checkname" ."[]" ."\" id=\"$checkname" ."[]" ."\" $ro value=\"$B[0]\">$B[1] &nbsp;&nbsp;";  
        }
   }
 return $Resultado;
}

function Display_Checks_Tokenized($values=array(),$checkname,$valores,$TokenSeparator,$closechar,$ro="")
{
 $A=array(); 
 $A=TokenValues($values,$TokenSeparator,$closechar);
 $B=Null;
 $R="";
 $i=0;
 for($j=0;$j<count($A);$j++)
   {
      $B=TokenValues($A[$j],":","");  
      if (((int)$B[0] & (int)$valores)==(int)$B[0])
        {
          $Resultado .=  "<input Type=\"checkbox\" name=\"$checkname" ."[]" ."\" id=\"$checkname" ."[]" ."\"  $ro checked value=\"$B[0]\">$B[1] &nbsp;&nbsp;";
        }  
        else
        {
          $Resultado .=  "<input Type=\"checkbox\" name=\"$checkname" ."[]" ."\" id=\"$checkname" ."[]" ."\" $ro value=\"$B[0]\">$B[1] &nbsp;&nbsp;";  
        }
   }
 return $Resultado;
}


function List_Checks_Sumarized($values=array(),$checkname,$valores,$TokenSeparator,$closechar,$ro="",$gray="")
{
 $A=array(); 
 $A=TokenValues($values,$TokenSeparator,$closechar);
 $B=Null;
 $R="";
 $i=0;
 for($j=0;$j<count($A);$j++)
   {
      $B=TokenValues($A[$j],":","");  
      if (((int)$B[0] & (int)$valores)==(int)$B[0])
        {
          $Resultado .=  "<img src='images/checkbox-cheked$gray.jpg'>$B[1] &nbsp;&nbsp;";
        }  
        else
        {
          $Resultado .=  "<img src='images/checkbox-uncheked$gray.jpg'>$B[1] &nbsp;&nbsp;";  
        }
   }
 return $Resultado;
}

function List_Checks_Tokenized($values=array(),$checkname,$valores,$TokenSeparator,$closechar,$ro="",$gray="")
{
 $A=array(); 
 $A=TokenValues($values,$TokenSeparator,$closechar);
 $B=Null;
 $R="";
 $i=0;
 for($j=0;$j<count($A);$j++)
   {
      $B=TokenValues($A[$j],":","");  
      if (((int)$B[0] & (int)$valores)==(int)$B[0])
        {
          $Resultado .=  "<img src='images/checkbox-cheked$gray.jpg'>$B[1] &nbsp;&nbsp;";
        }  
        else
        {
          $Resultado .=  "<img src='images/checkbox-uncheked$gray.jpg'>$B[1] &nbsp;&nbsp;";  
        }
   }
 return $Resultado;
}


function Get_ValueFromList($values,$valor,$TokenSeparator,$closechar)
{
 $A=array(); 
 $A=TokenValues($values,$TokenSeparator,$closechar);
 $B=Null;
 for($j=0;$j<count($A);$j++)
   {
      $B=TokenValues($A[$j],":","");  
      if ($B[0]==$valor)
        {
            return $B[1];
        }
   }
}


//Write INI File
function write_ini_file($assoc_arr, $path, $has_sections=FALSE) 
{ 
    $content = ""; 
    if ($has_sections) { 
        foreach ($assoc_arr as $key=>$elem) { 
            $content .= "[".$key."]\n"; 
            foreach ($elem as $key2=>$elem2) { 
                if(is_array($elem2)) 
                { 
                    for($i=0;$i<count($elem2);$i++) 
                    { 
                        $content .= $key2."[] = \"".$elem2[$i]."\"\n"; 
                    } 
                } 
                else if($elem2=="") $content .= $key2." = \n"; 
                else $content .= $key2." = \"".$elem2."\"\n"; 
            } 
        } 
    } 
    else { 
        foreach ($assoc_arr as $key=>$elem) { 
            if(is_array($elem)) 
            { 
                for($i=0;$i<count($elem);$i++) 
                { 
                    $content .= $key."[] = \"".$elem[$i]."\"\n"; 
                } 
            } 
            else if($elem=="") $content .= $key." = \n"; 
            else $content .= $key." = \"".$elem."\"\n"; 
        } 
    } 

    if (!$handle = fopen($path, 'w')) { 
        return false; 
    } 
    if (!fwrite($handle, $content)) { 
        return false; 
    } 
    fclose($handle); 
    return true; 
}
//Muestra en HTML usando Javascript un calendario flotante
// es indispensable que en el directorio raiz exista la carpeta calendar con los scripts
function show_calendar($name)
{$result =Null;
$result ="<img src=\"images/calendar.png\" id=\"cal_$name\" name=\"cal_$name\" alt=\"Seleccione del Calendario\" title=\"Seleccione del Calendario\" style='cursor:pointer;cursor:hand;' />";
$result .="<script type=\"text/javascript\">";
$result .="Calendar.setup({";
$result .="    inputField:\"" .$name ."\",";
$result .="    ifFormat:\"%d/%m/%Y\",";
$result .="    button:\"cal_" .$name ."\"";
$result .="});";
$result .="</script>";
return $result;
}

function FormatMoneda($number)
{
setlocale(LC_MONETARY, 'en_US');
return sprintf('%01.2f', $number);
// ($        1,234.57)
}

function FormatCurrency($amount, $NumDigitsAfterDecimal, $IncludeLeadingDigit = -2, $UseParensForNegativeNumbers = -2, $GroupDigits = -2) {

    // export the values returned by localeconv into the local scope
    if (!EW_USE_DEFAULT_LOCALE) extract(localeconv()); // PHP 4 >= 4.0.5

    // set defaults if locale is not set
    if (empty($decimal_point)) $decimal_point = DEFAULT_DECIMAL_POINT;
    if (empty($thousands_sep)) $thousands_sep = DEFAULT_THOUSANDS_SEP;
    if (empty($currency_symbol)) $currency_symbol = DEFAULT_CURRENCY_SYMBOL;
    if (empty($mon_decimal_point)) $mon_decimal_point = DEFAULT_MON_DECIMAL_POINT;
    if (empty($mon_thousands_sep)) $mon_thousands_sep = DEFAULT_MON_THOUSANDS_SEP;
    if (empty($positive_sign)) $positive_sign = DEFAULT_POSITIVE_SIGN;
    if (empty($negative_sign)) $negative_sign = DEFAULT_NEGATIVE_SIGN;
    if (empty($frac_digits) || $frac_digits == CHAR_MAX) $frac_digits = DEFAULT_FRAC_DIGITS;
    if (empty($p_cs_precedes) || $p_cs_precedes == CHAR_MAX) $p_cs_precedes = DEFAULT_P_CS_PRECEDES;
    if (empty($p_sep_by_space) || $p_sep_by_space == CHAR_MAX) $p_sep_by_space = DEFAULT_P_SEP_BY_SPACE;
    if (empty($n_cs_precedes) || $n_cs_precedes == CHAR_MAX) $n_cs_precedes = DEFAULT_N_CS_PRECEDES;
    if (empty($n_sep_by_space) || $n_sep_by_space == CHAR_MAX) $n_sep_by_space = DEFAULT_N_SEP_BY_SPACE;
    if (empty($p_sign_posn) || $p_sign_posn == CHAR_MAX) $p_sign_posn = DEFAULT_P_SIGN_POSN;
    if (empty($n_sign_posn) || $n_sign_posn == CHAR_MAX) $n_sign_posn = DEFAULT_N_SIGN_POSN;

    // check $NumDigitsAfterDecimal
    if ($NumDigitsAfterDecimal > -1)
        $frac_digits = $NumDigitsAfterDecimal;

    // check $UseParensForNegativeNumbers
    if ($UseParensForNegativeNumbers == -1) {
        $n_sign_posn = 0;
        if ($p_sign_posn == 0) {
            if (DEFAULT_P_SIGN_POSN != 0)
                $p_sign_posn = DEFAULT_P_SIGN_POSN;
            else
                $p_sign_posn = 3;
        }
    } elseif ($UseParensForNegativeNumbers == 0) {
        if ($n_sign_posn == 0)
            if (DEFAULT_P_SIGN_POSN != 0)
                $n_sign_posn = DEFAULT_P_SIGN_POSN;
            else
                $n_sign_posn = 3;
    }

    // check $GroupDigits
    if ($GroupDigits == -1) {
        $mon_thousands_sep = DEFAULT_MON_THOUSANDS_SEP;
    } elseif ($GroupDigits == 0) {
        $mon_thousands_sep = "";
    }

    // start by formatting the unsigned number
    $number = number_format(abs($amount),
                            $frac_digits,
                            $mon_decimal_point,
                            $mon_thousands_sep);

    // check $IncludeLeadingDigit
    if ($IncludeLeadingDigit == 0) {
        if (substr($number, 0, 2) == "0.")
            $number = substr($number, 1, strlen($number)-1);
    }
    if ($amount < 0) {
        $sign = $negative_sign;

        // "extracts" the boolean value as an integer
        $n_cs_precedes  = intval($n_cs_precedes  == true);
        $n_sep_by_space = intval($n_sep_by_space == true);
        $key = $n_cs_precedes . $n_sep_by_space . $n_sign_posn;
    } else {
        $sign = $positive_sign;
        $p_cs_precedes  = intval($p_cs_precedes  == true);
        $p_sep_by_space = intval($p_sep_by_space == true);
        $key = $p_cs_precedes . $p_sep_by_space . $p_sign_posn;
    }
    $formats = array(

      // currency symbol is after amount
      // no space between amount and sign

      '000' => '(%s' . $currency_symbol . ')',
      '001' => $sign . '%s ' . $currency_symbol,
      '002' => '%s' . $currency_symbol . $sign,
      '003' => '%s' . $sign . $currency_symbol,
      '004' => '%s' . $sign . $currency_symbol,

      // one space between amount and sign
      '010' => '(%s ' . $currency_symbol . ')',
      '011' => $sign . '%s ' . $currency_symbol,
      '012' => '%s ' . $currency_symbol . $sign,
      '013' => '%s ' . $sign . $currency_symbol,
      '014' => '%s ' . $sign . $currency_symbol,

      // currency symbol is before amount
      // no space between amount and sign

      '100' => '(' . $currency_symbol . '%s)',
      '101' => $sign . $currency_symbol . '%s',
      '102' => $currency_symbol . '%s' . $sign,
      '103' => $sign . $currency_symbol . '%s',
      '104' => $currency_symbol . $sign . '%s',

      // one space between amount and sign
      '110' => '(' . $currency_symbol . ' %s)',
      '111' => $sign . $currency_symbol . ' %s',
      '112' => $currency_symbol . ' %s' . $sign,
      '113' => $sign . $currency_symbol . ' %s',
      '114' => $currency_symbol . ' ' . $sign . '%s');

  // lookup the key in the above array
    return sprintf($formats[$key], $number);
}
function GetFileExtension($fname)
{  $long=strlen($fname);
    return strtoupper(substr($fname,long-3));
}
function PackImage($filename,$ext)
{
  switch ($ext)
  {
   case "GIF" :   
     $image = imagecreatefromgif($filename); 
     ob_start(); 
     imagegif($image); 
     $img = ob_get_contents();
     ob_end_clean();
     $img = str_replace('##','##',mysql_escape_string($img));
      break;
   case "JPG" :   
     $image = imagecreatefromjpeg($filename); 
     ob_start(); 
     imagegif($image); 
     $img = ob_get_contents();
     ob_end_clean();
     $img = str_replace('##','##',mysql_escape_string($img));
      break;
   case "PNG" :   
     $image = imagecreatefrompng($filename); 
     ob_start(); 
     imagegif($image); 
     $img = ob_get_contents();
     ob_end_clean();
     $img = str_replace('##','##',mysql_escape_string($img));
      break;
  }
  return $img;      
}

function ShowImage($img)
{ 
  //header("Content-Type: images");
  echo $img;
}

 function load_xml_to_FieldsConfigArray($archivoxml,&$ArrConfig)
 { 
   $xml=simplexml_load_file($archivoxml);   
    for($j=0;$j<$n;$j++)                               
    { 
      
    $ArrConfig[$xml->field[$j]->FieldName];
    $ArrConfig[$xml->field[$j]->FieldName]["Type"]=$xml->field[$j]->Type;
    $ArrConfig[$xml->field[$j]->FieldName]["PK"]=$xml->field[$j]->PK;
    $ArrConfig[$xml->field[$j]->FieldName]["AI"]=$xml->field[$j]->AI;
    $ArrConfig[$xml->field[$j]->FieldName]["Long"]=$xml->field[$j]->Long;
    $ArrConfig[$xml->field[$j]->FieldName]["Format"]=$xml->field[$j]->Format;
    $ArrConfig[$xml->field[$j]->FieldName]["UseCalendar"]=$xml->field[$j]->UseCalendar;
    $ArrConfig[$xml->field[$j]->FieldName]["UseCombo"]=$xml->field[$j]->UseCombo;
    $ArrConfig[$xml->field[$j]->FieldName]["Width"]=$xml->field[$j]->Width;
    $ArrConfig[$xml->field[$j]->FieldName]["Height"]=$xml->field[$j]->Height;
    $ArrConfig[$xml->field[$j]->FieldName]["Border"]=$xml->field[$j]->Border;
    $ArrConfig[$xml->field[$j]->FieldName]["Values"]=$xml->field[$j]->Values;
    $ArrConfig[$xml->field[$j]->FieldName]["TableRel"]=$xml->field[$j]->TableRel;
    $ArrConfig[$xml->field[$j]->FieldName]["FieldRel"]=$xml->field[$j]->FieldRel;
    $ArrConfig[$xml->field[$j]->FieldName]["FieldDisplay"]=$xml->field[$j]->DisplayField;
    $ArrConfig[$xml->field[$j]->FieldName]["ShowPasswordInView"]=$xml->field[$j]->ShowPasswordInView;
    $ArrConfig[$xml->field[$j]->FieldName]["AllowAddNew"]=$xml->field[$j]->AllowAddNew;
    } 
  }

 function set_bool($var) 
 {   if ($var==Null)
      return (Boolean) TRUE;
     elseif (is_bool($var) )
        return (Boolean) $var;
     elseif (is_numeric($var))
      {
          if ($var<0)
           return TRUE;
          else
           return  FALSE;
      }
     elseif (is_string($var))
      {
          switch (strtoupper($var))
          {
              case "SI": return TRUE; break;
              case "YES" : return TRUE; break;
              case "TRUE" : return TRUE; break;
              case "NO" : return FALSE; break;
              case "FALSE" :return FALSE; break;
              case "VERDADERO":return  TRUE; break;
              case "FALSO":return  FALSE; break;
              case "" : return  TRUE; break;
          }
          
      }
      else
        return FALSE;
 }

 function generate_css_table($Cols,$ncols,$nfilas,$buttons,$Headers,$Values,$clshead,$clscellodd,$clscelleven) 
 { $nbutons=count($buttons);
  if (count($nbutons)>0)
     { 
         for ($j=0;$j<nbutons;$j++)
           { $Cols[$j]="<ul>\n";
              $Cols[$j]="<li class='$clshead'>&nbsp;</li>\n";
                 for ($k=0;$k<$nfilas;$k++)
                 {
                     if (($k%2)==0)
                       $Cols[$j] .= "<li class='$clscelleven'>" .$buttons[$k] ."</li>\n";
                     else
                      $Cols[$j] .=  "<li class='$clscellodd'>" .$buttons[$k] ."</li>\n";
                 }
             $Cols[$j] .="</ul>\n";
           }
     }
  for($j=$nbutons;$j<$ncols;$j++)
   { $Cols[$j]="<ul>\n"; 
     $Cols[$j] .= "<li class='$clshead'>" .$Headers[$j] ."</li>\n";
     for ($k=0;$k<$nfilas;$k++)
     {
         if (($k%2)==0)
           $Cols[$j] .= "<li class='$clscelleven'>" .$Values[$j][$k] ."</li>\n";
         else
          $Cols[$j] .=  "<li class='$clscellodd'>" .$Values[$j][$k] ."</li>\n";  
     }
     $Cols[$j] .="</ul>\n";
   }    
 }
 
 function display_cols_css_table($cols)
 { $ncols=count($cols);
   for($c=0;$c<$ncols;$c++)
   {
       echo $cols[$c];
   }
 }                                         

function interpreta_cadena($CurrId=Null,$CurrPage=Null,$FldPK=Null,$FldRel=Null,$FldDisp=Null,$cadena)
{ //palabras Claves:CurrId,CurrPage,FldPK,FldRel,FLdDisp
   if ($CurrId) str_replace($cadena,"{CurrId}",$CurrId);
   if ($CurrPage) str_replace($cadena,"{CurrPage}",$CurrPage);
   if ($FldPK) str_replace($cadena,"{FldPK}",$FldPK);
   if ($FldPK) str_replace($cadena,"{FldRel}",$FldRel);
   if ($FldPK) str_replace($cadena,"{FldDisp}",$FldDisp);
}
 
 function interpreta_cadenaStr($values,$cadena)
{ //
   $ArrTokens=Array();
   $ArrTokens=explode(",",$values);
   $i=0;
   for ($i=0;$i<count($ArrTokens);$i++)
   {
    $Token=substr($ArrTokens[$i],0,stripos($ArrTokens[$i],"=",0));
    $Valor=substr($ArrTokens[$i],stripos($ArrTokens[$i],"=",0)+1,strlen($ArrTokens[$i]));
    $Token="{" .$Token ."}";
    $cadena=str_replace($Token,$Valor,$cadena);
   }
   return $cadena;
   
}
//Despliega La etiqueta personalizada de los campos si Existe
function ShowLabelField($clase,$FieldName)
{
  if ($clase->GetFieldSettings($FieldName,"Label")!="")
     {
         return $clase->GetFieldSettings($FieldName,"Label");
     }
  else
    {
        return $FieldName;
    } 
}
 
  
?>