miércoles, septiembre 05, 2012

Anymazion Returns

Anymazion Back Online, puedes visitarnos en anymazion.com.ar

sábado, junio 05, 2010

Extendiendo un control TreePanel

    /**
     *  Allow: Dynamic enabling/disabling of drag and/or drop.
     *  Author: murrah
     *  Post: 21893 #4
     */
    Ext.ux.TreeDocs = function(config) {
        Ext.ux.TreeDocs.superclass.constructor.call(this, config);
    };

    /**
     *  Allow: Extend more the Tree. / Add Mask to TreePanel
     *  Author: HACKPRO TM / OutpostMM
     *  Post: - / 43645 #6
     */
    Ext.extend(Ext.ux.TreeDocs, Ext.tree.TreePanel, {
     maxNumber: 0,
     allowDrag: function(allow) {
            if (allow) {
                if ( (this.enableDD) || (this.enableDrag) ) {
                    this.dragZone = new Ext.tree.TreeDragZone(this, this.dragConfig || {
                        ddGroup: this.ddGroup || "TreeDD",
                        scroll: this.ddScroll
                    });

                }

            } else if (this.dragZone != undefined) {
             this.dragZone.unreg(); // Unregister the dragZone so Dragging is disabled.
            }

        },
        allowDrop: function(allow) {
            if (allow) {
                if ( (this.enableDD) || (this.enableDrop) ) {
                    this.dropZone = new Ext.tree.TreeDropZone(this, this.dropConfig || {
                        ddGroup: this.ddGroup || "TreeDD", 
                        appendOnly: this.ddAppendOnly === true
                    });

                }

            } else if (this.dropZone != undefined) {
                this.dropZone.unreg(); // Unregister the dropZone so Dropping is disabled.
            }

        },
        
        /**
         * Allow: Recursive Count Nodes write by HACKPRO TM based in the zesh code.
         * Author: zesh
         * Post: 1930 #3
         */
        recursiveCount: function(node) {
         if (node.hasChildNodes()) {
          var totalNodes = 0;
          
             // Recurse on all child nodes of the current node.
             for (var i = 0; i < node.childNodes.length; i++) {
              totalNodes += node.childNodes.length;
                 this.recursiveCount(node.childNodes[i]);
             }
             
            }
            
            return totalNodes;
            
        },
        
        recursiveMaxID: function(node) {
         if (node.hasChildNodes()) {
             // Recurse on all child nodes of the current node.
             for (var i = 0; i < node.childNodes.length; i++) {
              var nID = node.childNodes[i].id;
              
              if (nID) {
               nID = parseInt(nID.replace(/\D/g, ''), 10);
              } else {
               nID = -1;
              }
              
              if (nID > this.maxNumber) {
               this.maxNumber = nID;
              }
              
              this.recursiveMaxID(node.childNodes[i]);
             }
             
            }
            
            return this.maxNumber;
            
        },
        
        getMaxID: function() {
         var rootTree = this.getRootNode();
         this.recursiveMaxID(rootTree);
         
         return this.recursiveMaxID(rootTree);
        },
        
        getCountNodes: function() {
         var rootTree = this.getRootNode();
         var len = rootTree.childNodes.length + this.recursiveCount(rootTree) + 1;
         
         return len;
        },
        
        removeChildren: function(node) {
            while (node.firstChild) {
                var c = node.firstChild;
             node.removeChild(c);
             c.destroy();
         }
         
     },
     
     putRootNode: function(node, jsonData) {
      this.removeChildren(node);
      this.getRootNode().appendChild(jsonData);
     },
     
     /**
      * @cfg {Boolean} mask Indicates if the tree panel should have a loadmask applied when loading nodes
      */
     mask: false,
     maskObject: null,
     /**
      * @cfg {Object} maskConfig A configuration object that can be applied to the loadmask.
      */
     maskConfig: { msg: "Cargando..." },
 
     // init
     initComponent:function() {
         // call parent
         Ext.ux.TreeDocs.superclass.initComponent.apply(this, arguments);
 
         if (this.mask) { this.on('render', this.createMask, this); }
     }, // end initComponent
 
     /**
      * @private
      */
     createMask: function() {
      if (this.maskObject == null) {
       var mask = new Ext.LoadMask(this.getEl(), this.maskConfig);
      } else {
       var mask = new Ext.LoadMask(this.maskObject, this.maskConfig);
      }     
         
         this.getLoader().on('beforeload', mask.show, mask);
         this.getLoader().on('load', mask.hide, mask);
     }

    });

    Ext.reg("treedocs", Ext.ux.TreeDocs);

viernes, junio 04, 2010

JavaScript image combobox v2.1 by Marghoob Suleman

Encontré hace algunos días, este gran Jquery Plugin, hice un pequeño skin para el mismo y adicione un pequeño código para arreglar un problema al cargar con elementos no visibles inicialmente.

El código original lo pueden descargar de http://www.marghoobsuleman.com/jquery-image-dropdown

Como se vería el skin que hice


Pueden descargar el skin desde aquí

No olviden visitar la web del autor.

domingo, mayo 23, 2010

Generic Code to use any SQLite DB with C#

How use SQLite Database with C# and System.Data.SQLite using SharpDevelop


Original by Zhanshan Dong

/*
 * Original by Zhanshan Dong
 * A little modified by HACKPRO TM.
 * Created: 22/05/2010
 * Hour: 10:20 p.m.
 * 
 */

using System;
using System.Windows.Forms;
using System.Data;
using System.Data.SQLite;
using System.IO;

public class ConnSQLite {
 
 private SQLiteConnection Conn;
 private SQLiteCommand Cmd;
 private bool isConnect = false;

 public ConnSQLite(string dbName, string connection) {
  
  bool hasDBFile = File.Exists(dbName);
  
  if (hasDBFile == true) {
   ConnectDB(connection);
   Cmd = CreateCMD();
  } else {
   isConnect = false;
  }
  
 }

 ~ConnSQLite() {
  
  if (isConnect == true) {
   Cmd.Dispose();
   Conn.Close();
  }
  
 }

 private void ConnectDB(string connection) {
  
  Conn = new SQLiteConnection(connection);
  Conn.Open();
  
  if (Conn.State.ToString() == "Open") {
   isConnect = true;
  } else {
   isConnect = false;
  }
  
 }

 private SQLiteCommand CreateCMD() {
  
  SQLiteCommand cmd = new SQLiteCommand();
  return Conn.CreateCommand();
  
 }

 private void disposeCMD(SQLiteCommand cmd) {
  
  cmd.Dispose();
  
 }
 
 public bool IsConnect() {
  
  return isConnect;
  
 }

 public void ExecuteNonQuerySQL(string SQL) {
  
  Cmd.CommandText = SQL;
  Cmd.ExecuteNonQuery();
  
 }

 public SQLiteDataReader ExecuteQuerySQL(string SQL, SQLiteCommand cmd) {
  
  cmd.CommandText = SQL;
  return cmd.ExecuteReader();
  
 }
 
 public DataTable RecordSet(string SQL) {
  
  SQLiteDataAdapter da = new SQLiteDataAdapter(SQL, Conn);
  DataSet ds = new DataSet();
  DataTable dt = new DataTable();
  ds.Reset();
  da.Fill(ds);
  dt = ds.Tables[0];
  return dt;
  
 }
 
 public double MAXId(string SQL) {
  
  SQLiteCommand cmd = CreateCMD();
  SQLiteDataReader dbReader = ExecuteQuerySQL(SQL, cmd);
  double rowVal = 0;
  
  if (dbReader.HasRows == true) {
   while (dbReader.Read()) {
    rowVal = dbReader.GetDouble(0);
   }
   
  } else {
   rowVal = 0;
  }
  
  dbReader.Close();
  cmd.Dispose();
  return rowVal;
  
 }

 public int getRowCount(string SQL) {
  
  SQLiteCommand cmd = CreateCMD();
  SQLiteDataReader dbReader = ExecuteQuerySQL(SQL, cmd);
  int rowCount = 0;
  
  if (dbReader.HasRows) {
   dbReader.Read();
   rowCount = dbReader.GetInt32(0);
  }
  
  dbReader.Close();
  cmd.Dispose();
  return rowCount;
  
 }

}

Prevent Loop No-Leaf Nodes in ExtJS TreeView

