ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
Validator.php
Go to the documentation of this file.
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 
49 {
50  var $_type;
51  var $_style;
53  var $_blank;
54  var $_incell;
68  var $_parser;
69 
71  {
72  $this->_parser = $parser;
73  $this->_type = 0x01; // FIXME: add method for setting datatype
74  $this->_style = 0x00;
75  $this->_fixedList = false;
76  $this->_blank = false;
77  $this->_incell = false;
78  $this->_showprompt = false;
79  $this->_showerror = true;
80  $this->_title_prompt = "\x00";
81  $this->_descr_prompt = "\x00";
82  $this->_title_error = "\x00";
83  $this->_descr_error = "\x00";
84  $this->_operator = 0x00; // default is equal
85  $this->_formula1 = "";
86  $this->_formula2 = "";
87  }
88 
89  function setPrompt($promptTitle = "\x00", $promptDescription = "\x00", $showPrompt = true)
90  {
91  $this->_showprompt = $showPrompt;
92  $this->_title_prompt = $promptTitle;
93  $this->_descr_prompt = $promptDescription;
94  }
95 
96  function setError($errorTitle = "\x00", $errorDescription = "\x00", $showError = true)
97  {
98  $this->_showerror = $showError;
99  $this->_title_error = $errorTitle;
100  $this->_descr_error = $errorDescription;
101  }
102 
103  function allowBlank()
104  {
105  $this->_blank = true;
106  }
107 
108  function onInvalidStop()
109  {
110  $this->_style = 0x00;
111  }
112 
113  function onInvalidWarn()
114  {
115  $this->_style = 0x01;
116  }
117 
118  function onInvalidInfo()
119  {
120  $this->_style = 0x02;
121  }
122 
123  function setFormula1($formula)
124  {
125  // Parse the formula using the parser in Parser.php
126  $error = $this->_parser->parse($formula);
127  if (PEAR::isError($error)) {
128  return $this->_formula1;
129  }
130 
131  $this->_formula1 = $this->_parser->toReversePolish();
132  if (PEAR::isError($this->_formula1)) {
133  return $this->_formula1;
134  }
135  return true;
136  }
137 
138  function setFormula2($formula)
139  {
140  // Parse the formula using the parser in Parser.php
141  $error = $this->_parser->parse($formula);
142  if (PEAR::isError($error)) {
143  return $this->_formula2;
144  }
145 
146  $this->_formula2 = $this->_parser->toReversePolish();
147  if (PEAR::isError($this->_formula2)) {
148  return $this->_formula2;
149  }
150  return true;
151  }
152 
153  function _getOptions()
154  {
155  $options = $this->_type;
156  $options |= $this->_style << 3;
157  if($this->_fixedList)
158  $options |= 0x80;
159  if($this->_blank)
160  $options |= 0x100;
161  if(!$this->_incell)
162  $options |= 0x200;
163  if($this->_showprompt)
164  $options |= 0x40000;
165  if($this->_showerror)
166  $options |= 0x80000;
167  $options |= $this->_operator << 20;
168 
169  return $options;
170  }
171 
172  function _getData()
173  {
174  $title_prompt_len = strlen($this->_title_prompt);
175  $descr_prompt_len = strlen($this->_descr_prompt);
176  $title_error_len = strlen($this->_title_error);
177  $descr_error_len = strlen($this->_descr_error);
178 
179  $formula1_size = strlen($this->_formula1);
180  $formula2_size = strlen($this->_formula2);
181 
182  $data = pack("V", $this->_getOptions());
183  $data .= pack("vC", $title_prompt_len, 0x00) . $this->_title_prompt;
184  $data .= pack("vC", $title_error_len, 0x00) . $this->_title_error;
185  $data .= pack("vC", $descr_prompt_len, 0x00) . $this->_descr_prompt;
186  $data .= pack("vC", $descr_error_len, 0x00) . $this->_descr_error;
187 
188  $data .= pack("vv", $formula1_size, 0x0000) . $this->_formula1;
189  $data .= pack("vv", $formula2_size, 0x0000) . $this->_formula2;
190 
191  return $data;
192  }
193 }
194 
195 /*class Spreadsheet_Excel_Writer_Validation_List extends Spreadsheet_Excel_Writer_Validation
196 {
197  function Spreadsheet_Excel_Writer_Validation_list()
198  {
199  parent::Spreadsheet_Excel_Writer_Validation();
200  $this->_type = 0x03;
201  }
202 
203  function setList($source, $incell = true)
204  {
205  $this->_incell = $incell;
206  $this->_fixedList = true;
207 
208  $source = implode("\x00", $source);
209  $this->_formula1 = pack("CCC", 0x17, strlen($source), 0x0c) . $source;
210  }
211 
212  function setRow($row, $col1, $col2, $incell = true)
213  {
214  $this->_incell = $incell;
215  //$this->_formula1 = ...;
216  }
217 
218  function setCol($col, $row1, $row2, $incell = true)
219  {
220  $this->_incell = $incell;
221  //$this->_formula1 = ...;
222  }
223 }*/
224 
225 ?>