Subversion Repositories eFlore/Applications.cel

Rev

Rev 1604 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1604 raphael 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
class Spreadsheet_Excel_Writer_Validator
49
{
50
   var $_type;
51
   var $_style;
52
   var $_fixedList;
53
   var $_blank;
54
   var $_incell;
55
   var $_showprompt;
56
   var $_showerror;
57
   var $_title_prompt;
58
   var $_descr_prompt;
59
   var $_title_error;
60
   var $_descr_error;
61
   var $_operator;
62
   var $_formula1;
63
   var $_formula2;
64
    /**
65
    * The parser from the workbook. Used to parse validation formulas also
66
    * @var Spreadsheet_Excel_Writer_Parser
67
    */
68
    var $_parser;
69
 
3473 killian 70
    function __construct(&$parser)
1604 raphael 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
        }
160
        if ($this->_blank) {
161
            $options |= 0x100;
162
        }
163
        if (!$this->_incell) {
164
            $options |= 0x200;
165
        }
166
        if ($this->_showprompt) {
167
            $options |= 0x40000;
168
        }
169
        if ($this->_showerror) {
170
            $options |= 0x80000;
171
        }
172
      $options |= $this->_operator << 20;
173
 
174
      return $options;
175
   }
176
 
177
   function _getData()
178
   {
179
      $title_prompt_len = strlen($this->_title_prompt);
180
      $descr_prompt_len = strlen($this->_descr_prompt);
181
      $title_error_len = strlen($this->_title_error);
182
      $descr_error_len = strlen($this->_descr_error);
183
 
184
      $formula1_size = strlen($this->_formula1);
185
      $formula2_size = strlen($this->_formula2);
186
 
187
      $data  = pack("V", $this->_getOptions());
188
      $data .= pack("vC", $title_prompt_len, 0x00) . $this->_title_prompt;
189
      $data .= pack("vC", $title_error_len, 0x00) . $this->_title_error;
190
      $data .= pack("vC", $descr_prompt_len, 0x00) . $this->_descr_prompt;
191
      $data .= pack("vC", $descr_error_len, 0x00) . $this->_descr_error;
192
 
193
      $data .= pack("vv", $formula1_size, 0x0000) . $this->_formula1;
194
      $data .= pack("vv", $formula2_size, 0x0000) . $this->_formula2;
195
 
196
      return $data;
197
   }
198
}
199
 
200
/*class Spreadsheet_Excel_Writer_Validation_List extends Spreadsheet_Excel_Writer_Validation
201
{
202
   function Spreadsheet_Excel_Writer_Validation_list()
203
   {
204
      parent::Spreadsheet_Excel_Writer_Validation();
205
      $this->_type = 0x03;
206
   }
207
 
208
   function setList($source, $incell = true)
209
   {
210
      $this->_incell = $incell;
211
      $this->_fixedList = true;
212
 
213
      $source = implode("\x00", $source);
214
      $this->_formula1 = pack("CCC", 0x17, strlen($source), 0x0c) . $source;
215
   }
216
 
217
   function setRow($row, $col1, $col2, $incell = true)
218
   {
219
      $this->_incell = $incell;
220
      //$this->_formula1 = ...;
221
   }
222
 
223
   function setCol($col, $row1, $row2, $incell = true)
224
   {
225
      $this->_incell = $incell;
226
      //$this->_formula1 = ...;
227
   }
228
}*/
229
 
230
?>