Using this overrider function you can stop the loading waiting loop in the TreeView.

    /**
     *  Allow: Stop loading No-Leaf Node.
     *  Author: HACKPRO TM
     *  Post: -
     */
    Ext.override(Ext.tree.TreeLoader, {
     load: function(A, B) {
      if (this.clearOnLoad) {
    while (A.firstChild) {
     A.removeChild(A.firstChild);
    }
    
   }
   
   if (this.doPreload(A)) {
    if (typeof B == "function") {
     B();
    }
    
   } else if (this.dataUrl || this.url) {
    this.requestData(A, B);
   } else if (typeof B == "function") {
    B();
   }
   
  }
  
    });
    
    Ext.override(Ext.tree.TreeNodeUI, {
     updateExpandIcon : function() {
         if (this.rendered) {
             var n = this.node, c1, c2;
             var cls = n.isLast() ? "x-tree-elbow-end" : "x-tree-elbow";
             var hasChild = n.hasChildNodes();
             var cls1 = '';
             
             if (hasChild || n.attributes.expandable || n.attributes.isFolder) {
                 if (n.expanded) {
                     cls1 = "-minus";
                     c1 = "x-tree-node-collapsed";
                     c2 = "x-tree-node-expanded";
                 } else {
                     cls1 = "-plus";
                     c1 = "x-tree-node-expanded";
                     c2 = "x-tree-node-collapsed";
                 }
                 
                 if (this.wasLeaf) {
                     this.removeClass("x-tree-node-leaf");
                     this.wasLeaf = false;
                 }
                 
                 if (n.attributes.isFolder && n.attributes.leaf) {
                  cls1 = '';
                 }
                 
                 cls += cls1;
                 
                 if (this.c1 != c1 || this.c2 != c2) {
                     Ext.fly(this.elNode).replaceClass(c1, c2);
                     this.c1 = c1; this.c2 = c2;
                 }
                 
             } else {
                 if (!this.wasLeaf) {
                     Ext.fly(this.elNode).replaceClass("x-tree-node-expanded", "x-tree-node-leaf");
                     delete this.c1;
                     delete this.c2;
                     this.wasLeaf = true;
                 }
                 
             }
             
             var ecc = "x-tree-ec-icon " + cls;
             
             if (this.ecc != ecc) {
                 this.ecNode.className = ecc;
                 this.ecc = ecc;
             }
             
         }
         
     }
     
 });

sábado, mayo 09, 2009

Encrypt/Decrypt String with Javascript


Encrypt/Decrypt string using Javascript, based in the PHP class and VB Code.

Copyrigth HACKPRO TM (C) 2008-2009


How to use:

$Security.Encrypt_Text(string, [utf8]);
$Security.Decrypt_Text(string, [utf8]);


/**
*********************************************************  
*    Reservados todos los derechos HACKPRO TM © 2005    *
*-------------------------------------------------------*
* Siéntase libre para usar esta clase en sus páginas,   *
* con tal de que TODOS los créditos permanecen intactos.*
* Sólo ladrones deshonrosos transmite el código que los *
* programadores REALES escriben con difícultad y libre- *
* mente lo comparten quitando los comentarios y diciendo*
* que ellos escribieron el código.                      *
*-------------------------------------------------------*
* Encrypts and Decrypts a chain.                        *
*-------------------------------------------------------*
*-------------------------------------------------------*
* Original in VB for:    Kelvin C. Perez.               *
* E-Mail:                kelvin_perez@msn.com           *
* WebSite:               http://home.coqui.net/punisher *
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++*
* Programmed in PHP for: Heriberto Mantilla Santamaría. *
* E-Mail:                heri_05-hms@mixmail.com        *
* WebSite:               www.geocities.com/hackprotm/   *
*-------------------------------------------------------*
* IMPORTANT NOTE                                        *
*-------------------------------------------------------*
* Feel free to use this class in your pages, provided   *
* ALL credits remain intact. Only dishonorable thieves  *
* download code that REAL programmers work hard to write*
* and freely share with their programming peers, then   *
* remove the comments and claim that they wrote the     *
* code.                                                 *
*-------------------------------------------------------*
*  @author Heriberto Mantilla Santamaría                *
*  @version 1.1                                         *
*********************************************************
*         All Rights Reserved HACKPRO TM © 2005         *
*********************************************************
*/

