| 
									
										
										
										
											2010-08-26 19:14:53 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** PHPExcel root directory */ | 
					
						
							|  |  |  | if (!defined('PHPEXCEL_ROOT')) { | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * @ignore | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../'); | 
					
						
							|  |  |  |     require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php'); | 
					
						
							| 
									
										
										
										
											2010-08-26 19:14:53 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** MAX_VALUE */ | 
					
						
							|  |  |  | define('MAX_VALUE', 1.2e308); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** 2 / PI */ | 
					
						
							|  |  |  | define('M_2DIVPI', 0.63661977236758134307553505349006); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** MAX_ITERATIONS */ | 
					
						
							|  |  |  | define('MAX_ITERATIONS', 256); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** PRECISION */ | 
					
						
							|  |  |  | define('PRECISION', 8.88E-016); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * PHPExcel_Calculation_Functions | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |  * Copyright (c) 2006 - 2015 PHPExcel | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This library is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  * modify it under the terms of the GNU Lesser General Public | 
					
						
							|  |  |  |  * License as published by the Free Software Foundation; either | 
					
						
							|  |  |  |  * version 2.1 of the License, or (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This library is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 
					
						
							|  |  |  |  * Lesser General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU Lesser General Public | 
					
						
							|  |  |  |  * License along with this library; if not, write to the Free Software | 
					
						
							|  |  |  |  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  |  * @category    PHPExcel | 
					
						
							|  |  |  |  * @package        PHPExcel_Calculation | 
					
						
							|  |  |  |  * @copyright    Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel) | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |  * @license        http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL | 
					
						
							|  |  |  |  * @version        ##VERSION##, ##DATE##
 | 
					
						
							| 
									
										
										
										
											2010-08-26 19:14:53 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  | class PHPExcel_Calculation_Functions | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-08-26 19:14:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  |     /** constants */ | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     const COMPATIBILITY_EXCEL      = 'Excel'; | 
					
						
							|  |  |  |     const COMPATIBILITY_GNUMERIC   = 'Gnumeric'; | 
					
						
							|  |  |  |     const COMPATIBILITY_OPENOFFICE = 'OpenOfficeCalc'; | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     const RETURNDATE_PHP_NUMERIC = 'P'; | 
					
						
							|  |  |  |     const RETURNDATE_PHP_OBJECT  = 'O'; | 
					
						
							|  |  |  |     const RETURNDATE_EXCEL       = 'E'; | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Compatibility mode to use for error checking and responses | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @access    private | 
					
						
							|  |  |  |      * @var string | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-05-11 00:31:26 +00:00
										 |  |  |     protected static $compatibilityMode = self::COMPATIBILITY_EXCEL; | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Data Type to use when returning date values | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @access    private | 
					
						
							|  |  |  |      * @var string | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-05-11 00:31:26 +00:00
										 |  |  |     protected static $returnDateType = self::RETURNDATE_EXCEL; | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * List of error codes | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @access    private | 
					
						
							|  |  |  |      * @var array | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-05-11 00:31:26 +00:00
										 |  |  |     protected static $errorCodes = array( | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |         'null'           => '#NULL!', | 
					
						
							|  |  |  |         'divisionbyzero' => '#DIV/0!', | 
					
						
							|  |  |  |         'value'          => '#VALUE!', | 
					
						
							|  |  |  |         'reference'      => '#REF!', | 
					
						
							|  |  |  |         'name'           => '#NAME?', | 
					
						
							|  |  |  |         'num'            => '#NUM!', | 
					
						
							|  |  |  |         'na'             => '#N/A', | 
					
						
							|  |  |  |         'gettingdata'    => '#GETTING_DATA' | 
					
						
							|  |  |  |     ); | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Set the Compatibility Mode | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @access    public | 
					
						
							|  |  |  |      * @category Function Configuration | 
					
						
							|  |  |  |      * @param     string        $compatibilityMode        Compatibility Mode | 
					
						
							|  |  |  |      *                                                Permitted values are: | 
					
						
							|  |  |  |      *                                                    PHPExcel_Calculation_Functions::COMPATIBILITY_EXCEL            'Excel' | 
					
						
							|  |  |  |      *                                                    PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC        'Gnumeric' | 
					
						
							|  |  |  |      *                                                    PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE    'OpenOfficeCalc' | 
					
						
							|  |  |  |      * @return     boolean    (Success or Failure) | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     public static function setCompatibilityMode($compatibilityMode) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  |         if (($compatibilityMode == self::COMPATIBILITY_EXCEL) || | 
					
						
							|  |  |  |             ($compatibilityMode == self::COMPATIBILITY_GNUMERIC) || | 
					
						
							|  |  |  |             ($compatibilityMode == self::COMPATIBILITY_OPENOFFICE)) { | 
					
						
							|  |  |  |             self::$compatibilityMode = $compatibilityMode; | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |             return true; | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Return the current Compatibility Mode | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @access    public | 
					
						
							|  |  |  |      * @category Function Configuration | 
					
						
							|  |  |  |      * @return     string        Compatibility Mode | 
					
						
							|  |  |  |      *                            Possible Return values are: | 
					
						
							|  |  |  |      *                                PHPExcel_Calculation_Functions::COMPATIBILITY_EXCEL            'Excel' | 
					
						
							|  |  |  |      *                                PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC        'Gnumeric' | 
					
						
							|  |  |  |      *                                PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE    'OpenOfficeCalc' | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     public static function getCompatibilityMode() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  |         return self::$compatibilityMode; | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Set the Return Date Format used by functions that return a date/time (Excel, PHP Serialized Numeric or PHP Object) | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @access    public | 
					
						
							|  |  |  |      * @category Function Configuration | 
					
						
							|  |  |  |      * @param     string    $returnDateType            Return Date Format | 
					
						
							|  |  |  |      *                                                Permitted values are: | 
					
						
							|  |  |  |      *                                                    PHPExcel_Calculation_Functions::RETURNDATE_PHP_NUMERIC        'P' | 
					
						
							|  |  |  |      *                                                    PHPExcel_Calculation_Functions::RETURNDATE_PHP_OBJECT        'O' | 
					
						
							|  |  |  |      *                                                    PHPExcel_Calculation_Functions::RETURNDATE_EXCEL            'E' | 
					
						
							|  |  |  |      * @return     boolean                            Success or failure | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     public static function setReturnDateType($returnDateType) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  |         if (($returnDateType == self::RETURNDATE_PHP_NUMERIC) || | 
					
						
							|  |  |  |             ($returnDateType == self::RETURNDATE_PHP_OBJECT) || | 
					
						
							|  |  |  |             ($returnDateType == self::RETURNDATE_EXCEL)) { | 
					
						
							| 
									
										
										
										
											2015-05-11 00:31:26 +00:00
										 |  |  |             self::$returnDateType = $returnDateType; | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |             return true; | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Return the current Return Date Format for functions that return a date/time (Excel, PHP Serialized Numeric or PHP Object) | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @access    public | 
					
						
							|  |  |  |      * @category Function Configuration | 
					
						
							|  |  |  |      * @return     string        Return Date Format | 
					
						
							|  |  |  |      *                            Possible Return values are: | 
					
						
							|  |  |  |      *                                PHPExcel_Calculation_Functions::RETURNDATE_PHP_NUMERIC        'P' | 
					
						
							|  |  |  |      *                                PHPExcel_Calculation_Functions::RETURNDATE_PHP_OBJECT        'O' | 
					
						
							|  |  |  |      *                                PHPExcel_Calculation_Functions::RETURNDATE_EXCEL            'E' | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     public static function getReturnDateType() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-05-11 00:31:26 +00:00
										 |  |  |         return self::$returnDateType; | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * DUMMY | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @access    public | 
					
						
							|  |  |  |      * @category Error Returns | 
					
						
							|  |  |  |      * @return    string    #Not Yet Implemented
 | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     public static function DUMMY() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  |         return '#Not Yet Implemented'; | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * DIV0 | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @access    public | 
					
						
							|  |  |  |      * @category Error Returns | 
					
						
							|  |  |  |      * @return    string    #Not Yet Implemented
 | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     public static function DIV0() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-05-11 00:31:26 +00:00
										 |  |  |         return self::$errorCodes['divisionbyzero']; | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * NA | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * Excel Function: | 
					
						
							|  |  |  |      *        =NA() | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * Returns the error value #N/A
 | 
					
						
							|  |  |  |      *        #N/A is the error value that means "no value is available."
 | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @access    public | 
					
						
							|  |  |  |      * @category Logical Functions | 
					
						
							|  |  |  |      * @return    string    #N/A!
 | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     public static function NA() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-05-11 00:31:26 +00:00
										 |  |  |         return self::$errorCodes['na']; | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * NaN | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * Returns the error value #NUM!
 | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @access    public | 
					
						
							|  |  |  |      * @category Error Returns | 
					
						
							|  |  |  |      * @return    string    #NUM!
 | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     public static function NaN() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-05-11 00:31:26 +00:00
										 |  |  |         return self::$errorCodes['num']; | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * NAME | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * Returns the error value #NAME?
 | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @access    public | 
					
						
							|  |  |  |      * @category Error Returns | 
					
						
							|  |  |  |      * @return    string    #NAME?
 | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     public static function NAME() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-05-11 00:31:26 +00:00
										 |  |  |         return self::$errorCodes['name']; | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * REF | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * Returns the error value #REF!
 | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @access    public | 
					
						
							|  |  |  |      * @category Error Returns | 
					
						
							|  |  |  |      * @return    string    #REF!
 | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     public static function REF() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-05-11 00:31:26 +00:00
										 |  |  |         return self::$errorCodes['reference']; | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * NULL | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * Returns the error value #NULL!
 | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @access    public | 
					
						
							|  |  |  |      * @category Error Returns | 
					
						
							|  |  |  |      * @return    string    #NULL!
 | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     public static function NULL() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-05-11 00:31:26 +00:00
										 |  |  |         return self::$errorCodes['null']; | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * VALUE | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * Returns the error value #VALUE!
 | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @access    public | 
					
						
							|  |  |  |      * @category Error Returns | 
					
						
							|  |  |  |      * @return    string    #VALUE!
 | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     public static function VALUE() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-05-11 00:31:26 +00:00
										 |  |  |         return self::$errorCodes['value']; | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     public static function isMatrixValue($idx) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return ((substr_count($idx, '.') <= 1) || (preg_match('/\.[A-Z]/', $idx) > 0)); | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     public static function isValue($idx) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return (substr_count($idx, '.') == 0); | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     public static function isCellValue($idx) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return (substr_count($idx, '.') > 1); | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-11 00:31:26 +00:00
										 |  |  |     public static function ifCondition($condition) | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  |         $condition    = PHPExcel_Calculation_Functions::flattenSingleValue($condition); | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |         if (!isset($condition{0})) { | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  |             $condition = '=""'; | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |         } | 
					
						
							|  |  |  |         if (!in_array($condition{0}, array('>', '<', '='))) { | 
					
						
							|  |  |  |             if (!is_numeric($condition)) { | 
					
						
							|  |  |  |                 $condition = PHPExcel_Calculation::_wrapResult(strtoupper($condition)); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             return '=' . $condition; | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |             preg_match('/([<>=]+)(.*)/', $condition, $matches); | 
					
						
							|  |  |  |             list(, $operator, $operand) = $matches; | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |             if (!is_numeric($operand)) { | 
					
						
							|  |  |  |                 $operand = str_replace('"', '""', $operand); | 
					
						
							|  |  |  |                 $operand = PHPExcel_Calculation::_wrapResult(strtoupper($operand)); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             return $operator.$operand; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * ERROR_TYPE | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param    mixed    $value    Value to check | 
					
						
							|  |  |  |      * @return    boolean | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     public static function ERROR_TYPE($value = '') | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $value = self::flattenSingleValue($value); | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $i = 1; | 
					
						
							| 
									
										
										
										
											2015-05-11 00:31:26 +00:00
										 |  |  |         foreach (self::$errorCodes as $errorCode) { | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  |             if ($value === $errorCode) { | 
					
						
							|  |  |  |                 return $i; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             ++$i; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         return self::NA(); | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * IS_BLANK | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param    mixed    $value    Value to check | 
					
						
							|  |  |  |      * @return    boolean | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     public static function IS_BLANK($value = null) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  |         if (!is_null($value)) { | 
					
						
							|  |  |  |             $value    = self::flattenSingleValue($value); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return is_null($value); | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * IS_ERR | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param    mixed    $value    Value to check | 
					
						
							|  |  |  |      * @return    boolean | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     public static function IS_ERR($value = '') | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $value = self::flattenSingleValue($value); | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return self::IS_ERROR($value) && (!self::IS_NA($value)); | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * IS_ERROR | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param    mixed    $value    Value to check | 
					
						
							|  |  |  |      * @return    boolean | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     public static function IS_ERROR($value = '') | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $value = self::flattenSingleValue($value); | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |         if (!is_string($value)) { | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  |             return false; | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-05-11 00:31:26 +00:00
										 |  |  |         return in_array($value, array_values(self::$errorCodes)); | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * IS_NA | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param    mixed    $value    Value to check | 
					
						
							|  |  |  |      * @return    boolean | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     public static function IS_NA($value = '') | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $value = self::flattenSingleValue($value); | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return ($value === self::NA()); | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * IS_EVEN | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param    mixed    $value    Value to check | 
					
						
							|  |  |  |      * @return    boolean | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     public static function IS_EVEN($value = null) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  |         $value = self::flattenSingleValue($value); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |         if ($value === null) { | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  |             return self::NAME(); | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |         } elseif ((is_bool($value)) || ((is_string($value)) && (!is_numeric($value)))) { | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  |             return self::VALUE(); | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  |         return ($value % 2 == 0); | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * IS_ODD | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param    mixed    $value    Value to check | 
					
						
							|  |  |  |      * @return    boolean | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     public static function IS_ODD($value = null) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  |         $value = self::flattenSingleValue($value); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |         if ($value === null) { | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  |             return self::NAME(); | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |         } elseif ((is_bool($value)) || ((is_string($value)) && (!is_numeric($value)))) { | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  |             return self::VALUE(); | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  |         return (abs($value) % 2 == 1); | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * IS_NUMBER | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param    mixed    $value        Value to check | 
					
						
							|  |  |  |      * @return    boolean | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     public static function IS_NUMBER($value = null) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $value = self::flattenSingleValue($value); | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (is_string($value)) { | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |             return false; | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  |         } | 
					
						
							|  |  |  |         return is_numeric($value); | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * IS_LOGICAL | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param    mixed    $value        Value to check | 
					
						
							|  |  |  |      * @return    boolean | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     public static function IS_LOGICAL($value = null) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $value = self::flattenSingleValue($value); | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return is_bool($value); | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * IS_TEXT | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param    mixed    $value        Value to check | 
					
						
							|  |  |  |      * @return    boolean | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     public static function IS_TEXT($value = null) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $value = self::flattenSingleValue($value); | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return (is_string($value) && !self::IS_ERROR($value)); | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * IS_NONTEXT | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param    mixed    $value        Value to check | 
					
						
							|  |  |  |      * @return    boolean | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     public static function IS_NONTEXT($value = null) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  |         return !self::IS_TEXT($value); | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * VERSION | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return    string    Version information | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     public static function VERSION() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  |         return 'PHPExcel ##VERSION##, ##DATE##'; | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * N | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * Returns a value converted to a number | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param    value        The value you want converted | 
					
						
							|  |  |  |      * @return    number        N converts values listed in the following table | 
					
						
							|  |  |  |      *        If value is or refers to N returns | 
					
						
							|  |  |  |      *        A number            That number | 
					
						
							|  |  |  |      *        A date                The serial number of that date | 
					
						
							|  |  |  |      *        TRUE                1 | 
					
						
							|  |  |  |      *        FALSE                0 | 
					
						
							|  |  |  |      *        An error value        The error value | 
					
						
							|  |  |  |      *        Anything else        0 | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     public static function N($value = null) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  |         while (is_array($value)) { | 
					
						
							|  |  |  |             $value = array_shift($value); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         switch (gettype($value)) { | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |             case 'double': | 
					
						
							|  |  |  |             case 'float': | 
					
						
							|  |  |  |             case 'integer': | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  |                 return $value; | 
					
						
							|  |  |  |                 break; | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |             case 'boolean': | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  |                 return (integer) $value; | 
					
						
							|  |  |  |                 break; | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |             case 'string': | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  |                 //    Errors
 | 
					
						
							|  |  |  |                 if ((strlen($value) > 0) && ($value{0} == '#')) { | 
					
						
							|  |  |  |                     return $value; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         return 0; | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * TYPE | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * Returns a number that identifies the type of a value | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param    value        The value you want tested | 
					
						
							|  |  |  |      * @return    number        N converts values listed in the following table | 
					
						
							|  |  |  |      *        If value is or refers to N returns | 
					
						
							|  |  |  |      *        A number            1 | 
					
						
							|  |  |  |      *        Text                2 | 
					
						
							|  |  |  |      *        Logical Value        4 | 
					
						
							|  |  |  |      *        An error value        16 | 
					
						
							|  |  |  |      *        Array or Matrix        64 | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     public static function TYPE($value = null) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $value = self::flattenArrayIndexed($value); | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  |         if (is_array($value) && (count($value) > 1)) { | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |             end($value); | 
					
						
							|  |  |  |             $a = key($value); | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  |             //    Range of cells is an error
 | 
					
						
							|  |  |  |             if (self::isCellValue($a)) { | 
					
						
							|  |  |  |                 return 16; | 
					
						
							|  |  |  |             //    Test for Matrix
 | 
					
						
							|  |  |  |             } elseif (self::isMatrixValue($a)) { | 
					
						
							|  |  |  |                 return 64; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |         } elseif (empty($value)) { | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  |             //    Empty Cell
 | 
					
						
							|  |  |  |             return 1; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |         $value = self::flattenSingleValue($value); | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |         if (($value === null) || (is_float($value)) || (is_int($value))) { | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  |                 return 1; | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |         } elseif (is_bool($value)) { | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  |                 return 4; | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |         } elseif (is_array($value)) { | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  |                 return 64; | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |         } elseif (is_string($value)) { | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  |             //    Errors
 | 
					
						
							|  |  |  |             if ((strlen($value) > 0) && ($value{0} == '#')) { | 
					
						
							|  |  |  |                 return 16; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             return 2; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         return 0; | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Convert a multi-dimensional array to a simple 1-dimensional array | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param    array    $array    Array to be flattened | 
					
						
							|  |  |  |      * @return    array    Flattened array | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     public static function flattenArray($array) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  |         if (!is_array($array)) { | 
					
						
							|  |  |  |             return (array) $array; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $arrayValues = array(); | 
					
						
							|  |  |  |         foreach ($array as $value) { | 
					
						
							|  |  |  |             if (is_array($value)) { | 
					
						
							|  |  |  |                 foreach ($value as $val) { | 
					
						
							|  |  |  |                     if (is_array($val)) { | 
					
						
							|  |  |  |                         foreach ($val as $v) { | 
					
						
							|  |  |  |                             $arrayValues[] = $v; | 
					
						
							|  |  |  |                         } | 
					
						
							|  |  |  |                     } else { | 
					
						
							|  |  |  |                         $arrayValues[] = $val; | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 $arrayValues[] = $value; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $arrayValues; | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Convert a multi-dimensional array to a simple 1-dimensional array, but retain an element of indexing | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param    array    $array    Array to be flattened | 
					
						
							|  |  |  |      * @return    array    Flattened array | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     public static function flattenArrayIndexed($array) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  |         if (!is_array($array)) { | 
					
						
							|  |  |  |             return (array) $array; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $arrayValues = array(); | 
					
						
							|  |  |  |         foreach ($array as $k1 => $value) { | 
					
						
							|  |  |  |             if (is_array($value)) { | 
					
						
							|  |  |  |                 foreach ($value as $k2 => $val) { | 
					
						
							|  |  |  |                     if (is_array($val)) { | 
					
						
							|  |  |  |                         foreach ($val as $k3 => $v) { | 
					
						
							|  |  |  |                             $arrayValues[$k1.'.'.$k2.'.'.$k3] = $v; | 
					
						
							|  |  |  |                         } | 
					
						
							|  |  |  |                     } else { | 
					
						
							|  |  |  |                         $arrayValues[$k1.'.'.$k2] = $val; | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 $arrayValues[$k1] = $value; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $arrayValues; | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Convert an array to a single scalar value by extracting the first element | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param    mixed        $value        Array or scalar value | 
					
						
							|  |  |  |      * @return    mixed | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     public static function flattenSingleValue($value = '') | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  |         while (is_array($value)) { | 
					
						
							|  |  |  |             $value = array_pop($value); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $value; | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2010-08-26 19:14:53 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //
 | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  | //    There are a few mathematical functions that aren't available on all versions of PHP for all platforms
 | 
					
						
							|  |  |  | //    These functions aren't available in Windows implementations of PHP prior to version 5.3.0
 | 
					
						
							|  |  |  | //    So we test if they do exist for this version of PHP/operating platform; and if not we create them
 | 
					
						
							| 
									
										
										
										
											2010-08-26 19:14:53 +00:00
										 |  |  | //
 | 
					
						
							|  |  |  | if (!function_exists('acosh')) { | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     function acosh($x) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  |         return 2 * log(sqrt(($x + 1) / 2) + sqrt(($x - 1) / 2)); | 
					
						
							|  |  |  |     }    //    function acosh()
 | 
					
						
							| 
									
										
										
										
											2010-08-26 19:14:53 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if (!function_exists('asinh')) { | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     function asinh($x) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  |         return log($x + sqrt(1 + $x * $x)); | 
					
						
							|  |  |  |     }    //    function asinh()
 | 
					
						
							| 
									
										
										
										
											2010-08-26 19:14:53 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if (!function_exists('atanh')) { | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     function atanh($x) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  |         return (log(1 + $x) - log(1 - $x)) / 2; | 
					
						
							|  |  |  |     }    //    function atanh()
 | 
					
						
							| 
									
										
										
										
											2010-08-26 19:14:53 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //
 | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  | //    Strangely, PHP doesn't have a mb_str_replace multibyte function
 | 
					
						
							|  |  |  | //    As we'll only ever use this function with UTF-8 characters, we can simply "hard-code" the character set
 | 
					
						
							| 
									
										
										
										
											2010-08-26 19:14:53 +00:00
										 |  |  | //
 | 
					
						
							|  |  |  | if ((!function_exists('mb_str_replace')) && | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  |     (function_exists('mb_substr')) && (function_exists('mb_strlen')) && (function_exists('mb_strpos'))) { | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |     function mb_str_replace($search, $replace, $subject) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         if (is_array($subject)) { | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  |             $ret = array(); | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |             foreach ($subject as $key => $val) { | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  |                 $ret[$key] = mb_str_replace($search, $replace, $val); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             return $ret; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |         foreach ((array) $search as $key => $s) { | 
					
						
							|  |  |  |             if ($s == '' && $s !== 0) { | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  |                 continue; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             $r = !is_array($replace) ? $replace : (array_key_exists($key, $replace) ? $replace[$key] : ''); | 
					
						
							|  |  |  |             $pos = mb_strpos($subject, $s, 0, 'UTF-8'); | 
					
						
							| 
									
										
										
										
											2015-05-09 13:33:20 +00:00
										 |  |  |             while ($pos !== false) { | 
					
						
							| 
									
										
										
										
											2015-05-08 00:09:27 +00:00
										 |  |  |                 $subject = mb_substr($subject, 0, $pos, 'UTF-8') . $r . mb_substr($subject, $pos + mb_strlen($s, 'UTF-8'), 65535, 'UTF-8'); | 
					
						
							|  |  |  |                 $pos = mb_strpos($subject, $s, $pos + mb_strlen($r, 'UTF-8'), 'UTF-8'); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         return $subject; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-08-26 19:14:53 +00:00
										 |  |  | } |