Spreadsheet_Excel_Writer
[ class tree: Spreadsheet_Excel_Writer ] [ index: Spreadsheet_Excel_Writer ] [ all elements ]

Source for file Validator.php

Documentation is available at Validator.php

  1. <?php
  2. /*
  3. *  Module written by Herman Kuiper <herman@ozuzo.net>
  4. *
  5. *  License Information:
  6. *
  7. *    Spreadsheet_Excel_Writer:  A library for generating Excel Spreadsheets
  8. *    Copyright (c) 2002-2003 Xavier Noguer xnoguer@rezebra.com
  9. *
  10. *    This library is free software; you can redistribute it and/or
  11. *    modify it under the terms of the GNU Lesser General Public
  12. *    License as published by the Free Software Foundation; either
  13. *    version 2.1 of the License, or (at your option) any later version.
  14. *
  15. *    This library is distributed in the hope that it will be useful,
  16. *    but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  18. *    Lesser General Public License for more details.
  19. *
  20. *    You should have received a copy of the GNU Lesser General Public
  21. *    License along with this library; if not, write to the Free Software
  22. *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  23. */
  24.  
  25. //require_once('PEAR.php');
  26.  
  27. // Possible operator types
  28.  
  29. /*
  30. FIXME: change prefixes
  31. */
  32. define("OP_BETWEEN",    0x00);
  33. define("OP_NOTBETWEEN"0x01);
  34. define("OP_EQUAL",      0x02);
  35. define("OP_NOTEQUAL",   0x03);
  36. define("OP_GT",         0x04);
  37. define("OP_LT",         0x05);
  38. define("OP_GTE",        0x06);
  39. define("OP_LTE",        0x07);
  40.  
  41. /**
  42. * Baseclass for generating Excel DV records (validations)
  43. *
  44. @author   Herman Kuiper
  45. @category FileFormats
  46. @package  Spreadsheet_Excel_Writer
  47. */
  48. {
  49.    var $_type;
  50.    var $_style;
  51.    var $_fixedList;
  52.    var $_blank;
  53.    var $_incell;
  54.    var $_showprompt;
  55.    var $_showerror;
  56.    var $_title_prompt;
  57.    var $_descr_prompt;
  58.    var $_title_error;
  59.    var $_descr_error;
  60.    var $_operator;
  61.    var $_formula1;
  62.    var $_formula2;
  63.     /**
  64.     * The parser from the workbook. Used to parse validation formulas also
  65.     * @var Spreadsheet_Excel_Writer_Parser 
  66.     */
  67.     var $_parser;
  68.  
  69.     function Spreadsheet_Excel_Writer_Validator(&$parser)
  70.     {
  71.         $this->_parser       $parser;
  72.         $this->_type         = 0x01; // FIXME: add method for setting datatype
  73.         $this->_style        = 0x00;
  74.         $this->_fixedList    = false;
  75.         $this->_blank        = false;
  76.         $this->_incell       = false;
  77.         $this->_showprompt   = false;
  78.         $this->_showerror    = true;
  79.         $this->_title_prompt "\x00";
  80.         $this->_descr_prompt "\x00";
  81.         $this->_title_error  "\x00";
  82.         $this->_descr_error  "\x00";
  83.         $this->_operator     = 0x00; // default is equal
  84.         $this->_formula1    '';
  85.         $this->_formula2    '';
  86.     }
  87.  
  88.    function setPrompt($promptTitle "\x00"$promptDescription "\x00"$showPrompt = true)
  89.    {
  90.       $this->_showprompt $showPrompt;
  91.       $this->_title_prompt $promptTitle;
  92.       $this->_descr_prompt $promptDescription;
  93.    }
  94.  
  95.    function setError($errorTitle "\x00"$errorDescription "\x00"$showError = true)
  96.    {
  97.       $this->_showerror $showError;
  98.       $this->_title_error $errorTitle;
  99.       $this->_descr_error $errorDescription;
  100.    }
  101.  
  102.    function allowBlank()
  103.    {
  104.       $this->_blank = true;
  105.    }
  106.  
  107.    function onInvalidStop()
  108.    {
  109.       $this->_style = 0x00;
  110.    }
  111.  
  112.     function onInvalidWarn()
  113.     {
  114.         $this->_style = 0x01;
  115.     }
  116.  
  117.     function onInvalidInfo()
  118.     {
  119.         $this->_style = 0x02;
  120.     }
  121.  
  122.     function setFormula1($formula)
  123.     {
  124.         // Parse the formula using the parser in Parser.php
  125.         $error $this->_parser->parse($formula);
  126.         if (PEAR::isError($error)) {
  127.             return $this->_formula1;
  128.         }
  129.  
  130.         $this->_formula1 $this->_parser->toReversePolish();
  131.         if (PEAR::isError($this->_formula1)) {
  132.             return $this->_formula1;
  133.         }
  134.         return true;
  135.     }
  136.  
  137.     function setFormula2($formula)
  138.     {
  139.         // Parse the formula using the parser in Parser.php
  140.         $error $this->_parser->parse($formula);
  141.         if (PEAR::isError($error)) {
  142.             return $this->_formula2;
  143.         }
  144.  
  145.         $this->_formula2 $this->_parser->toReversePolish();
  146.         if (PEAR::isError($this->_formula2)) {
  147.             return $this->_formula2;
  148.         }
  149.         return true;
  150.     }
  151.  
  152.     function _getOptions()
  153.     {
  154.         $options $this->_type;
  155.         $options |= $this->_style << 3;
  156.         if ($this->_fixedList{
  157.             $options |= 0x80;
  158.         }
  159.         if ($this->_blank{
  160.             $options |= 0x100;
  161.         }
  162.         if (!$this->_incell{
  163.             $options |= 0x200;
  164.         }
  165.         if ($this->_showprompt{
  166.             $options |= 0x40000;
  167.         }
  168.         if ($this->_showerror{
  169.             $options |= 0x80000;
  170.         }
  171.       $options |= $this->_operator << 20;
  172.  
  173.       return $options;
  174.    }
  175.  
  176.    function _getData()
  177.    {
  178.       $title_prompt_len strlen($this->_title_prompt);
  179.       $descr_prompt_len strlen($this->_descr_prompt);
  180.       $title_error_len strlen($this->_title_error);
  181.       $descr_error_len strlen($this->_descr_error);
  182.  
  183.       $formula1_size strlen($this->_formula1);
  184.       $formula2_size strlen($this->_formula2);
  185.  
  186.       $data  pack("V"$this->_getOptions());
  187.       $data .= pack("vC"$title_prompt_len0x00$this->_title_prompt;
  188.       $data .= pack("vC"$title_error_len0x00$this->_title_error;
  189.       $data .= pack("vC"$descr_prompt_len0x00$this->_descr_prompt;
  190.       $data .= pack("vC"$descr_error_len0x00$this->_descr_error;
  191.  
  192.       $data .= pack("vv"$formula1_size0x0000$this->_formula1;
  193.       $data .= pack("vv"$formula2_size0x0000$this->_formula2;
  194.  
  195.       return $data;
  196.    }
  197. }
  198.  
  199. /*class Spreadsheet_Excel_Writer_Validation_List extends Spreadsheet_Excel_Writer_Validation
  200. {
  201.    function Spreadsheet_Excel_Writer_Validation_list()
  202.    {
  203.       parent::Spreadsheet_Excel_Writer_Validation();
  204.       $this->_type = 0x03;
  205.    }
  206.  
  207.    function setList($source, $incell = true)
  208.    {
  209.       $this->_incell = $incell;
  210.       $this->_fixedList = true;
  211.  
  212.       $source = implode("\x00", $source);
  213.       $this->_formula1 = pack("CCC", 0x17, strlen($source), 0x0c) . $source;
  214.    }
  215.  
  216.    function setRow($row, $col1, $col2, $incell = true)
  217.    {
  218.       $this->_incell = $incell;
  219.       //$this->_formula1 = ...;
  220.    }
  221.  
  222.    function setCol($col, $row1, $row2, $incell = true)
  223.    {
  224.       $this->_incell = $incell;
  225.       //$this->_formula1 = ...;
  226.    }
  227. }*/
  228.  
  229. ?>

Documentation generated on Mon, 11 Mar 2019 15:47:14 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.