/**
* Portion of this code is the php.js
* ----------------------------------------------------------------------------------- 
* More info at: http://phpjs.org
* 
* This is version: 2.47
* php.js is copyright 2009 Kevin van Zonneveld.
* 
* Portions copyright Brett Zamir (http://brettz9.blogspot.com), Kevin van
* Zonneveld (http://kevin.vanzonneveld.net), Onno Marsman, Michael White
* (http://getsprink.com), Waldo Malqui Silva, Paulo Ricardo F. Santos, Jack,
* Philip Peterson, Jonas Raoni Soares Silva (http://www.jsfromhell.com), Ates
* Goral (http://magnetiq.com), Legaev Andrey, Martijn Wieringa, Nate,
* Philippe Baumann, Enrique Gonzalez, Webtoolkit.info
* (http://www.webtoolkit.info/), Ash Searle (http://hexmen.com/blog/), travc,
* Jani Hartikainen, Carlos R. L. Rodrigues (http://www.jsfromhell.com), d3x,
* Johnny Mast (http://www.phpvrouwen.nl), marrtins, Alex, Erkekjetter, Andrea
* Giammarchi (http://webreflection.blogspot.com), GeekFG
* (http://geekfg.blogspot.com), Mirek Slugen, Breaking Par Consulting Inc
* (http://www.breakingpar.com/bkp/home.nsf/0/87256B280015193F87256CFB006C45F7),
* Ole Vrijenhoek, Josh Fraser
* (http://onlineaspect.com/2007/06/08/auto-detect-a-time-zone-with-javascript/),
* Steven Levithan (http://blog.stevenlevithan.com), Public Domain
* (http://www.json.org/json2.js), Marc Palau, mdsjack
* (http://www.mdsjack.bo.it), David, Arpad Ray (mailto:arpad@php.net),
* Pellentesque Malesuada, Thunder.m, Aman Gupta, Tyler Akins
* (http://rumkin.com), Alfonso Jimenez (http://www.alfonsojimenez.com), Karol
* Kowalski, AJ, Caio Ariede (http://caioariede.com), Sakimori, gorthaur,
* Steve Hilder, john (http://www.jd-tech.net), David James, class_exists,
* noname, Steve Clay, T. Wild, Hyam Singer
* (http://www.impact-computing.com/), kenneth, Subhasis Deb, Pyerre, Felix
* Geisendoerfer (http://www.debuggable.com/felix), djmix, Jon Hohle, Douglas
* Crockford (http://javascript.crockford.com), mktime, sankai, Sanjoy Roy,
* 0m3r, Marco, Thiago Mata (http://thiagomata.blog.com), madipta, Gilbert,
* ger, Bryan Elliott, David Randall, Ozh, T0bsn, Tim Wiel, Peter-Paul Koch
* (http://www.quirksmode.org/js/beat.html), Bayron Guevara, MeEtc
* (http://yass.meetcweb.com), Brad Touesnard, XoraX (http://www.xorax.info),
* echo is bad, J A R, duncan, Paul, Linuxworld, Marc Jansen, Der Simon
* (http://innerdom.sourceforge.net/), Lincoln Ramsay, LH, Francesco, Slawomir
* Kaniecki, marc andreu, Eric Nagel, Bobby Drake, rezna, Mick@el, Pierre-Luc
* Paour, Martin Pool, Kirk Strobeck, Pul, Luke Godfrey, Christian Doebler,
* YUI Library:
* http://developer.yahoo.com/yui/docs/YAHOO.util.DateLocale.html, Blues at
* http://hacks.bluesmoon.info/strftime/strftime.js, penutbutterjelly, Gabriel
* Paderni, Blues (http://tech.bluesmoon.info/), Anton Ongson, Simon Willison
* (http://simonwillison.net), Kristof Coomans (SCK-CEN Belgian Nucleair
* Research Centre), Saulo Vallory, hitwork, Norman "zEh" Fuchs, sowberry,
* Yves Sucaet, Nick Callen, ejsanders, johnrembo, dptr1988, Pedro Tainha
* (http://www.pedrotainha.com), T.Wild, uestla, Valentina De Rosa,
* strcasecmp, strcmp, metjay, DxGx, Alexander Ermolaev
* (http://snippets.dzone.com/user/AlexanderErmolaev), ChaosNo1, Andreas,
* Garagoth, Manish, Cord, Matt Bradley, Robin, FremyCompany, Tim de Koning,
* taith, Victor, stensi, Arno, Nathan, nobbler, Mateusz "loonquawl" Zalega,
* ReverseSyntax, Jalal Berrami, Francois, Scott Cariss, Tod Gentille, baris
* ozdil, booeyOH, Cagri Ekin, Luke Smith (http://lucassmith.name), Ben Bryan,
* Leslie Hoare, Andrej Pavlovic, Dino, mk.keck, Rival, Diogo Resende, Yannoo,
* gabriel paderni, FGFEmperor, jakes, Atli Þór, Howard Yeend, Allan Jensen
* (http://www.winternet.no), Benjamin Lupton
* 
* Dual licensed under the MIT (MIT-LICENSE.txt)
* and GPL (GPL-LICENSE.txt) licenses.
* 
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
* 
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
* 
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL KEVIN VAN ZONNEVELD BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/

(function() {
if (typeof(Security) == "undefined") {
var Security = function() {
if (window == this || !this.init) {
return new Security();
} else {
return this.init();
}
};
}

var nEncKey, cText, nCharSize, cSourceText;

Security.prototype = {
init : function() {
},

Encrypt_Text : function(cText, utf8) {


if (utf8) {
var eText = this.utf8_encode(cText);
} else {
var eText = cText;
}

var nCounter = 0;
// Get a random Number between 1 and 100. This will be the multiplier
// for the Ascii value of the characters.
this.nEncKey = this.intval((100 * this.Rnd()) + 1);

// Loop until we get a random value betwee 5 and 7. This will be
// the lenght (with leading zeros) of the value of the Characters.
this.nCharSize = 0;
var nUpperBound = 10;
var nLowerBound = 5;
this.nCharSize = this.intval((nUpperBound - nLowerBound + 1) * this.Rnd() + nLowerBound);
// Encrypt the Size of the characters and convert it to String.
// This size has to be standard so we always get the right character.
var cCharSize = this.fEncryptedKeySize(this.nCharSize);
// Convert the KeyNumber to String with leading zeros.
var cEncKey = this.NumToString(this.nEncKey, this.nCharSize);
// Get the text to encrypt and it's size.
var cEncryptedText = '';
var nTextLenght = this.strlen(eText);

// Loop thru the text one character at the time.
for (nCounter = 1; nCounter <= nTextLenght; nCounter++) {
// Get the Next Character.
var cChar = this.Mid(eText, nCounter, 1);
// Get Ascii Value of the character multplied by the Key Number.
var nChar = this.ord(cChar) * this.nEncKey;
// Get the String version of the Ascii Code with leading zeros.
// using the Random generated Key Lenght.
var cChar2 = this.NumToString(nChar, this.nCharSize);
// Add the Newly generated character to the encrypted text variable.
cEncryptedText += cChar2;
}

// Separate the text in two to insert the enc
// key in the middle of the string.
var nLeft = this.intval(this.strlen(cEncryptedText) / 2);
var cLeft = this.strleft(cEncryptedText, nLeft);
var nRight = this.strlen(cEncryptedText) - nLeft;
var cRight = this.strright(cEncryptedText, nRight);
// Add a Dummy string at the end to fool people.
var cDummy = this.CreateDummy();
// Add all the strings together to get the final result.
this.cSourceText = cEncryptedText;
this.InsertInTheMiddle(this.cSourceText, cEncKey);
this.InsertInTheMiddle(this.cSourceText, cCharSize);
cEncryptedText = this.cSourceText;
cEncryptedText = this.CreateDummy() + cEncryptedText + this.CreateDummy();

return cEncryptedText;

},

Decrypt_Text : function(cText, utf8) {

var cTempText = cText;
var cDecryptedText = '';
var len = this.strlen(cTempText);
var nChar2 = 0;
var nChar = 0;

this.cText = '';

// Replace alpha characters for zeros.
for (var nCounter = 1; nCounter <= len; nCounter++) {
cChar = this.Mid(cTempText, nCounter, 1);
if (this.is_numeric(cChar) == true) {
this.cText += cChar;
} else {
this.cText += '0';
}

}

// Get the size of the key.
this.cText = this.strleft(this.cText, this.strlen(this.cText) - 4);
this.cText = this.strright(this.cText, this.strlen(this.cText) - 4);
this.nCharSize = 0;
this.Extract_Char_Size(this.cText, this.nCharSize);
this.Extract_Enc_Key(this.cText, this.nCharSize, this.nEncKey);

// Decrypt the Size of the encrypted characters.
nTextLenght = this.strlen(this.cText);
// Loop thru text in increments of the Key Size.
var nCounter = 1;

do { // Get a Character the size of the key.
cChar = this.Mid(this.cText, nCounter, this.nCharSize);
// Get the value of the character.
nChar = this.Val(cChar);
// Divide the value by the Key to get the real value of the
// character.
if (this.nEncKey > 0) {
nChar2 = parseInt(nChar / this.nEncKey);
}

// Convert the value to the character.
cChar2 = this.chr(nChar2);
cDecryptedText += cChar2;
nCounter += parseInt(this.nCharSize);
} while (nCounter <= nTextLenght);

// Clear any unwanted spaces and show the decrypted text.
cDecryptedText = this.trim(cDecryptedText);

if (utf8) {
return this.utf8_decode(cDecryptedText);
} else {
return cDecryptedText;
}

},

Extract_Char_Size : function(cText, nCharSize) {

// Get the half left side of the text.
var nLeft = this.intval(this.strlen(cText) / 2);
var cLeft = this.strleft(cText, nLeft);
// Get the half right side of the text.
var nRight = this.strlen(cText) - nLeft;
var cRight = this.strright(cText, nRight);

// Get the key from the text.
var nKeyEnc = this.Val(this.strright(cLeft, 2));
var nKeySize = this.Val(this.strleft(cRight, 2));

if (nKeyEnc >= 5) {
this.nCharSize = parseInt(nKeySize) + parseInt(nKeyEnc);   
} else {
this.nCharSize = parseInt(nKeySize) - parseInt(nKeyEnc); 
}

this.cText = this.strleft(cLeft, this.strlen(cLeft) - 2) +
this.strright(cRight, this.strlen(cRight) - 2);

},

Extract_Enc_Key : function(cText, nCharSize, nEncKey) {

var cEncKey = '';

// Get the real size of the text (without the previously
// stored character size).
var nLenght = this.strlen(cText) - nCharSize;
// Get the half left and half right sides of the text.
var nLeft = this.intval(nLenght / 2);
var cLeft = this.strleft(cText, nLeft);
var nRight = nLenght - nLeft;
var cRight = this.strright(cText, nRight);
// Get the key from the text.
cEncKey = this.Mid(cText, nLeft + 1, nCharSize);
// Get the numeric value of the key.
this.nEncKey = this.Val(this.trim(cEncKey));
// Get the real text to decrypt (left side + right side).
this.cText = cLeft + '' + cRight;
},

fEncryptedKeySize : function(nKeySize) {

var nLowerBound = 0;
var nKeyEnc = this.intval((nKeySize - nLowerBound + 1) * this.Rnd() + nLowerBound);

if (nKeyEnc >= 5) {
nKeySize = parseInt(nKeySize) - parseInt(nKeyEnc); 
} else {
nKeySize = parseInt(nKeySize) + parseInt(nKeyEnc); 
}

return this.NumToString(nKeyEnc, 2) + this.NumToString(nKeySize, 2);

},

NumToString : function(nNumber, nZeros) {

// Check that the zeros to fill are not smaller than the actual size.
var cNumber = this.trim(nNumber);
var nLenght = this.strlen(cNumber);

if (nZeros < nLenght) {
nZeros = 0;
}

var nUpperBound = 122;
var nLowerBound = 65;
var nCounter = 0;

for (nCounter = 1; nCounter <= (nZeros - nLenght); nCounter++) { // Add a zero in front of the string until we reach the desired size.
var lCreated = false;

do {
nNumber = this.intval((nUpperBound - nLowerBound + 1) * this.Rnd() + nLowerBound);
if ((nNumber > 90) && (nNumber < 97)) {
lCreated = false; 
} else {
lCreated = true; 
}

} while (lCreated == false);

cChar = this.chr(nNumber);
cNumber = cChar + cNumber;
}

// Return the resulting string.
return cNumber;

},

InsertInTheMiddle : function(cSourceText, cTextToInsert) {

// Get the half left and half right sides of the text.
var nLeft = this.intval(this.strlen(cSourceText) / 2);
var cLeft = this.strleft(cSourceText, nLeft);
var nRight = this.strlen(cSourceText) - nLeft;
var cRight = this.strright(cSourceText, nRight);
// Insert cTextToString in the middle of cSourceText.
this.cSourceText = cLeft + cTextToInsert + cRight;

},

CreateDummy : function() {

var nUpperBound = 122;
var nLowerBound = 48;
var nCounter = 0;
var cDummy = '';

for (nCounter = 1; nCounter <= 4; nCounter++) {
var lCreated = false;

do {
nDummy = this.intval((nUpperBound - nLowerBound + 1) * this.Rnd() + nLowerBound)
if (((nDummy > 57) && (nDummy < 65)) || ((nDummy > 90) && (nDummy < 97))) {
lCreated = false; 
} else {
lCreated = true; 
}

} while (lCreated == false);

cDummy += this.chr(nDummy);

}

return cDummy;

},

is_numeric : function(mixed_var) {
// More info at: http://phpjs.org
// This is version: 2.47 php.js is copyright 2009 Kevin van Zonneveld.

if (mixed_var === '') {
return false;
}

return !isNaN(mixed_var * 1);

},

strlen : function(string) {

var str = string + '';

return str.length;

},

strright : function(tmp, nRight) {

var len = this.strlen(tmp);

if (nRight == 0){
str = ''; 
} else if (nRight < len) {
str = this.Mid(tmp, len - nRight + 1, len); 
}

return str;

},

strleft : function(tmp, nLeft) {

var len = this.strlen(tmp);

if (nLeft == 0){
str = ''; 
} else if (nLeft < len) {
str = this.Mid(tmp, 1, nLeft); 
}

return str;

},

Mid : function(tmp, start, length) {

str = this.substr(tmp, start - 1, length);
return str;

},

substr : function(f_string, f_start, f_length) {

var str = f_string + '';

return str.substr(f_start, f_length);

},

trim : function(f_string) {

var str = f_string + '';

while (str.charAt(0) == (" ")) {
str = str.substring(1);
}

while (str.charAt(str.length-1) == " ") {
str = str.substring(0,str.length-1);
}

return str;

},

Rnd : function() {

do {
var tmp = Math.abs( Math.tan( Math.random() ) );
} while ((tmp > 1) || (tmp < 0));

tmp = this.Mid(tmp, 1, 8);

return tmp;

},

Val : function(tmp) {

var length = this.strlen(tmp);
var tmp2 = 0;

for (i = 1; i <= length; i++) {
var tmp1 = this.substr(tmp, i - 1, 1);
if (this.is_numeric(tmp1) == true) {
tmp2 += tmp1;
}

}

return this.intval(tmp2);

},

intval : function(mixed_var, base) {
// More info at: http://phpjs.org
// This is version: 2.47 php.js is copyright 2009 Kevin van Zonneveld.

var tmp;
var type = typeof(mixed_var);
if (type == 'boolean') {
if (mixed_var == true) {
return 1;
} else {
return 0;
}

} else if (type == 'string') {
tmp = parseInt(mixed_var * 1);
if (isNaN(tmp) || !isFinite(tmp)) {
return 0;
} else {
return tmp.toString(base || 10);
}

} else if (type == 'number' && isFinite(mixed_var)) {
return Math.floor(mixed_var);
} else {
return 0;
}

},

chr : function(ascii) {

return String.fromCharCode(ascii);

},

ord : function(string) {

string += '';
return string.charCodeAt(0);

},

utf8_encode : function(string) {
// More info at: http://phpjs.org
// This is version: 2.47 php.js is copyright 2009 Kevin van Zonneveld.

string = (string + '').replace(/\r\n/g, "\n").replace(/\r/g, "\n");
var utftext = "";
var start, end;
var stringl = 0;
start = end = 0;
stringl = string.length;

for (var n = 0; n < stringl; n++) {
var c1 = string.charCodeAt(n);
var enc = null;

if (c1 < 128) {
end++;
} else if ((c1 > 127) && (c1 < 2048)) {
enc = String.fromCharCode((c1 >> 6) | 192)
+ String.fromCharCode((c1 & 63) | 128);
} else {
enc = String.fromCharCode((c1 >> 12) | 224)
+ String.fromCharCode(((c1 >> 6) & 63) | 128)
+ String.fromCharCode((c1 & 63) | 128);
}

if (enc != null) {
if (end > start) {
utftext += string.substring(start, end);
}

utftext += enc;
start = end = n + 1;
}

}

if (end > start) {
utftext += string.substring(start, string.length);
}

return utftext;

},

utf8_decode : function(str_data) {
// More info at: http://phpjs.org
// This is version: 2.47 php.js is copyright 2009 Kevin van Zonneveld.

var tmp_arr = [], i = 0, ac = 0, c1 = 0, c2 = 0, c3 = 0;
str_data += '';

while (i < str_data.length) {
c1 = str_data.charCodeAt(i);
if (c1 < 128) {
tmp_arr[ac++] = String.fromCharCode(c1);
i++;
} else if ((c1 > 191) && (c1 < 224)) {
c2 = str_data.charCodeAt(i + 1);
tmp_arr[ac++] = String.fromCharCode(((c1 & 31) << 6)
| (c2 & 63));
i += 2;
} else {
c2 = str_data.charCodeAt(i + 1);
c3 = str_data.charCodeAt(i + 2);
tmp_arr[ac++] = String.fromCharCode(((c1 & 15) << 12)
| ((c2 & 63) << 6) | (c3 & 63));
i += 3;
}

}

return tmp_arr.join('');

}

};

window.$Security = Security();

})();

jueves, mayo 07, 2009

TreeCombo (ExtJS)






Pequeña extensión para extender un Tree con un Combo.




































/**
* @author Possible author is roytmana
* @version 1.0
* @class Ext.ux.TreeCombo
* @extends Ext.form.ComboBox
*+++++++++++++++++++++++++++++++++++++++
*          Edit by HACKPRO TM
*+++++++++++++++++++++++++++++++++++++++
*/

