Page MenuHomeIn-Portal Phabricator

in-portal
No OneTemporary

File Metadata

Created
Fri, Apr 18, 8:40 AM

in-portal

Index: branches/5.0.x/core/units/general/xml_helper.php
===================================================================
--- branches/5.0.x/core/units/general/xml_helper.php (revision 12308)
+++ branches/5.0.x/core/units/general/xml_helper.php (nonexistent)
@@ -1,395 +0,0 @@
-<?php
-/**
-* @version $Id$
-* @package In-Portal
-* @copyright Copyright (C) 1997 - 2009 Intechnic. All rights reserved.
-* @license GNU/GPL
-* In-Portal is Open Source software.
-* This means that this software may have been modified pursuant
-* the GNU General Public License, and as distributed it includes
-* or is derivative of works licensed under the GNU General Public License
-* or other free or open source software licenses.
-* See http://www.in-portal.net/license/ for copyright notices and details.
-*/
-
- defined('FULL_PATH') or die('restricted access!');
-
- class kXMLHelper extends kHelper {
-
- var $RootElement = null;
-
- /**
- * Enter description here...
- *
- * @var kXMLNode
- */
- var $CurrentElement = null;
-
- var $Mode;
-
- /**
- * Parses XML data specified and returns root node
- *
- * @param string $xml
- * @return kXMLNode
- */
- function &Parse($xml = null, $mode = XML_NO_TEXT_NODES)
- {
- $this->Mode = $mode;
- $this->Clear(); // in case if Parse method is called more then one time
- $xml_parser = xml_parser_create();
- xml_set_element_handler( $xml_parser, Array(&$this, 'startElement'), Array(&$this, 'endElement') );
- xml_set_character_data_handler( $xml_parser, Array(&$this, 'characterData') );
- if (!xml_parse($xml_parser, $xml, 1)) {
- $this->RootElement = new kXMLNode('ERROR', array('code'=>xml_get_error_code($xml_parser),'message'=>xml_error_string(xml_get_error_code($xml_parser))));
- trigger_error(sprintf('XML error: %s at line %d',
- xml_error_string(xml_get_error_code($xml_parser)),
- xml_get_current_line_number($xml_parser)), E_USER_WARNING);
- }
- xml_parser_free($xml_parser);
-
- $root_copy = $this->RootElement;
-
- return $root_copy;
- }
-
- function ConvertHTMLEntities($s){
- //build first an assoc. array with the entities we want to match
- $table1 = get_html_translation_table(HTML_ENTITIES, ENT_QUOTES);
-
- $patterns = array();
- $replacements = array();
- //now build another assoc. array with the entities we want to replace (numeric entities)
- foreach ($table1 as $k=>$v){
- $patterns[] = "/$v/";
- // $c = htmlentities($k,ENT_QUOTES,"UTF-8");
- $replacements[] = "&#".ord($k).";";
- }
-
- //now perform a replacement using preg_replace
- //each matched value in array 1 will be replaced with the corresponding value in array 2
- $s = preg_replace($patterns,$replacements,$s);
- return $s;
- }
-
- function startElement(&$Parser, &$Elem, $Attrs)
- {
- $parent =& $this->CurrentElement; // 1. $parent is now reference to $this->CurrentElement
- $this->CurrentElement =& new kXMLNode($Elem, $Attrs); // 2. =& ensures, that new object won't be assigned to $parent as well (don't remove)
- if (!isset($this->RootElement) || is_null($this->RootElement)) {
- $this->RootElement =& $this->CurrentElement;
- }
- if (!is_null($parent)) {
- $parent->AddChild($this->CurrentElement);
- }
- }
-
- function characterData($Parser, $Line)
- {
- if ($this->Mode == XML_WITH_TEXT_NODES) {
- $text_node = new kXMLNode('_TEXT_');
- $text_node->AppendData($Line);
- $this->CurrentElement->AddChild( $text_node );
- }
- else {
- $this->CurrentElement->AppendData($Line);
- }
- }
-
- function endElement($Parser, $Elem)
- {
- if ($this->Mode == XML_WITH_TEXT_NODES) {
- /*if (count($this->CurrentElement->Children) == 1 && $this->CurrentElement->firstChild->Name == '_TEXT_') {
- $this->CurrentElement->Children = array();
- }*/
- }
- if ($this->CurrentElement->Parent != null) {
- $this->CurrentElement =& $this->CurrentElement->Parent;
- }
- }
-
- function Clear()
- {
- unset($this->RootElement);
- unset($this->CurrentElement);
- }
- }
-
- class kXMLNode {
- /**
- * Name of this node
- *
- * @var string
- */
- var $Name = null;
-
- /**
- * Attributes of this node
- *
- * @var Array
- */
- var $Attributes = array();
-
- /**
- * List of node childnodes
- *
- * @var Array
- */
- var $Children = array();
-
- /**
- * Node content (usually text)
- *
- * @var string
- */
- var $Data = null;
-
- /**
- * First child of this node
- *
- * @var kXMLNode
- */
- var $firstChild = null;
-
- /**
- * Last child of this node
- *
- * @var kXMLNode
- */
- var $lastChild = null;
-
- /**
- * Parent node
- *
- * @var kXMLNode
- */
- var $Parent = null;
-
- /**
- * Node position relative to other nodes of it's parent
- *
- * @var int
- */
- var $Position = 0;
-
- /**
- * Node identifier
- *
- * @var int
- */
- var $CRC = null;
-
- function kXMLNode($name, $attrs = array())
- {
- $this->Name = strtoupper($name);
- foreach ($attrs as $attr => $value) {
- $this->Attributes[strtoupper($attr)] = $value;
- }
- $this->CRC = crc32($this->Name.join(array_keys($this->Attributes)).join(array_values($this->Attributes)));
- }
-
- function SetParent(&$elem)
- {
- $this->Parent =& $elem;
- }
-
- /**
- * Adds new child to current node
- *
- * @param kXMLNode $a_child
- */
- function AddChild(&$a_child)
- {
- $node_count = count($this->Children);
- $a_child->Position = $node_count;
-
- if ($node_count == 0) {
- $this->firstChild =& $a_child;
- $this->lastChild =& $a_child;
- }
- else {
- $this->lastChild =& $a_child;
- }
-
- $this->Children[] =& $a_child;
- $a_child->SetParent($this);
- }
-
- /**
- * Appends data to current node
- *
- * @param string $data
- */
- function AppendData($data)
- {
- $this->Data .= $data;
- }
-
- /**
- * Returns child node by given path
- *
- * @param string $path
- * @return kXMLNode
- */
- function &GetChild($path)
- {
- $entries = explode('/', strtoupper($path));
- $cur = array_shift($entries);
- if ($cur == $this->Name) $cur = array_shift($entries);
- if (!$cur) return $this;
- if (!isset($this->Children[$cur])) return false;
- $left = implode('/', $entries);
- if (!$left) return $this->Children[$cur];
- return $this->Children[$cur]->GetChild($left);
- }
-
- /**
- * Returns node value by given path
- *
- * @param string $path
- * @return string
- */
- function GetChildValue($path)
- {
- $child =& $this->GetChild($path);
- if ($child !== false) {
- return $child->Data;
- }
- }
-
- /**
- * Returns child node by given position among it siblings
- *
- * @param int $position
- * @return kXMLNode
- */
- function &GetChildByPosition($position)
- {
- if ($position < count($this->Children) ) {
- return $this->Children[$position];
- }
- else {
- $false = false;
- return $false;
- }
- }
-
- /**
- * Recursively searches for child with given name under current node
- *
- * @param string $name
- * @return kXMLNode
- */
- function &FindChild($name)
- {
- $name = strtoupper($name);
- if ($this->Name == $name) return $this;
- // if (isset($this->Children[$name])) return $this->Children[$name];
- // $children = array_keys($this->Children);
- foreach ($this->Children as $elem)
- {
- $child =& $elem->FindChild($name);
- if ($child !== false)
- {
- return $child;
- }
- }
- $false = false;
- return $false;
- }
-
- /**
- * Retruns value of given child or value of it's attribute
- *
- * @param string $name
- * @param string $attr
- * @return string
- */
- function FindChildValue($name, $attr=null)
- {
- $child =& $this->FindChild($name);
- if ($child !== false) {
- if (isset($attr)) {
- return $child->Attributes[strtoupper($attr)];
- }
- return $child->Data;
- }
- }
-
- /**
- * Returns next node to this, false in case of end list
- *
- * @return kXMLNode
- */
- function &PrevSibling()
- {
- if (!is_null($this->Parent) && $this->Position > 0) {
- $pos = $this->Position - 1;
- do {
- $ret =& $this->Parent->GetChildByPosition($pos--);
- } while ($ret->Name == '_TEXT_' && $pos >= 0);
- if ($ret->Name == '_TEXT_') $ret = false;
- return $ret;
- }
- else {
- $false = false;
- return $false;
- }
- }
-
- /**
- * Returns next node to this, false in case of end list
- *
- * @return kXMLNode
- */
- function &NextSibling()
- {
- if (!is_null($this->Parent)) {
- $pos = $this->Position + 1;
- do {
- $ret =& $this->Parent->GetChildByPosition($pos++);
- } while ($pos < count($this->Parent->Children) && ($ret->Name == '_TEXT_'));
-
- if (is_object($ret) && ($ret->Name == '_TEXT_')) {
- $ret = false;
- }
- return $ret;
- }
- else {
- $false = false;
- return $false;
- }
- }
- /**
- * Reconstructs XML of the node and subnodes
- *
- * $param bool $content_only
- */
- function GetXML($content_only = false)
- {
- $xml = '';
- if (!$content_only) {
- $xml = '<'.$this->Name;
- if (count($this->Attributes)) {
- $xml .= ' ';
- $att_contents = array();
- foreach ($this->Attributes as $name => $value) {
- $att_contents[] = $name.'="'.$value.'"';
- }
- $xml .= implode(' ', $att_contents);
- }
- $xml .= '>';
- }
- $xml .= $this->Data;
- foreach ($this->Children as $node) {
- /* @var $node kXMLNode */
-
- $xml .= $node->GetXML($node->Name == '_TEXT_' ? true : false);
- }
-
- if (!$content_only) {
- $xml .= '</'.$this->Name.'>';
- }
- return $xml;
- }
- }
\ No newline at end of file
Property changes on: branches/5.0.x/core/units/general/xml_helper.php
___________________________________________________________________
Deleted: cvs2svn:cvs-rev
## -1 +0,0 ##
-1.8.2.10
\ No newline at end of property
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
Deleted: svn:keywords
## -1 +0,0 ##
-Id
\ No newline at end of property
Index: branches/5.0.x/core/units/general/country_states.php
===================================================================
--- branches/5.0.x/core/units/general/country_states.php (revision 12308)
+++ branches/5.0.x/core/units/general/country_states.php (nonexistent)
@@ -1,121 +0,0 @@
-<?php
-/**
-* @version $Id$
-* @package In-Portal
-* @copyright Copyright (C) 1997 - 2009 Intechnic. All rights reserved.
-* @license GNU/GPL
-* In-Portal is Open Source software.
-* This means that this software may have been modified pursuant
-* the GNU General Public License, and as distributed it includes
-* or is derivative of works licensed under the GNU General Public License
-* or other free or open source software licenses.
-* See http://www.in-portal.net/license/ for copyright notices and details.
-*/
-
- defined('FULL_PATH') or die('restricted access!');
-
- class kCountryStatesHelper extends kHelper
- {
- var $CountriesWithStates = Array('USA', 'CAN');
-
- function CountryHasStates($country_code)
- {
- return !$country_code ? false : in_array($country_code,$this->CountriesWithStates);
- }
-
- /**
- * Prepares states dropdown based on country selected
- *
- * @param kEvent $event
- * @param string $state_field
- * @param string $country_field
- */
- function PopulateStates(&$event, $state_field, $country_field)
- {
- static $country_states = Array ();
-
- $object =& $event->getObject();
- $country_abbr = $object->GetDBField($country_field);
-
- if (!$country_abbr) {
- return ;
- }
-
- if (!array_key_exists($country_abbr, $country_states)) {
- $sql = 'SELECT DestId
- FROM '.TABLE_PREFIX.'StdDestinations
- WHERE DestType = 1 AND DestAbbr = '.$this->Conn->qstr($country_abbr);
- $country_id = $this->Conn->GetOne($sql);
- if (!$country_id) {
- return ;
- }
-
- $sql = 'SELECT p.Translation as DestName, sd.DestAbbr
- FROM ' . TABLE_PREFIX . 'StdDestinations AS sd
- LEFT JOIN ' . TABLE_PREFIX . 'Phrase AS p ON p.Phrase = sd.DestName
- WHERE DestType = 2 AND DestParentId = ' . $country_id . ' AND LanguageId = ' . $this->Application->GetVar('m_lang') . '
- ORDER BY Translation';
-
- $country_states[$country_abbr] = $this->Conn->GetCol($sql, 'DestAbbr');
- }
-
- $object->Fields[$state_field]['options'] = $country_states[$country_abbr];
- $object->Fields[$state_field]['options'][''] = '';
- }
-
- /**
- * Returns valid state code for state name and country code passed
- *
- * @param string $state_name
- * @param string $country_code
- * @return string
- */
- function CheckState($state_name, $country_code)
- {
- if( !$this->CountryHasStates($country_code) ) return $state_name;
-
- $sql = 'SELECT sdStates.DestAbbr
- FROM '.TABLE_PREFIX.'StdDestinations AS sdStates
- LEFT JOIN '.TABLE_PREFIX.'Phrase AS p ON p.Phrase = sdStates.DestName
- LEFT JOIN '.TABLE_PREFIX.'StdDestinations AS sdCountries ON sdStates.DestParentId = sdCountries.DestId
- WHERE (sdStates.DestType = 2) AND
- (sdStates.DestParentId = sdCountries.DestId) AND
- (p.LanguageId = %1$s) AND
- (sdCountries.DestAbbr = %2$s) AND
- (
- (LOWER(sdStates.DestAbbr) = %3$s) OR (LOWER(sdStates.DestAbbr2) = %3$s) OR (LOWER(sdStates.DestName) = %3$s) OR (LOWER(p.Translation) = %3$s)
- )';
-
- $state_name = trim( mb_strtolower($state_name) );
- $sql = sprintf($sql, $this->Application->GetVar('m_lang'), $this->Conn->qstr($country_code), $this->Conn->qstr($state_name) );
-
- return $this->Conn->GetOne($sql);
- }
-
- function CheckStateField(&$event, $state_field, $country_field)
- {
-
- $items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) );
- if($items_info)
- {
- list($id, $field_values) = each($items_info);
- if( isset($field_values[$state_field]) && isset($field_values[$country_field]) )
- {
- $user_state = getArrayValue($field_values,$state_field);
- $valid_state = $this->CheckState($user_state, getArrayValue($field_values,$country_field) );
- if($valid_state !== false)
- {
- $field_values[$state_field] = $valid_state;
- $items_info[$id] = $field_values;
- $this->Application->SetVar( $event->getPrefixSpecial(true), $items_info);
- }
- else
- {
- $object =& $event->getObject();
- $object->Fields[$state_field]['options'][$user_state] = $user_state;
- $object->SetError($state_field, 'invalid_state', 'la_invalid_state');
- }
- }
- }
- }
- }
\ No newline at end of file
Property changes on: branches/5.0.x/core/units/general/country_states.php
___________________________________________________________________
Deleted: cvs2svn:cvs-rev
## -1 +0,0 ##
-1.4.48.2
\ No newline at end of property
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
Deleted: svn:keywords
## -1 +0,0 ##
-Id
\ No newline at end of property
Index: branches/5.0.x/core/units/general/custom_fields.php
===================================================================
--- branches/5.0.x/core/units/general/custom_fields.php (revision 12308)
+++ branches/5.0.x/core/units/general/custom_fields.php (nonexistent)
@@ -1,130 +0,0 @@
-<?php
-/**
-* @version $Id$
-* @package In-Portal
-* @copyright Copyright (C) 1997 - 2009 Intechnic. All rights reserved.
-* @license GNU/GPL
-* In-Portal is Open Source software.
-* This means that this software may have been modified pursuant
-* the GNU General Public License, and as distributed it includes
-* or is derivative of works licensed under the GNU General Public License
-* or other free or open source software licenses.
-* See http://www.in-portal.net/license/ for copyright notices and details.
-*/
-
- defined('FULL_PATH') or die('restricted access!');
-
- /**
- * Enter description here...
- *
- * @todo rewrite
- */
- class InpCustomFieldsHelper extends kHelper {
-
- /**
- * Parses given option string and returns associative array
- *
- * @param string $values_list
- * @param string $separator
- * @param bool $parse
- * @return Array
- */
- function GetValuesHash($values_list, $separator = VALUE_LIST_SEPARATOR, $parse = true)
- {
- $values_list = trim($this->ParseConfigSQL($values_list, $separator, $parse), $separator);
-
- if (!$values_list) {
- // no options, then return empty array
- return Array();
- }
-
- $optionValuesTmp = explode($separator, $values_list);
- $optionValues = Array();
-
- if (substr_count($values_list, '=') != count($optionValuesTmp)) {
- if ($this->Application->isDebugMode()) {
- $this->Application->Debugger->appendTrace();
- }
-
- trigger_error('Invalid symbol in ValueList field [' . substr($values_list, 0, 100) . ' ...]' , E_USER_NOTICE);
- return Array ();
- }
-
- if ($parse) {
- // normal way
- foreach ($optionValuesTmp as $optionValue) {
- list ($key, $val) = explode('=', $optionValue);
-
- $val = substr($val, 0, 1) == '+' ? substr($val, 1) : $this->Application->Phrase($val);
-
- $optionValues[$key] = $val;
- }
- }
- else {
- // during custom field editing
- foreach ($optionValuesTmp as $optionValue) {
- list ($key, $val) = explode('=', $optionValue);
-
- if (substr($key, 0, 3) == 'SQL') {
- $val = base64_decode( str_replace('_', '=', substr($val, 1)) );
- }
-
- $optionValues[$key] = $val;
- }
- }
-
- return $optionValues;
- }
-
- /**
- * Replace SQL's in valueList with appropriate queried values
- *
- * @param string $valueString
- * @param string $separator
- * @return string
- * @todo Apply refactoring to embedded vars stuff
- */
- function ParseConfigSQL($valueString, $separator = VALUE_LIST_SEPARATOR, $parse_sqls = true)
- {
- $string = trim( str_replace(Array('<PREFIX>', '%3$s'), Array (TABLE_PREFIX, $this->Application->GetVar('m_lang')), $valueString) );
-
- if (preg_match_all('/<SQL([+]{0,1})>(.*?)<\/SQL>/', $string, $regs)) {
- $i = 0;
- $sql_count = count($regs[0]);
- while ($i < $sql_count) {
- if ($parse_sqls) {
- $replacement = $this->_queryConfigSQL($regs[2][$i], $regs[1][$i], $separator);
- }
- else {
- $sql = base64_encode('<SQL'.$regs[1][$i].'>'.$regs[2][$i].'</SQL>');
- $replacement = 'SQL' . $i . '=+' . str_replace('=', '_', $sql);
- }
-
- $string = str_replace('<SQL'.$regs[1][$i].'>'.$regs[2][$i].'</SQL>', $replacement, $string);
- $i++;
- }
-
- $string = preg_replace('/[' . preg_quote($separator, '/') . ']+/', $separator, $string); // trim trailing separators inside string
- }
-
- return $string;
- }
-
- /**
- * Transforms given sql into value list string
- *
- * @param string $sql
- * @param string $plus
- * @param string $separator
- * @return string
- */
- function _queryConfigSQL($sql, $plus = '', $separator = VALUE_LIST_SEPARATOR)
- {
- $values = $this->Conn->Query($sql);
- foreach ($values as $index => $value) {
- $values[$index] = $value['OptionValue'] . '=' . $plus . $value['OptionName'];
- }
-
- return implode($separator, $values);
- }
- }
\ No newline at end of file
Property changes on: branches/5.0.x/core/units/general/custom_fields.php
___________________________________________________________________
Deleted: cvs2svn:cvs-rev
## -1 +0,0 ##
-1.9.2.4
\ No newline at end of property
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
Deleted: svn:keywords
## -1 +0,0 ##
-Id
\ No newline at end of property
Index: branches/5.0.x/core/units/general/brackets.php
===================================================================
--- branches/5.0.x/core/units/general/brackets.php (revision 12308)
+++ branches/5.0.x/core/units/general/brackets.php (nonexistent)
@@ -1,470 +0,0 @@
-<?php
-/**
-* @version $Id$
-* @package In-Portal
-* @copyright Copyright (C) 1997 - 2009 Intechnic. All rights reserved.
-* @license GNU/GPL
-* In-Portal is Open Source software.
-* This means that this software may have been modified pursuant
-* the GNU General Public License, and as distributed it includes
-* or is derivative of works licensed under the GNU General Public License
-* or other free or open source software licenses.
-* See http://www.in-portal.net/license/ for copyright notices and details.
-*/
-
- defined('FULL_PATH') or die('restricted access!');
-
- class kBracketsHelper extends kHelper {
-
- /**
- * Field name holding minimal amount
- *
- * @var string
- */
- var $min_field = '';
-
- /**
- * Field name holding maximal amount
- *
- * @var string
- */
- var $max_field = '';
-
- /**
- * Default values to be set to automtically created price brackets
- *
- * @var Array
- */
- var $default_values = Array();
-
- var $defaultStartValue = 1;
-
- /**
- * Decimal separator
- *
- * @var string
- */
- var $_decimalSeparator = '';
-
- /**
- * Thousands separator
- *
- * @var string
- */
- var $_thousandsSeparator = '';
-
- /**
- * Current language
- *
- * @var LanguagesItem
- */
- var $_language = null;
-
- function kBracketsHelper()
- {
- parent::kHelper();
-
- $this->_language =& $this->Application->recallObject('lang.current');
- /* @var $lang kDBItem */
-
- $this->_decimalSeparator = $this->_language->GetDBField('DecimalPoint');
- $this->_thousandsSeparator = $this->_language->GetDBField('ThousandSep');
- }
-
- function InitHelper($min_field, $max_field, $default_values, $default_start_value = null)
- {
- $this->min_field = $min_field;
- $this->max_field = $max_field;
- $this->default_values = $default_values;
-
- if (isset($default_start_value)) {
- $this->defaultStartValue = $default_start_value;
- }
- }
-
- /**
- * Converts number to operatable form
- *
- * @param string $value
- * @return float
- */
- function _parseNumber($value)
- {
- $value = str_replace($this->_thousandsSeparator, '', $value);
- $value = str_replace($this->_decimalSeparator, '.', $value);
-
- return $value;
- }
-
- /**
- * Returns brackets from form with all numbers parsed
- *
- * @param kEvent $event
- * @return Array
- */
- function getBrackets(&$event)
- {
- $items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) );
-
- return $this->parseBrackets($items_info);
- }
-
- function parseBrackets($brackets)
- {
- if (!$brackets) {
- return $brackets;
- }
-
- foreach ($brackets as $id => $field_values) {
- if (strlen($brackets[$id][$this->min_field])) {
- $brackets[$id][$this->min_field] = (float)$this->_parseNumber($brackets[$id][$this->min_field]);
- }
-
- if (strlen($brackets[$id][$this->max_field])) {
- $brackets[$id][$this->max_field] = (float)$this->_parseNumber($brackets[$id][$this->max_field]);
- }
- }
-
- return $brackets;
- }
-
- /**
- * Formats given brackets and sets them back to request
- *
- * @param kEvent $event
- * @param Array $brackets
- */
- function setBrackets(&$event, $brackets)
- {
- $brackets = $this->formatBrackets($brackets);
-
- $this->Application->SetVar($event->getPrefixSpecial(true), $brackets);
- }
-
- function formatBrackets($brackets)
- {
- if (!$brackets) {
- return $brackets;
- }
-
- foreach ($brackets as $id => $field_values) {
- if (strlen($brackets[$id][$this->min_field])) {
- $brackets[$id][$this->min_field] = $this->_language->formatNumber($brackets[$id][$this->min_field]);
- }
-
- if (strlen($brackets[$id][$this->max_field])) {
- $brackets[$id][$this->max_field] = $this->_language->formatNumber($brackets[$id][$this->max_field]);
- }
- }
-
- return $brackets;
- }
-
- /**
- * Adds 5 more empty brackets to brackets
- *
- * @param kEvent $event
- */
- function OnMoreBrackets(&$event)
- {
- $field_values = $this->getBrackets($event);
-
- $object =& $event->getObject();
-
- foreach($field_values as $id => $record)
- {
- if($record[$this->max_field] == '&#8734;') $field_values[$id][$this->max_field] = -1;
- }
-
- $new_id = (int)$this->Conn->GetOne('SELECT MIN('.$object->IDField.') FROM '.$object->TableName);
- if($new_id > 0) $new_id = 0;
- do
- {
- $new_id--;
- }while( $this->arraySearch($field_values, $object->IDField, $new_id) );
-
-
- $last_max_qty = $this->Conn->GetOne('SELECT MAX('.$this->max_field.') FROM '.$object->TableName);
- $min_qty = $this->Conn->GetOne('SELECT MIN('.$this->max_field.') FROM '.$object->TableName);
-
- if($min_qty == -1) $last_max_qty = -1;
- if(!$last_max_qty) $last_max_qty = $this->defaultStartValue;
-
-
- for($i = $new_id; $i > $new_id - 5; $i--)
- {
- $field_values[$i][$object->IDField] = $i;
- $field_values[$i][$this->min_field] = ($i == $new_id-4 && $last_max_qty != -1) ? $last_max_qty : '';
- $field_values[$i][$this->max_field] = ($i == $new_id-4 && $last_max_qty != -1) ? -1 : '';
- $field_values[$i] = array_merge_recursive2($field_values[$i], $this->default_values);
- }
-
- $event->CallSubEvent('OnPreSaveBrackets');
-
- $this->setBrackets($event, $field_values);
- }
-
- /**
- * Adds infinity bracket
- *
- * @param kEvent $event
- */
- function OnInfinity(&$event)
- {
- $object =& $event->getObject();
- $infinite_exists = $this->Conn->GetOne('SELECT COUNT(*) FROM '.$object->TableName.' WHERE '.$this->max_field.' = -1');
- $field_values = $this->getBrackets($event);
- /*if(is_array($field_values))
- {
- foreach($field_values as $values)
- {
- $infinite_exists = $infinite_exists || ($values[$this->max_field] == -1);
- }
- }*/
-
- if ($infinite_exists == 0) {
- reset($field_values);
- $last_bracket = end($field_values);
- $new_id = (int)$this->Conn->GetOne('SELECT MIN('.$object->IDField.') FROM '.$object->TableName);
-
- $brackets_exist = (int)$this->Conn->GetOne('SELECT COUNT(*) FROM '.$object->TableName);
-
- if($new_id > 0) $new_id = 0;
- do
- {
- $new_id--;
- }while( $this->arraySearch($field_values, $object->IDField, $new_id) );
-
- $infinite_bracket[$object->IDField] = $new_id;
- $infinite_bracket[$this->min_field] = ($brackets_exist > 0) ? $last_bracket[$this->max_field] : $this->defaultStartValue;
- $infinite_bracket[$this->max_field] = '-1';
- $infinite_bracket = array_merge_recursive2($infinite_bracket, $this->default_values);
-
- $field_values[$new_id] = $infinite_bracket;
- reset($field_values);
-
- $this->setBrackets($event, $field_values);
- }
- }
-
- /**
- * Saves brackets to database
- *
- * @param kEvent $event
- */
- function OnPreSaveBrackets(&$event)
- {
- $items_info = $this->getBrackets($event);
- if ($items_info) {
- $object =& $event->getObject();
-
- $linked_info = $object->getLinkedInfo();
- $stored_ids = $this->Conn->GetCol('SELECT '.$object->IDField.' FROM '.$object->TableName.' WHERE '.$linked_info['ForeignKey'].' = '.$linked_info['ParentId']);
-
- uasort($items_info, Array(&$this, 'compareBrackets') );
-
- foreach ($items_info as $item_id => $values) {
-
- if (in_array($item_id, $stored_ids)) { //if it's already exist
- $object->SetDefaultValues();
- $object->Load($item_id);
- $object->SetFieldsFromHash($values);
- if (!$object->Validate()) {
- unset($stored_ids[array_search($item_id, $stored_ids)]);
- $event->redirect = false;
- continue;
- }
- if( $object->Update($item_id) )
- {
- $event->status = erSUCCESS;
- }
- else
- {
- $event->status = erFAIL;
- $event->redirect = false;
- break;
- }
- unset( $stored_ids[ array_search($item_id, $stored_ids) ] );
- }
- else {
- $object->SetDefaultValues();
- $object->SetFieldsFromHash($values);
- $object->SetDBField($linked_info['ForeignKey'], $linked_info['ParentId']);
-
- if( $object->Create() )
- {
- $object->setTempID();
- $event->status = erSUCCESS;
- }
- }
- }
-
- // delete
- foreach ($stored_ids as $stored_id)
- {
- $this->Conn->Query('DELETE FROM '.$object->TableName.' WHERE '.$object->IDField.' = '.$stored_id);
- }
-
- }
- }
-
- function arrangeBrackets(&$event)
- {
- $object =& $event->getObject();
-
- $temp = $this->getBrackets($event);
-
- foreach($temp as $id => $record)
- {
- if( $record[$this->max_field] == '&#8734;' )
- {
- $temp[$id][$this->max_field] = -1;
- }
- }
-
- $temp_orig = $temp;
- reset($temp);
- if( is_array($temp) )
- {
- // array to store max values (2nd column)
- $end_values = Array();
-
- // get minimal value of Min
- $first_elem = current($temp);
- $start = $first_elem[$this->min_field];
- if (!strlen($start)) {
- $start = $this->defaultStartValue;
- }
-
- foreach($temp as $id => $record)
- {
- if(
- // MAX is less than start
- ($record[$this->max_field] <= $start && $record[$this->max_field] != -1) ||
- // Max is empty
- !strlen($record[$this->max_field]) ||
- // Max already defined in $end_values
- (array_search($record[$this->max_field], $end_values) !== false)
- ) { // then delete from brackets list
- unset($temp[$id]);
- }
- else { // this is when ok - add to end_values list
- $end_values[] = $record[$this->max_field];
- }
- }
-
- // sort brackets by 2nd column (Max values)
- uasort($temp, Array(&$this, 'compareBrackets') );
- reset($temp);
- $first_item = each($temp);
- $first_item_key = $first_item['key'];
-
- $linked_info = $object->getLinkedInfo();
- $sql = 'SELECT %s FROM %s WHERE %s = %s';
- $ids = $this->Conn->GetCol( sprintf($sql, $object->IDField, $object->TableName, $linked_info['ForeignKey'], $linked_info['ParentId']) );
- if( is_array($ids) )
- {
- usort($ids, Array(&$this, 'sortBracketIDs') );
- }
-
-// $min_id = min( min($ids) - 1, -1 );
-
- foreach($temp as $key => $record)
- {
- $temp[$key][$this->min_field] = $start;
- $start = $temp[$key][$this->max_field];
- }
- }
-
- $this->setBrackets($event, $temp);
-
- return $temp;
- }
-
- function compareBrackets($bracket1, $bracket2) // ap_bracket_comp
- {
- $bracket1_min = $bracket1[$this->min_field];
- $bracket1_max = $bracket1[$this->max_field];
-
- $bracket2_min = $bracket2[$this->min_field];
- $bracket2_max = $bracket2[$this->max_field];
-
- // limits
- if( ($bracket1_min != '') && ($bracket1_max == '') && ($bracket2_min != '') && ($bracket2_max != '') ) return 1;
- if( ($bracket1_min != '') && ($bracket1_max == '') && ($bracket2_min == '') && ($bracket2_max == '') ) return -1;
- if( ($bracket1_max == '') && ($bracket2_max != '') ) return 1;
- if( ($bracket1_max != '') && ($bracket2_max == '') ) return -1;
-
-
- if( ( ($bracket1_max > $bracket2_max) && ($bracket2_max != -1) ) || ( ($bracket1_max == -1) && ($bracket2_max != -1) ) )
- {
- return 1;
- }
- elseif( ($bracket1_max < $bracket2_max) || ( ($bracket2_max == -1) && ($bracket1_max != -1) ) )
- {
- return -1;
- }
- else
- {
- return 0;
- }
- }
-
- function sortBracketIDs($first_id, $second_id) // pr_bracket_id_sort
- {
- $first_abs = abs($first_id);
- $second_abs = abs($second_id);
-
- $first_sign = ($first_id == 0) ? 0 : $first_id / $first_abs;
- $second_sign = ($second_id == 0) ? 0 : $second_id / $second_abs;
-
- if($first_sign != $second_sign)
- {
- if($first_id > $second_id)
- {
- $bigger =& $first_abs;
- $smaller =& $second_abs;
- }
- else
- {
- $bigger =& $second_abs;
- $smaller =& $first_abs;
- }
- $smaller = $bigger + $smaller;
- }
-
- return ($first_abs > $second_abs) ? 1 : ($first_abs < $second_abs ? -1 : 0);
- }
-
- /**
- * Searches through submitted grid data to find record with specific value in specific field
- *
- * @param Array $records // grid data from REQUEST
- * @param string $field
- * @param string $value
- * @return bool
- */
- function arraySearch($records, $field, $value) // check_array
- {
- foreach ($records as $record)
- {
- if ($record[$field] == $value)
- {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Replate infinity mark with -1 before saving to db
- *
- * @param kEvent $event
- */
- function replaceInfinity(&$event)
- {
- $object =& $event->getObject();
- if($object->GetDBField($this->max_field) == '&#8734;') $object->SetDBField($this->max_field, -1);
- }
-
- }
\ No newline at end of file
Property changes on: branches/5.0.x/core/units/general/brackets.php
___________________________________________________________________
Deleted: cvs2svn:cvs-rev
## -1 +0,0 ##
-1.4.26.2
\ No newline at end of property
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
Deleted: svn:keywords
## -1 +0,0 ##
-Id
\ No newline at end of property
Index: branches/5.0.x/core/units/general/general_config.php
===================================================================
--- branches/5.0.x/core/units/general/general_config.php (revision 12308)
+++ branches/5.0.x/core/units/general/general_config.php (revision 12309)
@@ -1,53 +1,50 @@
<?php
/**
* @version $Id$
* @package In-Portal
* @copyright Copyright (C) 1997 - 2009 Intechnic. All rights reserved.
* @license GNU/GPL
* In-Portal is Open Source software.
* This means that this software may have been modified pursuant
* the GNU General Public License, and as distributed it includes
* or is derivative of works licensed under the GNU General Public License
* or other free or open source software licenses.
* See http://www.in-portal.net/license/ for copyright notices and details.
*/
defined('FULL_PATH') or die('restricted access!');
$config = Array (
'Prefix' => 'm',
'EventHandlerClass' => Array ('class' => 'kEventHandler', 'file' => '', 'build_event' => 'OnBuild'),
// 'TagProcessorClass' => Array ('class' => 'kMainTagProcessor', 'file' => '', 'build_event' => 'OnBuild'),
'QueryString' => Array (
1 => 'cat_id',
2 => 'cat_page',
3 => 'lang',
4 => 'theme',
5 => 'opener',
6 => 'wid',
),
'TitleField' => 'CachedNavbar',
'TitlePhrase' => 'la_Text_Category',
'CatalogTabIcon' => 'icon16_folder.gif',
'ItemType' => 1,
'TableName' => TABLE_PREFIX . 'Category',
'CatalogItem' => true,
'PortalStyleEnv' => true,
'RewritePriority' => 100,
'RewriteListener' => 'ModRewriteHelper:MainRewriteListener',
'PermTabText' => 'In-Portal',
'PermSection' => Array ('search' => 'in-portal:configuration_search', 'custom' => 'in-portal:configuration_custom'),
'RegisterClasses' => Array (
- Array ('class' => 'InpCustomFieldsHelper', 'pseudo' => 'InpCustomFieldsHelper', 'file' => 'custom_fields.php', 'build_event' => '', 'require_classes' => 'kHelper'),
- Array ('class' => 'kCountryStatesHelper', 'pseudo' => 'CountryStatesHelper', 'file' => 'country_states.php', 'build_event' => '', 'require_classes' => 'kHelper'),
- Array ('class' => 'kBracketsHelper', 'pseudo' => 'BracketsHelper', 'file' => 'brackets.php', 'build_event' => '', 'require_classes' => 'kHelper'),
- Array ('class' => 'kXMLHelper', 'pseudo' => 'kXMLHelper', 'file' => 'xml_helper.php', 'build_event' => '', 'require_classes' => 'kHelper'),
+
),
);
\ No newline at end of file

Event Timeline