/**
	 * Fetch latest version and licensing information from versions server
	 *
	 * @param  boolean     $detailed  Gives detailed latest version description ?
	 * @return array|NULL             errorText  NULL if the key record could be fetched and stored, otherwise major error string
	 */
	public function fetchVersion( $detailed = false ) {
		global $_CB_framework;

		$return							=	null;
		if ( ! isset( $this->responses[$detailed] ) ) {
			$cbsubsVersion				=	explode( ' ', cbpaidApp::version() );
			$this->version				=	$cbsubsVersion[0];
			$this->versionminor			=	( isset( $cbsubsVersion[1] ) ? $cbsubsVersion[1] : '' );

			$formvars		=	array(	'task'					=>	'version',
										'type'					=>	'3',
										'version'				=>	'300',
										'product'				=>	$this->product,
										'productversion'		=>	$this->version,
										'productversionminor'	=>	$this->versionminor,
										'lang'					=>	$_CB_framework->getCfg( 'lang_tag' ),
										'info'					=>	( $detailed ? 'latestversiondetailed' : 'latestversionsummary' )
			);
			$random						=	sprintf( '%08x', mt_rand() );
			$formvars['sign']			=	$random . '-' . md5( $random . implode( '&', $formvars ) );

			$result						=	null;
			$status						=	null;
			$timeout					=	90;
			$live_site					=	$_CB_framework->getCfg( 'live_site' );
			$error						=	cbpaidWebservices::httpsRequest( $this->url, $formvars, $timeout, $result, $status, 'post', 'normal', '*/*', $this->https, $this->port, '', '', false, $live_site );

			$this->responses[$detailed]	=	array();
			if ($error || ( $status != 200) ) {
				$return					=	CBPTXT::T("Connection to update server failed") . ': ' . CBPTXT::T("Error") . ': ' . $error . ($status == -100 ? CBPTXT::T("Timeout") : $status);
			} else {
				$resultArray			=	explode( '-', $result );
				if ( count( $resultArray ) == 3 ) {
					$md5hash			=	md5( $resultArray[1] . $resultArray[0] );
					if ( $md5hash == $resultArray[2] ) {
						$result			=	base64_decode( $resultArray[0] );
						$arr			=	explode( '&', $result );
						$this->responses[$detailed]						=	array();
						foreach ( $arr as $v ) {
							$parts										=	explode( '=', $v );
							if ( count( $parts ) == 2 ) {
								$this->responses[$detailed][$parts[0]]	=	rawurldecode( $parts[1] );
							}
						}
						$return			=	null;
					} else {
						$return			=	CBPTXT::T("Hash mismatch");
					}
				} else {
					// echo $result;
					$return				=	CBPTXT::T("Malformed version server response");	// . $result;
				}
			}
		}
		if ( $return === null ) {
			return $this->responses[$detailed];
		}
		return $return;
	}
 /**
  * View for <param  type="private" class="cbpaidParamsExt" method="checkPluginsPublished">...
  *
  * @param  string              $value                  Stored Data of Model Value associated with the element
  * @param  ParamsInterface     $pluginParams           Main settigns parameters of the plugin
  * @param  string              $name                   Name attribute
  * @param  CBSimpleXMLElement  $param                  This XML node
  * @param  string              $control_name           Name of the control
  * @param  string              $control_name_name      css id-encode of the names of the controls surrounding this node
  * @param  boolean             $view                   TRUE: view, FALSE: edit
  * @param  cbpaidTable         $modelOfData            Data of the Model corresponding to this View
  * @param  cbpaidTable[]       $modelOfDataRows        Displayed Rows if it is a table
  * @param  int                 $modelOfDataRowsNumber  Total Number of rows
  * @return null|string
  */
 public function checkPluginsPublished($value, &$pluginParams, $name, &$param, $control_name, $control_name_name, $view, &$modelOfData, &$modelOfDataRows, &$modelOfDataRowsNumber)
 {
     global $_PLUGINS;
     $groups = explode(',', $param->attributes('groups'));
     $action = $param->attributes('action');
     $path = $param->attributes('path');
     $version = cbpaidApp::version();
     $html = null;
     foreach ($groups as $group) {
         $matches = null;
         if (preg_match('/^([^\\[]+)\\[(.+)\\]$/', $group, $matches)) {
             $classId = $matches[2];
             $group = $matches[1];
         } else {
             $classId = null;
         }
         $_PLUGINS->loadPluginGroup($group, $classId, 0);
         $loadedPlugins = $_PLUGINS->getLoadedPluginGroup($group);
         foreach ($loadedPlugins as $plugin) {
             if (!$classId || substr($classId, -1) == '.' && substr($plugin->element, 0, strlen($classId)) == $classId || $plugin->element == $classId) {
                 $element = $_PLUGINS->loadPluginXML('action', $action, $plugin->id);
                 $viewModel = $element->getElementByPath($path);
                 if (!$path || $viewModel) {
                     if ($plugin->published == 0) {
                         $html .= '<div class="cbWarning">' . sprintf(CBPTXT::Th("The integration plugin '%s' is installed but not published."), htmlspecialchars($plugin->name)) . '</div>';
                     }
                     $cbsubsv = $element->getElementByPath('cbsubsversion');
                     if ($cbsubsv) {
                         if (!cbStartOfStringMatch($version, $cbsubsv->attributes('version'))) {
                             $html .= '<div class="cbWarning">' . sprintf(CBPTXT::T("The CBSubs integration plugin '%s' is for another CBSubs version %s."), htmlspecialchars($plugin->name), htmlspecialchars($cbsubsv->attributes('version'))) . '</div>';
                         }
                     } else {
                         $html .= '<div class="cbWarning">' . sprintf(CBPTXT::T("The CBSubs integration plugin '%s' has no CBSubs version information in XML."), htmlspecialchars($plugin->name)) . '</div>';
                     }
                 }
             }
         }
     }
     /*
     		if ( $html ) {
     			$html			=	'<div class="cbDisabled">'
     							.	CBPTXT::Th("Following CBSubs integration CB plugins are installed but not published (so not active in front-end)")
     							.	':'
     							.	'</div>'
     							.	$html
     							;
     		}
     */
     return $html;
 }
 /**
  * Error Handling function of CBSubs to give as argument for set_error_handler
  * @deprecated : Use cbpaidErrorHandler::init() to set it.
  *
  * @param $errno
  * @param string $errstr
  * @param string $errfile
  * @param string $errline
  * @return bool
  */
 public static function _error_handler_callable($errno, $errstr = '', $errfile = '', $errline = '')
 {
     if (self::$handlerOff || defined('E_STRICT') && $errno == constant('E_STRICT')) {
         return false;
     }
     global $_CB_framework, $_CB_database;
     $cfg['adminEmail'] = null;
     // if error has been supressed with an @
     if (error_reporting() == 0) {
         return false;
     }
     // check if function has been called by an exception
     if (func_num_args() == 5) {
         // called by trigger_error()
         list($errno, $errstr, $errfile, $errline) = func_get_args();
         $backtrace = debug_backtrace();
     } else {
         // caught exception
         /** @var $exc Exception */
         $exc = func_get_arg(0);
         $errno = $exc->getCode();
         $errstr = $exc->getMessage();
         $errfile = $exc->getFile();
         $errline = $exc->getLine();
         $backtrace = array_reverse($exc->getTrace());
     }
     $errorType = array(E_ERROR => 'ERROR', E_WARNING => 'WARNING', E_PARSE => 'PARSING ERROR', E_NOTICE => 'NOTICE', E_CORE_ERROR => 'CORE ERROR', E_CORE_WARNING => 'CORE WARNING', E_COMPILE_ERROR => 'COMPILE ERROR', E_COMPILE_WARNING => 'COMPILE WARNING', E_USER_ERROR => 'USER ERROR', E_USER_WARNING => 'USER WARNING', E_USER_NOTICE => 'USER NOTICE');
     if (defined('E_STRICT')) {
         // php 5
         $errorType[E_STRICT] = 'STRICT NOTICE';
     }
     if (defined('E_RECOVERABLE_ERROR')) {
         // php 5.1.6 + 5.2.x
         $errorType[E_RECOVERABLE_ERROR] = 'E_RECOVERABLE_ERROR';
     }
     $errorPriority = array(E_ERROR => 1, E_WARNING => 4, E_PARSE => 1, E_NOTICE => 5, E_CORE_ERROR => 1, E_CORE_WARNING => 4, E_COMPILE_ERROR => 1, E_COMPILE_WARNING => 4, E_USER_ERROR => 1, E_USER_WARNING => 4, E_USER_NOTICE => 5);
     if (defined('E_STRICT')) {
         $errorPriority[E_STRICT] = 6;
     }
     if (defined('E_RECOVERABLE_ERROR')) {
         $errorPriority[E_RECOVERABLE_ERROR] = 6;
     }
     // create error message
     if (array_key_exists($errno, $errorType)) {
         $err = $errorType[$errno];
     } else {
         $err = 'CAUGHT EXCEPTION';
     }
     $errMsg = $err . ': ' . $errstr . ' in ' . $errfile . ' on line ' . $errline;
     // start backtrace:
     $trace = '';
     foreach ($backtrace as $v) {
         if (isset($v['class'])) {
             $trace .= 'called in class ' . $v['class'] . '::' . $v['function'] . '(';
             if (isset($v['args'])) {
                 $separator = '';
                 foreach ($v['args'] as $arg) {
                     $trace .= $separator . self::cbpaidGetArgument($arg);
                     $separator = ', ';
                 }
             }
             $trace .= ')';
             if (isset($v['line'])) {
                 $trace .= ' on line ' . $v['line'];
             }
             if (isset($v['file'])) {
                 $trace .= ' in file ' . substr(strrchr($v['file'], '/'), 1);
             }
         } elseif (isset($v['function'])) {
             if (strtolower($v['function']) != strtolower(__FUNCTION__)) {
                 $trace .= 'called in function ' . $v['function'] . '(';
                 if (!empty($v['args'])) {
                     $separator = '';
                     foreach ($v['args'] as $arg) {
                         $trace .= $separator . self::cbpaidGetArgument($arg);
                         $separator = ', ';
                     }
                 }
                 $trace .= ')';
                 if (isset($v['line'])) {
                     $trace .= ' on line ' . $v['line'];
                 }
                 if (isset($v['file'])) {
                     $trace .= ' in file ' . substr(strrchr($v['file'], '/'), 1);
                 }
             }
         } else {
             $trace .= '????';
             $trace .= '::::::' . var_export($v, true);
         }
         $trace .= "\n";
     }
     $trace .= '$_GET = ' . var_export($_GET, true) . "\n";
     $trace .= '$_POST = ' . var_export($_POST, true) . "\n";
     $errorText = $errMsg . "\n" . 'Trace:' . $trace . "\n";
     // display error msg, if debug is enabled
     if ($_CB_framework->getCfg('debug')) {
         if (defined('E_STRICT') && $errno != constant('E_STRICT')) {
             echo '<h2>CBPaid Debug Message</h2>' . nl2br($errMsg) . '<br />
 	        Trace:' . nl2br($trace) . '<br />';
         }
     }
     // what to do
     switch ($errno) {
         //    	case E_STRICT:	break;		// only if it's defined (php 4 compatibility)
         //        case E_NOTICE:
         //        case E_USER_NOTICE:
         //        	break;
         default:
             if (array_key_exists($errno, $errorPriority)) {
                 $priority = $errorPriority[$errno];
             } else {
                 $priority = 7;
             }
             $log = new cbpaidHistory($_CB_database);
             $errorTextForMe = strpos($errorText, 'cbpaidsubscriptions') !== false && strpos($errorText, 'parainvite') === false;
             if ($errorTextForMe) {
                 $log->logError($priority, $errorText, null);
             }
             if (TRUE || !$_CB_framework->getCfg('debug')) {
                 // send email to admin
                 if ($errorTextForMe && !empty($cfg['adminEmail'])) {
                     $params = cbpaidApp::settingsParams();
                     $licensee_name = $params->get('licensee_name');
                     @mail($cfg['adminEmail'], cbpaidApp::version() . ' error on ' . $_SERVER['HTTP_HOST'] . ' customer:' . $licensee_name, 'CBPaid Debug Message: ' . $errorText, 'From: error_handler');
                 }
                 if ($priority == 1) {
                     // end and display error msg
                     exit(self::cbDisplayClientMessage());
                 }
             } else {
                 exit('<p>aborting.</p>');
             }
             break;
     }
     return false;
 }
/**
 * Returns version
 * @deprecated 2.1
 *
 * @return string
 */
function cbpaidVersion()
{
    return cbpaidApp::version();
}