Ext.ux.TreeCombo = Ext.extend(Ext.form.ComboBox, {

lastKeys : '',
admitLeaf: true,
treeTypeAhead: false,

initList : function() {
if (this.list != undefined) {
return;
}

if (this.editable !== false) {
this.el.on("keyup", this.onKeyUpTree, this)
}

if (this.treeTypeAhead) {
this.taTask = new Ext.util.DelayedTask(this.onTreeTypeAhead, this);
}

var tConf = {
floating : true,
listeners : {
click : this.onNodeClick,
scope : this
},

alignTo : function(el, pos) {
this.setPagePosition(this.el.getAlignToXY(el, pos));
},
keys : [{
key : 9,
fn : function() {
this.onNodeClick(this.list.getSelectionModel()
.getSelectedNode());
},
scope : this
}, {
key : 27,
fn : function() {
this.collapse();
this.focus(true, true);
},
scope : this
}]

};

if (this.treeConfig) {
Ext.applyIf(tConf, this.treeConfig);
if (this.treeConfig.listeners) {
Ext.applyIf(tConf.listeners, this.treeConfig.listeners);
}

if (tConf.loader) {
tConf.loader.on("load", this.onTreeLoad, this);
}

}

this.list = new Ext.tree.TreePanel(tConf);

if (!this.list.rendered) {
var lw = this.listWidth || Math.max(this.wrap.getWidth(), this.minListWidth);
this.list.render(document.body);
this.list.setWidth(lw);
this.list.alignTo(this.wrap, this.listAlign);
this.innerList = this.list.body;
this.innerList.setWidth(lw);
this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
this.list.hide();
}

},

doQuery : function(q, forceAll) {
this.expand();
},

collapseIf : function(e) {
if (!e.within(this.wrap) && !e.within(this.list.el)) {
this.collapse();
}

},

selectNext : function() {
var sm = this.list.getSelectionModel();
if (!sm.getSelectedNode()) {
sm.select(this.list.getRootNode());
}

sm.selectNext();
},

selectPrev : function() {
var sm = this.list.getSelectionModel();
if (!sm.getSelectedNode()) {
sm.select(this.list.getRootNode());
}

sm.selectPrevious();
},

onViewClick : function(doFocus) {
this.collapse();
if (doFocus !== false) {
this.el.focus();
}

},

findNode : function(value, node, rootPath, like) {
var field = this;

if (node == null || node == undefined) {
node = field.list.getRootNode();
}

var value = value;

if (node.isLoaded() == true) {
if (node.childNodes.length > 0) {
field.nodeFound = node.findChild('text', value);

if (field.nodeFound == null || field.nodeFound == undefined) {
node.cascade(function() {
if (this.text == value) {
if ( (this.getPath('text') == rootPath) ||
(rootPath == null) ) {
field.nodeFound = this;
}

} else if (like == true) {
var str = this.text;
var found = str.indexOf(value);

if (found >= 0) {
field.nodeFound = this;
}

}

if (field.nodeFound != null
&& field.nodeFound != undefined) {
return false;
}

});

}

}

} else {
field.list.getLoader().load(node, function(loader, node, rootPath, like) {
node.loaded = true;
field.nodeFound = field.findNode(value, node, rootPath, like);
});

}

return field.nodeFound;
},

setValue : function(value, rootPath) {
if (this.list == undefined) {
this.initList();
}

if (value == '') {
this.setRawValue('');
return;
}

this.el.removeClass(this.emptyClass);
var nodeFound = this.findNode(value, null, rootPath, null);

if (nodeFound != null && nodeFound != undefined) {
text = nodeFound.attributes['text'];

if (text.length == 0) {
text = (!empty(this.value) ? this.value : '');
}

if ( (nodeFound.isLeaf() == false) &&
(this.admitLeaf == false) ) {
return;
}

var nodePath = nodeFound.getPath();
var treeRoot = this.list.getRootNode();
treeRoot.reload();
this.list.expandPath(nodePath);
this.list.selectPath(nodePath);

this.setRawValue(text);

if (this.hiddenField) {
this.hiddenField.value = value;
}

} else {
this.setRawValue();
var treeroot = this.list.getRootNode();
treeroot.reload();
this.list.collapseAll();
}

},

setValueFromNode : function(node) {
this.setRawValue(node.attributes.text);
if (this.hiddenField) {
this.hiddenField.value = node.id;
}

},

openCombo : function(){
this.onTriggerClick();
},

onTreeTypeAhead : function(){
var newValue = this.getRawValue();
var selStart = this.getRawValue().length;

if (selStart <= 0) {
this.setRawValue('');
var treeroot = this.list.getRootNode();
treeroot.reload();
this.list.collapseAll();
return;
}

var nodeFound = this.findNode(newValue, null, null, true);

if (nodeFound != null && nodeFound != undefined) {
text = nodeFound.attributes['text'];
var len = text.length;

if (selStart != len) {

if ( (nodeFound.isLeaf() == false) &&
(this.admitLeaf == false) ) {
return;
}

var nodePath = nodeFound.getPath();
var treeRoot = this.list.getRootNode();
treeRoot.reload();
this.list.expandPath(nodePath);
this.list.selectPath(nodePath);

this.setRawValue(text);
this.selectText(selStart, text.length);

if (this.hiddenField) {
this.hiddenField.value = newValue;
}

this.focus.defer(10, this);
}

}

},

onKeyUpTree : function(A) {
if (this.editable !== false && !A.isSpecialKey()) {
this.lastKeys = A.getKey();

if (this.treeTypeAhead && (this.lastKeys == Ext.EventObject.BACKSPACE || this.lastKeys == Ext.EventObject.DELETE) ) {
this.taTask.delay(250);
return;
}

if (this.treeTypeAhead) {
this.onTreeTypeAhead();
}

}

},

onNodeClick : function(node, e) {
if ( (node.isLeaf() == false) &&
(this.admitLeaf == false) ) {
return;
}

var oldValue = this.getValue();
this.setValueFromNode(node);
this.collapse();
if (this.treeTypeAhead) {
this.focus(true, false);
} else {
this.focus(false, false);
}

this.fireEvent('select', this, oldValue, this.getValue());
this.fireEvent('change', this, node);
this.fireEvent('rootchanged', node);
},

onTreeLoad : function(loader, node, response) {
if (this.list.getRootNode() == node) {
if (this.hiddenField && this.hiddenField.value
&& this.hiddenField.value != '') {
var n = this.list.getNodeById(this.hiddenField.value);
if (n) {
n.select();
this.setRawValue(n.attributes.text);
} else {
this.list.getSelectionModel().clearSelections();
this.setRawValue('');
this.hiddenField.value = '';
}

}

}

}

});

