|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 /* 00003 * Module written by Herman Kuiper <herman@ozuzo.net> 00004 * 00005 * License Information: 00006 * 00007 * Spreadsheet_Excel_Writer: A library for generating Excel Spreadsheets 00008 * Copyright (c) 2002-2003 Xavier Noguer xnoguer@rezebra.com 00009 * 00010 * This library is free software; you can redistribute it and/or 00011 * modify it under the terms of the GNU Lesser General Public 00012 * License as published by the Free Software Foundation; either 00013 * version 2.1 of the License, or (at your option) any later version. 00014 * 00015 * This library is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 * Lesser General Public License for more details. 00019 * 00020 * You should have received a copy of the GNU Lesser General Public 00021 * License along with this library; if not, write to the Free Software 00022 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00023 */ 00024 00025 //require_once('PEAR.php'); 00026 00027 // Possible operator types 00028 00029 /* 00030 FIXME: change prefixes 00031 */ 00032 define("OP_BETWEEN", 0x00); 00033 define("OP_NOTBETWEEN", 0x01); 00034 define("OP_EQUAL", 0x02); 00035 define("OP_NOTEQUAL", 0x03); 00036 define("OP_GT", 0x04); 00037 define("OP_LT", 0x05); 00038 define("OP_GTE", 0x06); 00039 define("OP_LTE", 0x07); 00040 00048 class Spreadsheet_Excel_Writer_Validator 00049 { 00050 var $_type; 00051 var $_style; 00052 var $_fixedList; 00053 var $_blank; 00054 var $_incell; 00055 var $_showprompt; 00056 var $_showerror; 00057 var $_title_prompt; 00058 var $_descr_prompt; 00059 var $_title_error; 00060 var $_descr_error; 00061 var $_operator; 00062 var $_formula1; 00063 var $_formula2; 00068 var $_parser; 00069 00070 function Spreadsheet_Excel_Writer_Validator(&$parser) 00071 { 00072 $this->_parser = $parser; 00073 $this->_type = 0x01; // FIXME: add method for setting datatype 00074 $this->_style = 0x00; 00075 $this->_fixedList = false; 00076 $this->_blank = false; 00077 $this->_incell = false; 00078 $this->_showprompt = false; 00079 $this->_showerror = true; 00080 $this->_title_prompt = "\x00"; 00081 $this->_descr_prompt = "\x00"; 00082 $this->_title_error = "\x00"; 00083 $this->_descr_error = "\x00"; 00084 $this->_operator = 0x00; // default is equal 00085 $this->_formula1 = ''; 00086 $this->_formula2 = ''; 00087 } 00088 00089 function setPrompt($promptTitle = "\x00", $promptDescription = "\x00", $showPrompt = true) 00090 { 00091 $this->_showprompt = $showPrompt; 00092 $this->_title_prompt = $promptTitle; 00093 $this->_descr_prompt = $promptDescription; 00094 } 00095 00096 function setError($errorTitle = "\x00", $errorDescription = "\x00", $showError = true) 00097 { 00098 $this->_showerror = $showError; 00099 $this->_title_error = $errorTitle; 00100 $this->_descr_error = $errorDescription; 00101 } 00102 00103 function allowBlank() 00104 { 00105 $this->_blank = true; 00106 } 00107 00108 function onInvalidStop() 00109 { 00110 $this->_style = 0x00; 00111 } 00112 00113 function onInvalidWarn() 00114 { 00115 $this->_style = 0x01; 00116 } 00117 00118 function onInvalidInfo() 00119 { 00120 $this->_style = 0x02; 00121 } 00122 00123 function setFormula1($formula) 00124 { 00125 // Parse the formula using the parser in Parser.php 00126 $error = $this->_parser->parse($formula); 00127 if (PEAR::isError($error)) { 00128 return $this->_formula1; 00129 } 00130 00131 $this->_formula1 = $this->_parser->toReversePolish(); 00132 if (PEAR::isError($this->_formula1)) { 00133 return $this->_formula1; 00134 } 00135 return true; 00136 } 00137 00138 function setFormula2($formula) 00139 { 00140 // Parse the formula using the parser in Parser.php 00141 $error = $this->_parser->parse($formula); 00142 if (PEAR::isError($error)) { 00143 return $this->_formula2; 00144 } 00145 00146 $this->_formula2 = $this->_parser->toReversePolish(); 00147 if (PEAR::isError($this->_formula2)) { 00148 return $this->_formula2; 00149 } 00150 return true; 00151 } 00152 00153 function _getOptions() 00154 { 00155 $options = $this->_type; 00156 $options |= $this->_style << 3; 00157 if ($this->_fixedList) { 00158 $options |= 0x80; 00159 } 00160 if ($this->_blank) { 00161 $options |= 0x100; 00162 } 00163 if (!$this->_incell) { 00164 $options |= 0x200; 00165 } 00166 if ($this->_showprompt) { 00167 $options |= 0x40000; 00168 } 00169 if ($this->_showerror) { 00170 $options |= 0x80000; 00171 } 00172 $options |= $this->_operator << 20; 00173 00174 return $options; 00175 } 00176 00177 function _getData() 00178 { 00179 $title_prompt_len = strlen($this->_title_prompt); 00180 $descr_prompt_len = strlen($this->_descr_prompt); 00181 $title_error_len = strlen($this->_title_error); 00182 $descr_error_len = strlen($this->_descr_error); 00183 00184 $formula1_size = strlen($this->_formula1); 00185 $formula2_size = strlen($this->_formula2); 00186 00187 $data = pack("V", $this->_getOptions()); 00188 $data .= pack("vC", $title_prompt_len, 0x00) . $this->_title_prompt; 00189 $data .= pack("vC", $title_error_len, 0x00) . $this->_title_error; 00190 $data .= pack("vC", $descr_prompt_len, 0x00) . $this->_descr_prompt; 00191 $data .= pack("vC", $descr_error_len, 0x00) . $this->_descr_error; 00192 00193 $data .= pack("vv", $formula1_size, 0x0000) . $this->_formula1; 00194 $data .= pack("vv", $formula2_size, 0x0000) . $this->_formula2; 00195 00196 return $data; 00197 } 00198 } 00199 00200 /*class Spreadsheet_Excel_Writer_Validation_List extends Spreadsheet_Excel_Writer_Validation 00201 { 00202 function Spreadsheet_Excel_Writer_Validation_list() 00203 { 00204 parent::Spreadsheet_Excel_Writer_Validation(); 00205 $this->_type = 0x03; 00206 } 00207 00208 function setList($source, $incell = true) 00209 { 00210 $this->_incell = $incell; 00211 $this->_fixedList = true; 00212 00213 $source = implode("\x00", $source); 00214 $this->_formula1 = pack("CCC", 0x17, strlen($source), 0x0c) . $source; 00215 } 00216 00217 function setRow($row, $col1, $col2, $incell = true) 00218 { 00219 $this->_incell = $incell; 00220 //$this->_formula1 = ...; 00221 } 00222 00223 function setCol($col, $row1, $row2, $incell = true) 00224 { 00225 $this->_incell = $incell; 00226 //$this->_formula1 = ...; 00227 } 00228 }*/ 00229 00230 ?>