Validator.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. //require_once('PEAR.php');
  25. // Possible operator types
  26. /*
  27. FIXME: change prefixes
  28. */
  29. define("OP_BETWEEN", 0x00);
  30. define("OP_NOTBETWEEN", 0x01);
  31. define("OP_EQUAL", 0x02);
  32. define("OP_NOTEQUAL", 0x03);
  33. define("OP_GT", 0x04);
  34. define("OP_LT", 0x05);
  35. define("OP_GTE", 0x06);
  36. define("OP_LTE", 0x07);
  37. /**
  38. * Baseclass for generating Excel DV records (validations)
  39. *
  40. * @author Herman Kuiper
  41. * @category FileFormats
  42. * @package Spreadsheet_Excel_Writer
  43. */
  44. class Spreadsheet_Excel_Writer_Validator
  45. {
  46. var $_type;
  47. var $_style;
  48. var $_fixedList;
  49. var $_blank;
  50. var $_incell;
  51. var $_showprompt;
  52. var $_showerror;
  53. var $_title_prompt;
  54. var $_descr_prompt;
  55. var $_title_error;
  56. var $_descr_error;
  57. var $_operator;
  58. var $_formula1;
  59. var $_formula2;
  60. /**
  61. * The parser from the workbook. Used to parse validation formulas also
  62. * @var Spreadsheet_Excel_Writer_Parser
  63. */
  64. var $_parser;
  65. function Spreadsheet_Excel_Writer_Validator(&$parser)
  66. {
  67. $this->_parser = $parser;
  68. $this->_type = 0x01; // FIXME: add method for setting datatype
  69. $this->_style = 0x00;
  70. $this->_fixedList = false;
  71. $this->_blank = false;
  72. $this->_incell = false;
  73. $this->_showprompt = false;
  74. $this->_showerror = true;
  75. $this->_title_prompt = "\x00";
  76. $this->_descr_prompt = "\x00";
  77. $this->_title_error = "\x00";
  78. $this->_descr_error = "\x00";
  79. $this->_operator = 0x00; // default is equal
  80. $this->_formula1 = '';
  81. $this->_formula2 = '';
  82. }
  83. function setPrompt($promptTitle = "\x00", $promptDescription = "\x00", $showPrompt = true)
  84. {
  85. $this->_showprompt = $showPrompt;
  86. $this->_title_prompt = $promptTitle;
  87. $this->_descr_prompt = $promptDescription;
  88. }
  89. function setError($errorTitle = "\x00", $errorDescription = "\x00", $showError = true)
  90. {
  91. $this->_showerror = $showError;
  92. $this->_title_error = $errorTitle;
  93. $this->_descr_error = $errorDescription;
  94. }
  95. function allowBlank()
  96. {
  97. $this->_blank = true;
  98. }
  99. function onInvalidStop()
  100. {
  101. $this->_style = 0x00;
  102. }
  103. function onInvalidWarn()
  104. {
  105. $this->_style = 0x01;
  106. }
  107. function onInvalidInfo()
  108. {
  109. $this->_style = 0x02;
  110. }
  111. function setFormula1($formula)
  112. {
  113. // Parse the formula using the parser in Parser.php
  114. $error = $this->_parser->parse($formula);
  115. if (PEAR::isError($error)) {
  116. return $this->_formula1;
  117. }
  118. $this->_formula1 = $this->_parser->toReversePolish();
  119. if (PEAR::isError($this->_formula1)) {
  120. return $this->_formula1;
  121. }
  122. return true;
  123. }
  124. function setFormula2($formula)
  125. {
  126. // Parse the formula using the parser in Parser.php
  127. $error = $this->_parser->parse($formula);
  128. if (PEAR::isError($error)) {
  129. return $this->_formula2;
  130. }
  131. $this->_formula2 = $this->_parser->toReversePolish();
  132. if (PEAR::isError($this->_formula2)) {
  133. return $this->_formula2;
  134. }
  135. return true;
  136. }
  137. function _getOptions()
  138. {
  139. $options = $this->_type;
  140. $options |= $this->_style << 3;
  141. if ($this->_fixedList) {
  142. $options |= 0x80;
  143. }
  144. if ($this->_blank) {
  145. $options |= 0x100;
  146. }
  147. if (!$this->_incell) {
  148. $options |= 0x200;
  149. }
  150. if ($this->_showprompt) {
  151. $options |= 0x40000;
  152. }
  153. if ($this->_showerror) {
  154. $options |= 0x80000;
  155. }
  156. $options |= $this->_operator << 20;
  157. return $options;
  158. }
  159. function _getData()
  160. {
  161. $title_prompt_len = strlen($this->_title_prompt);
  162. $descr_prompt_len = strlen($this->_descr_prompt);
  163. $title_error_len = strlen($this->_title_error);
  164. $descr_error_len = strlen($this->_descr_error);
  165. $formula1_size = strlen($this->_formula1);
  166. $formula2_size = strlen($this->_formula2);
  167. $data = pack("V", $this->_getOptions());
  168. $data .= pack("vC", $title_prompt_len, 0x00) . $this->_title_prompt;
  169. $data .= pack("vC", $title_error_len, 0x00) . $this->_title_error;
  170. $data .= pack("vC", $descr_prompt_len, 0x00) . $this->_descr_prompt;
  171. $data .= pack("vC", $descr_error_len, 0x00) . $this->_descr_error;
  172. $data .= pack("vv", $formula1_size, 0x0000) . $this->_formula1;
  173. $data .= pack("vv", $formula2_size, 0x0000) . $this->_formula2;
  174. return $data;
  175. }
  176. }
  177. /*class Spreadsheet_Excel_Writer_Validation_List extends Spreadsheet_Excel_Writer_Validation
  178. {
  179. function Spreadsheet_Excel_Writer_Validation_list()
  180. {
  181. parent::Spreadsheet_Excel_Writer_Validation();
  182. $this->_type = 0x03;
  183. }
  184. function setList($source, $incell = true)
  185. {
  186. $this->_incell = $incell;
  187. $this->_fixedList = true;
  188. $source = implode("\x00", $source);
  189. $this->_formula1 = pack("CCC", 0x17, strlen($source), 0x0c) . $source;
  190. }
  191. function setRow($row, $col1, $col2, $incell = true)
  192. {
  193. $this->_incell = $incell;
  194. //$this->_formula1 = ...;
  195. }
  196. function setCol($col, $row1, $row2, $incell = true)
  197. {
  198. $this->_incell = $incell;
  199. //$this->_formula1 = ...;
  200. }
  201. }*/
  202. ?>