Ext.reg('treecombo', Ext.ux.TreeCombo);

martes, abril 14, 2009

LexMath


Sencilla clase desarrollada en PHP basada en el código de dreamvb desarrollado en VB 6.

Como usarla:

include_once('modLex.php');

$Calc = new LexMath;
$Calc->init(); // Inicializa la clase.

Para agregar variables, se escriben de la siguiente forma:


$Calc->AddVar("pi", 3.14159265358979);
$Calc->AddVar("e", 2.71828182845905);

Y finalmente para realizar los cálculos se de realizar de la siguiente forma:

$Calc->Calc("area = 180");
$Calc->Calc("4 * Atn(1)")
$Calc->Calc("(-5 + 3)")
$Calc->Calc("Rnd(8)")
/**
 *  
 *  By DreamVB
 *  Programado en PHP por HACKPRO TM (C) 2008-2010
 *  Versión: 1.0
 *  Todos los Derechos Reservados
 *  ------------------------------------------
 *  @author Heriberto Mantilla Santamaría
 *  @version 1.0
 */

// Token Types
define('LERROR', -1);
define('NONE', 0);
define('DELIMITER', 1);
define('DIGIT', 2);
define('LSTRING', 3);
define('VARIABLE', 4);
define('IDENTIFIER', 6);
define('HEXDIGIT', 5);
define('FINISHED', 7);

// Relational
define('GE', 1); // Greator than or equal to
define('NE', 2); // Not equal to
define('LE', 3); // Less than or equal to

// Bitwise
define('cAND', 4);
define('cOR', 5);

// Bitshift
define('shr', 6);
define('shl', 7);
define('cXor', 8);
define('cIMP', 9);
define('cEqv', 11);
// define('cINC', 12);

class LexMath {
    var $Str_Ops = 'AND,OR,XOR,MOD,DIV,SHL,SHR,IMP,EQV,NOT';
    var $Str_Funcs = 'ABS,ATN,COS,EXP,LOG,LN,RND,ROUND,SGN,SIN,SQR,TAN,SUM,IIF';

    // We use this to store variables
    var $Token; // Current processing token
    var $TOK_TYPE; // Used to idenfiy the tokens
    var $Look_Pos; // Current processing char pointer
    var $ExprLine; // The Expression line to scan
    var $lVarCount;
    var $CalclMsg;
    var $lVars;

    function Abort($code, $aStr = '') {

        switch ($code) {
            case 0:
                $lMsg = 'Variable indefinida [' . $aStr . '] ';
                break;

            case 1:
                $lMsg = 'División por cero';
                break;

            case 2:
                $lMsg = 'Falta paréntesis ")" ';
                break;

            case 3:
                $lMsg = 'Dígito inválido [' . $aStr . '] ';
                break;

            case 4:
                $lMsg = 'Carácter desconocido [' . $aStr . '] ';
                break;

            case 5:
                $lMsg = 'La Variable [' . $aStr . ']  es un identificador y no puede usarse.';
                break;

            case 6:
                $lMsg = "Expresión prevista.";
                break;

            case 7:
                $lMsg = 'Valor hexagesimal inválido [0x' . strtoupper($aStr) . '] ';
                break;

        }

        $this->CalclMsg = $lMsg;
        $this->Look_Pos = strlen($this->ExprLine) + 1;

    }

    function AddVar($name, $lValue = 0) {

        // Add a new variable along with the variables value.
        $this->lVars[$name] = $lValue; // Add variable name and varaible data
        $this->lVarCount = $this->lVarCount + 1; // INC variable Counter

    }

    function Atom() {
        
        $atom = '';
        // Check for Digits ,Hexadecimal,Functions, Variables
        switch ($this->TOK_TYPE) {
            case HEXDIGIT: // Hexadecimal
                $Temp = trim($this->strright($this->Token, strlen($this->Token) - 2));

                if (strlen($Temp) == 0) {
                    $this->Abort(6);
                    return;
                } else
                    if ($this->isHex($Temp) == false) {
                        $this->Abort(7, $Temp);
                        return;
                    } else {
                        $atom = hexdec("&H" . $Temp);
                        $this->GetToken();
                    }

                    break;

            case IDENTIFIER: // Inbuilt Functions
                $atom = $this->CallIntFunc($this->Token);
                $this->GetToken();
                break;

            case DIGIT: // Digit const found

                if (is_numeric($this->Token) == false) {
                    $this->Abort(3, $this->Token); // Check we have a real digit
                    return;
                }

                $atom = $this->Token; // Return the value
                $this->GetToken(); // Get next token
                break;

            case LERROR: // Expression phase error
                $this->Abort(0, $this->Token); // Show error message
                break;
                return;

            case VARIABLE: // Variable found

                if ($this->FindVarIdx($this->Token) == -1) {
                    $this->Abort(0, $this->Token);
                    return;
                }

                $atom = $this->GetVarData($this->Token); // Return variable value
                $this->GetToken(); // Get next token
                break;

        }

        return $atom;

    }

    function CallIntFunc($sFunction) {

        // ABS,ATN,COS,EXP,LOG,RND,ROUND,SGN,SIN,SQR,TAN,IFF
        switch (strtoupper($sFunction)) {
            case 'ABS':
                $this->GetToken();
                $Temp = $this->Exp6();
                $CallIntF = abs($Temp);
                $this->PushBack();
                break;

            case 'ATN':
                $this->GetToken();
                $Temp = $this->Exp6();
                $CallIntF = atan($Temp);
                $this->PushBack();
                break;

            case 'COS':
                $this->GetToken();
                $Temp = $this->Exp6();
                $CallIntF = cos($Temp);
                $this->PushBack();
                break;

            case 'EXP':
                $this->GetToken();
                $Temp = $this->Exp6();
                $CallIntF = exp($Temp);
                $this->PushBack();
                break;

            case 'LOG':
                $this->GetToken();
                $Temp = $this->Exp6();
                $CallIntF = log10($Temp);
                $this->PushBack();
                break;

            case 'LN':
                $this->GetToken();
                $Temp = $this->Exp6();
                $CallIntF = log($Temp);
                $this->PushBack();
                break;

            case 'RND':
                $this->GetToken();
                $Temp = $this->Exp6();
                $CallIntF = $this->Rnd($Temp);
                $this->PushBack();
                break;

            case 'ROUND':
                $this->GetToken();
                $Temp = $this->Exp6();
                $CallIntF = round($Temp);
                $this->PushBack();
                break;

            case 'SGN':
                $this->GetToken();
                $Temp = $this->Exp6();
                $CallIntF = $this->Sgn($Temp);
                $this->PushBack();
                break;

            case 'SIN':
                $this->GetToken();
                $Temp = $this->Exp6();
                $CallIntF = sin($Temp);
                $this->PushBack();
                break;

            case 'SQR':
                $this->GetToken();
                $Temp = $this->Exp6();
                $CallIntF = sqrt($Temp);
                $this->PushBack();
                break;

            case 'TAN':
                $this->GetToken();
                $Temp = $this->Exp6();
                $CallIntF = tan(Temp);
                $this->PushBack();
                break;

            case 'SUM':
                $ArgList = $this->GetArgs();
                $Temp = 0;
                for ($X = 0; $X < count($ArgList); $X++) {
                    $Temp = $this->CDbl($Temp) + $this->CDbl($ArgList[$X]);
                }

                $this->GetToken();
                $CallIntF = $Temp;
                $this->PushBack();
                break;

            case 'IIF':
                $ArgList = $this->GetArgs();
                $CallIntF = $this->IIf($ArgList[0], $ArgList[1], $ArgList[2]);
                $this->PushBack();
                break;

        }

        return $CallIntF;

    }

    function ClearVar() {

        $this->lVarCount = 0;
        unset($this->lVars); // Resize variable stack

    }

    function Calc($Expression, $printExpression = false) {

        $this->CalclMsg = '';
        $this->ExprLine = $Expression; // Store the expression to scan
        $this->Look_Pos = 1; // Default state of char pos
        $this->GetToken(); // Kick start and Get the first token.

        if (($this->TOK_TYPE == FINISHED) or (strlen(trim($Expression)) == 0)) {
            return null;
            exit;
        } else {
            $Return = $this->Exp0();
        }

        if ($printExpression == true) {
            $Return = $Expression . ' : ' . $Return;
        }

        if (strlen($this->CalclMsg) > 0) {
            return 'NaN';
        } else {
            return $Return;
        }

    }

    function Sgn($val) {
        return $val == 0 ? 0 : ($val > 0 ? 1 : -1);
    }

    function Mid($tmp, $start, $length = '') {

        $start -= 1;
        if (is_string($length) == true) {
            $length = strlen($tmp);
        }

        $str = substr($tmp, $start, $length);
        return $str;

    }

    function strleft($tmp, $nLeft) {
        $len = strlen($tmp);

        if ($nLeft == 0) {
            $str = '';
        } else
            if ($nLeft < $len) {
                $str = $this->Mid($tmp, 1, $nLeft);
            }

        return $str;

    }

    function strright($tmp, $nRight) {

        $len = strlen($tmp);

        if ($nRight == 0) {
            $str = '';
        } else
            if ($nRight < $len) {
                $str = $this->Mid($tmp, $len - $nRight + 1, $len);
            }

        return $str;

    }

    function CDbl(&$Temp) {

        settype($varTemp, 'double');
        $varTemp = $Temp;
        return $varTemp;

    }

    function Rnd() {
        srand(); // Initialize random-number generator.
        do {
            $tmp = abs(tan(rand()));
        } while (($tmp > "1") || ($tmp < "0"));

        $tmp = $this->Mid($tmp, 1, 8);
        return $tmp;

    }

    function IIf($tst, $cmp, $bad) {

        return (($tst == $cmp) ? $cmp : $bad);

    }

    function Exp0() {

        // Assignments
        if ($this->TOK_TYPE == VARIABLE) {
            // Store temp type and token
            // we first need to check if the variable name is not an identifier
            if ($this->isIdent($this->Token) == true) {
                $this->Abort(5, $this->Token);
            }

            $Tmp_tokType = $this->TOK_TYPE;
            $Tmp_Token = $this->Token;
            // Locate the variables index
            $Var_Idx = $this->FindVarIdx($this->Token);
            // If we have an invaild var index -1 we Must add a new variable

            if ($Var_Idx == null) {
                // Add the new variable
                $this->AddVar($this->Token);
                // Now get the variable index again
                $Var_Idx = $this->FindVarIdx($this->Token);
            } else {
                $Exp0 = $this->Exp1();
                return $Exp0;
            }

            // Get the next token
            $this->GetToken();

            if ($this->Token != '=') {
                $this->PushBack(); // Move expr pointer back
                $this->Token = $Tmp_Token; // Restore temp token
                $this->TOK_TYPE = $Tmp_tokType; // Restore temp token type
            } else {
                // Carry on processing the expression
                $this->GetToken();
                // Set the variables value
                $Temp = $this->Exp1();
                $this->SetVar($Var_Idx, $Temp);
                $Exp0 = $Temp;
            }

        }

        $Exp0 = $this->Exp1();
        return $Exp0;

    }

    function Exp1() {

        // Relational operators
        $Relops = chr(GE) . chr(NE) . chr(LE) . '<>=!' . chr(0);
        $Exp1 = $this->Exp2();

        $op = $this->Token; // Get operator
        if (empty($op) == true) {
            $rPos = -1;
        } else {
            $rPos = strpos($Relops, $op); // Check for other ops in token <> =
        }


        if ($rPos > 0) {
            $this->GetToken(); // Get next token
            $Temp = $this->Exp2(); // Store temp val

            switch ($op) {
                case '<': // less {
                    $Exp1 = $this->CDbl($Exp1) < $this->CDbl($Temp);
                    break;

                case '>': // greator than
                    $Exp1 = $this->CDbl($Exp1) > $this->CDbl($Temp);
                    break;

                case chr(NE):
                    $Exp1 = $this->CDbl($Exp1) != $this->CDbl($Temp);
                    break;

                case chr(LE):
                    $Exp1 = $this->CDbl($Exp1) <= $this->CDbl($Temp);
                    break;

                case chr(GE):
                    $Exp1 = $this->CDbl($Exp1) >= $this->CDbl($Temp);
                    break;

                case '=': // equal to
                    $Exp1 = $this->CDbl($Exp1) == $this->CDbl($Temp);
                    break;

                case '!':
                    $Exp1 = !$this->CDbl($Temp);
                    break;

            }

            // op = Token
        }

        return $Exp1;

    }

    function Exp2() {

        // Add or Subtact two terms
        $Exp2 = $this->Exp3();
        $op = $this->Token; // Get operator

        while (($op == "+") or ($op == "-")) {
            $this->GetToken(); // Get next token
            $Temp = $this->Exp3(); // Temp value
            // Peform the expresion for the operator

            switch ($op) {
                case '-':
                    $Exp2 = $this->CDbl($Exp2) - $this->CDbl($Temp);
                    break;

                case '+':
                    $Exp2 = $this->CDbl($Exp2) + $this->CDbl($Temp);
                    break;

            }

            $op = $this->Token;
        }

        return $Exp2;

    }

    function Exp3() {

        // Multiply or Divide two factors
        $Exp3 = $this->Exp4();
        $op = $this->Token; // Get operator

        while (($op == "*") or ($op == "/") or ($op == "\\") or ($op == "%")) {
            $this->GetToken(); // Get next token
            $Temp = $this->Exp4(); // Temp value
            // Peform the expresion for the operator

            switch ($op) {
                case '*':
                    $Exp3 = $this->CDbl($Exp3) * $this->CDbl($Temp);
                    break;

                case '/':

                    if ($Temp == 0) {
                        $this->Abort(1);
                        return;
                    }

                    $Exp3 = $this->CDbl($Exp3) / $this->CDbl($Temp);
                    break;

                case "\\":

                    if ($Temp == 0) {
                        $this->Abort(1);
                        return;
                    }

                    $Exp3 = intval($this->CDbl($Exp3) / $this->CDbl($Temp));
                    break;

                case '%':

                    if ($Temp == 0) {
                        $this->Abort(1);
                        return;
                    }

                    $Exp3 = $this->CDbl($Exp3) % $this->CDbl($Temp);
                    break;

            }

            $op = $this->Token;
        }

        return $Exp3;

    }

    function Exp4() {

        // Bitwise operators ^ | & || &&
        $BitWOps = chr(cAND) . chr(cOR) . chr(shl) . chr(shr) . chr(cXor) . chr(cIMP) .
            chr(cEqv) . '^|&' . chr(0);
        $Exp4 = $this->Exp5();

        $op = $this->Token; // Get operator
        if (empty($op) == true) {
            $rPos = -1;
        } else {
            $rPos = strpos($BitWOps, $op); // Check for other ops in token <> =
        }

        if ($rPos === false) {

        } else {
            $this->GetToken(); // Get next token
            $Temp = $this->Exp5(); // Store temp val

            switch ($op) {
                case '^': // Excompnent
                    $Exp4 = pow($this->CDbl($Exp4), $this->CDbl($Temp));
                    break;

                case '&':
                    $Exp4 = $this->CDbl($Exp4) . $this->CDbl($Temp);
                    break;

                case chr(cAND):
                    $Exp4 = $this->CDbl($Exp4) and $this->CDbl($Temp);
                    break;

                case chr(cOR):
                    $Exp4 = $this->CDbl($Exp4) or $this->CDbl($Temp);
                    break;

                case chr(shl):
                    // Bitshift Shift left
                    $Exp4 = $this->CDbl($Exp4) * (pow(2, $this->CDbl($Temp)));
                    break;

                case chr(shr):
                    // bitshift right
                    $Exp4 = $this->CDbl($Exp4) / (pow(2, $this->CDbl($Temp)));
                    break;

                case chr(cXor):
                    // Xor
                    $Exp4 = $this->CDbl($Exp4) xor $this->CDbl($Temp);
                    break;

                case chr(cIMP):
                    // IMP
                    //$Exp4 = $this->CDbl($Exp4) Imp $this->CDbl($Temp);
                    break;

                case chr(cEqv):
                    // EQV
                    //$Exp4 = $this->CDbl($Exp4) Eqv $this->CDbl($Temp);
                    break;

            }

        }

        return $Exp4;

    }

    function Exp5() {

        $op = '';
        // Unary +,-

        if (($this->TOK_TYPE == DELIMITER) and (($this->Token == "+") or ($this->Token ==
            "-"))) {
            $op = $this->Token;
            $this->GetToken();
        }

        $Exp5 = $this->Exp6();
        if ($op == '-') {
            $Exp5 = -$this->CDbl($Exp5);
        }

        return $Exp5;

    }

    function Exp6() {

        // Check for Parenthesized expression
        if ($this->Token == '(') {
            $this->GetToken(); // Get next token
            $Exp6 = $this->Exp1();
            // Check that we have a closeing bracket
            if ($this->Token != ')') {
                $this->Abort(2);
                return;
            }

            $this->GetToken(); // Get next token

        } else {
            $Exp6 = $this->atom();
        }

        return $Exp6;

    }

    function FindVarIdx($name) {

        // Locate a variables position in the variables array
        $idx = null; // Bad position

        foreach ($this->lVars as $key => $value) {
            if (strtolower($key) == strtolower($name)) {
                $idx = $key;
                break;
            }

        }

        return $idx;

    }

    function GetArgs() {

        $this->GetToken();
        $Count = 0;
        $Temp = array();

        if ($this->Token != '(') {
            return;
        }

        do {

            $this->GetToken();
            $Value = $this->Exp1();
            $Temp[$Count] = $Value;
            $Count += 1;

        } while ($this->Token != ")");

        $Count = 0;
        $Value = 0;

        return $Temp;

    }

    function GetToken() {

        $Temp = '';
        // This is the main part of the pharser and is used to.
        // Identfiy all the tokens been scanned and return th correct token type

        // Clear current token info
        $this->Token = '';
        $this->TOK_TYPE = NONE;
        $Exit = false;

        if ($this->Look_Pos > strlen($this->ExprLine)) {
            $this->TOK_TYPE = FINISHED;
            return;
        }

        // Above exsits the function if we are passed expr len
        while (($this->Look_Pos <= strlen($this->ExprLine)) and ($this->isWhite($this->
            Mid($this->ExprLine, $this->Look_Pos, 1)) == true)) {
            // Skip over white spaces. and stay within the expr len
            $this->Look_Pos += 1; // INC

            if ($this->Look_Pos > strlen($this->ExprLine)) {
                $Exit = true;
                break;
            }

        }

        if ($Exit == true) {
            return;
        }

        // Some little test I was doing to do Increment/Decrement operators -- ++
        if (($this->Mid($this->ExprLine, $this->Look_Pos, 1) == '+') or ($this->Mid($this->
            ExprLine, $this->Look_Pos, 1) == '-')) {
            if (($this->Mid($this->ExprLine, $this->Look_Pos + 1, 1) == '+') or ($this->Mid
                ($this->ExprLine, $this->Look_Pos + 1, 1) == '-')) {
                $Temp = $this->Mid($this->ExprLine, 1, $this->Look_Pos - 1);

                if ($this->Mid($this->ExprLine, $this->Look_Pos + 1, 1) == '+') {
                    $dTmp = $this->GetVarData($Temp) + 1;
                } else
                    if ($this->Mid($this->ExprLine, $this->Look_Pos + 1, 1) == '-') {
                        $dTmp = $this->GetVarData($Temp) - 1;
                    }

                $this->SetVar($this->FindVarIdx($Temp), $dTmp);
                $this->Token = $Temp;
                return;
            }

        }
        // //

        if (($this->Mid($this->ExprLine, $this->Look_Pos, 1) == '&') or ($this->Mid($this->
            ExprLine, $this->Look_Pos, 1) == '|')) {
            // Bitwise code, I still got some work to do on this yet but it does the ones
            //  that are listed below fine

            switch ($this->Mid($this->ExprLine, $this->Look_Pos, 1)) {
                case '&':

                    if ($this->Mid($this->ExprLine, $this->Look_Pos + 1, 1) == '&') {
                        $this->Look_Pos += 2;
                        $this->Token = chr(cAND);
                        return;
                    } else {
                        $this->Look_Pos += 1;
                        $this->Token = '&';
                        return;
                    }

                    break;

                case '|':

                    if ($this->Mid($this->ExprLine, $this->Look_Pos + 1, 1) == '|') {
                        $this->Look_Pos += 2;
                        $this->Token = chr(cOR);
                        return;
                    } else {
                        $this->Look_Pos += 1;
                        $this->Token = '|';
                        return;
                    }

                    $this->TOK_TYPE = DELIMITER;
                    break;

            }

        }

        if (($this->Mid($this->ExprLine, $this->Look_Pos, 1) == '<') or ($this->Mid($this->
            ExprLine, $this->Look_Pos, 1) == '>')) {
            // Check for Relational operators < > <= >= <>
            // check for not equal to get first op <

            switch ($this->Mid($this->ExprLine, $this->Look_Pos, 1)) {
                case '<':

                    if ($this->Mid($this->ExprLine, $this->Look_Pos + 1, 1) == '>') {
                        // Not Equal to
                        $this->Look_Pos += 2;
                        $this->Token = Chr(NE);
                        return;
                    } else
                        if ($this->Mid($this->ExprLine, $this->Look_Pos + 1, 1) == '=') {
                            // Less { of equal to
                            $this->Look_Pos += 2;
                            $this->Token = chr(LE);
                            return;
                        } else
                            if ($this->Mid($this->ExprLine, $this->Look_Pos + 1, 1) == '<') {
                                // Bitshift left
                                $this->Look_Pos += 2;
                                $this->Token = chr(shl);
                                return;
                            } else {
                                // Less {
                                $this->Look_Pos += 2;
                                $this->Token = '<';
                                return;
                            }

                            break;

                case '>':

                    if ($this->Mid($this->ExprLine, $this->Look_Pos + 1, 1) == '=') {
                        // Greator than or equal to
                        $this->Look_Pos += 2;
                        $this->Token = chr(GE);
                        return;
                    } else
                        if ($this->Mid($this->ExprLine, $this->Look_Pos + 1, 1) == '>') {
                            $this->Look_Pos += 2;
                            $this->Token = chr(shr);
                            return;
                        } else {
                            // Greator than
                            $this->Look_Pos = $this->Look_Pos + 1;
                            $this->Token = '>';
                            return;
                        }

                        $this->TOK_TYPE = DELIMITER;
                    break;

            }

        }

        if ($this->IsDelim($this->Mid($this->ExprLine, $this->Look_Pos, 1)) == true) {
            // Check if we have a Delimiter ;,+-<>^=(*)/\%
            $this->Token = $this->Token . $this->Mid($this->ExprLine, $this->Look_Pos, 1); // Get next char
            $this->Look_Pos = $this->Look_Pos + 1; // INC
            $this->TOK_TYPE = DELIMITER; // Delimiter Token type
        } else
            if ($this->isDigit($this->Mid($this->ExprLine, $this->Look_Pos, 1)) == true) {
                // See if we are dealing with a Hexadecimal Value

                if ($this->Mid($this->ExprLine, $this->Look_Pos + 1, 1) == 'x') {

                    while ($this->isAlphaNum($this->Mid($this->ExprLine, $this->Look_Pos, 1)) == true) {
                        $this->Token = $this->Token . $this->Mid($this->ExprLine, $this->Look_Pos, 1);
                        $this->Look_Pos += 1;
                        $this->TOK_TYPE = HEXDIGIT;
                    }

                    return;
                }

                // Check if we are dealing with only digits 0 .. 9
                while ($this->IsDelim($this->Mid($this->ExprLine, $this->Look_Pos, 1)) == false) {
                    $this->Token .= $this->Mid($this->ExprLine, $this->Look_Pos, 1); // Get next char
                    $this->Look_Pos += 1; // INC
                    if ($this->Look_Pos > strlen($this->ExprLine)) {
                        break;
                    }

                }

                $this->TOK_TYPE = DIGIT; // Digit token type

            } else
                if ($this->isAlpha($this->Mid($this->ExprLine, $this->Look_Pos, 1)) == true) {
                    // Check if we have strings Note no string support in this version
                    //  this is only used for variables.

                    while ($this->IsDelim($this->Mid($this->ExprLine, $this->Look_Pos, 1)) == false) {
                        $this->Token .= $this->Mid($this->ExprLine, $this->Look_Pos, 1);
                        $this->Look_Pos += 1; // INC
                        // tok_type = VARIABLE
                        $this->TOK_TYPE = LSTRING; // String token type
                        if ($this->Look_Pos > strlen($this->ExprLine)) {
                            break;
                        }
                    }

                } else {
                    $this->Abort(4, $this->Mid($this->ExprLine, $this->Look_Pos, 1));
                    $this->TOK_TYPE = FINISHED;
                }

                if ($this->TOK_TYPE == LSTRING) {
                    // check for identifiers

                    if ($this->isIdent($this->Token) == true) {
                        $OkToken = false;

                        switch (strtoupper($this->Token)) {
                            case 'AND':
                                $this->Token = chr(cAND);
                                $OkToken = true;
                                break;

                            case 'OR':
                                $this->Token = chr(cOR);
                                $OkToken = true;
                                break;

                            case 'NOT':
                                $this->Token = '!';
                                $OkToken = true;
                                break;

                            case 'IMP':
                                $this->Token = chr(cIMP);
                                $OkToken = true;
                                break;

                            case 'EQV':
                                $this->Token = chr(cEqv);
                                $OkToken = true;
                                break;

                            case 'DIV':
                                $this->Token = "\\";
                                $OkToken = true;
                                break;

                            case 'MOD':
                                $this->Token = "%";
                                $OkToken = true;
                                break;

                            case 'XOR':
                                $this->Token = chr(cXor);
                                $OkToken = true;
                                break;

                            case 'SHL':
                                $this->Token = chr(shl);
                                break;

                            case 'SHR':
                                $this->Token = chr(shr);
                                break;
                        }

                        if ($OkToken == true) {
                            return;
                        }

                        $this->TOK_TYPE = DELIMITER;
                        return;

                    } else
                        if ($this->IsIdentFunc($this->Token) == true) {
                            $this->TOK_TYPE = IDENTIFIER;
                            //  GetToken
                            return;
                        } else {
                            $this->TOK_TYPE = VARIABLE;
                            return;
                        }

                }

    }

    function GetVarData($name) {

        // Return data from a variable stored in the variable stack
        return $this->lVars[$name];

    }

    function init() {

        $this->lVarCount = 0;
        unset($this->lVars);
        $this->lVars = array();

    }

    function isAlpha($c) {

        // Return true if we only have letters a-z  A-Z
        if ((strtoupper($c) >= "A") and (strtoupper($c) <= "Z")) {
            return true;
        } else {
            return false;
        }

    }

    function isAlphaNum($c) {

        return ($this->isDigit($c) or $this->isAlpha($c));

    }

    function IsDelim($c) {

        // Return true if we have a Delimiter
        $mystring = ' ;,+-<>^=(*)/\%&|!';
        $pos = strpos($mystring, $c);

        if ($pos === false) {
            $pos = false;
        } else {
            $pos = true;
        }

        return $pos;

    }

    function isDigit($c) {

        // Return true when we only have a digit
        if (is_numeric($c) == false) {
            return false;
        }

        if (($c >= '0') and ($c <= '9')) {
            return true;
        } else {
            return false;
        }

    }

    function isHex($HexVal) {

        for ($X = 1; $X <= strlen($HexVal); $X++) {
            $c = $this->Mid($HexVal, $X, 1);

            switch (strtoupper($c)) {
                case 0:
                    $isHex = true;
                    break;
                case 1:
                    $isHex = true;
                    break;
                case 2:
                    $isHex = true;
                    break;
                case 3:
                    $isHex = true;
                    break;
                case 4:
                    $isHex = true;
                    break;
                case 5:
                    $isHex = true;
                    break;
                case 6:
                    $isHex = true;
                    break;
                case 7:
                    $isHex = true;
                    break;
                case 8:
                    $isHex = true;
                    break;
                case 9:
                    $isHex = true;
                    break;
                case 'A':
                    $isHex = true;
                    break;
                case 'B':
                    $isHex = true;
                    break;
                case 'C':
                    $isHex = true;
                    break;
                case 'D':
                    $isHex = true;
                    break;
                case 'E':
                    $isHex = true;
                    break;
                case 'F':
                    $isHex = true;
                    break;
                default:
                    $isHex = false;
                    break;
            }

        }

        return $isHex;

    }

    function isIdent($sIdentName) {

        $Idents = split(",", $this->Str_Ops);
        $IsIdentF = false;

        for ($X = 0; $X < count($Idents); $X++) {

            if (strtolower($Idents[$X]) == strtolower($sIdentName)) {
                $IsIdentF = true;
                break;
            }

        }

        $X = 0;
        unset($Idents);
        return $IsIdentF;

    }

    function IsIdentFunc($sIdentName) {

        $Idents = split(",", $this->Str_Funcs);
        $IsIdentF = false;

        for ($X = 0; $X < count($Idents); $X++) {

            if (strtolower($Idents[$X]) == strtolower($sIdentName)) {
                $IsIdentF = true;
                break;
            }

        }

        $X = 0;
        unset($Idents);
        return $IsIdentF;

    }

    function isWhite($c) {

        // Return true if we find a white space.
        if (($c == ' ') or ($c == chr(9))) {
            return true;
        } else {
            return false;
        }

    }

    function PushBack() {

        $tok_len = strlen($this->Token);
        $this->Look_Pos -= $tok_len;

    }

    function SetVar($vIdx, $lData = 0) {

        // Set a variables value, by using the variables index vIdx
        $this->lVars[$vIdx] = $lData;

    }
}