Index: trunk/core/kernel/db/db_tag_processor.php =================================================================== diff -u -N -r8029 -r8067 --- trunk/core/kernel/db/db_tag_processor.php (.../db_tag_processor.php) (revision 8029) +++ trunk/core/kernel/db/db_tag_processor.php (.../db_tag_processor.php) (revision 8067) @@ -1436,7 +1436,16 @@ case 'multiselect': case 'radio': $field_options = $object->GetFieldOptions($field, 'options'); + + if ($object->GetDBField('DirectOptions')) { + // used for custom fields + $field_options['options'] = $object->GetDBField('DirectOptions'); + } + else { + // used for configuration $field_options['options'] = $helper->GetValuesHash( $object->GetDBField($params['value_list_field']) ); + } + $object->SetFieldOptions($field, $field_options); break; Index: trunk/core/kernel/db/dblist.php =================================================================== diff -u -N -r7702 -r8067 --- trunk/core/kernel/db/dblist.php (.../dblist.php) (revision 7702) +++ trunk/core/kernel/db/dblist.php (.../dblist.php) (revision 8067) @@ -202,6 +202,26 @@ } /** + * Reads filter content + * + * @param string $name filter name (for internal use) + * @param int $filter_type is filter having filter or where filter + * @param int $filter_scope filter subtype: FLT_NORMAL,FLT_SYSTEM,FLT_SEARCH,FLT_VIEW,FLT_CUSTOM + * @access public + */ + function getFilter($name, $filter_type = WHERE_FILTER, $filter_scope = FLT_SYSTEM) + { + $filter_source = Array( WHERE_FILTER => 'WhereFilter', + HAVING_FILTER => 'HavingFilter', + AGGREGATE_FILTER => 'AggregateFilter'); + $filter_name = $filter_source[$filter_type]; + + $filter =& $this->$filter_name; + $filter =& $filter[$filter_scope]; + return $filter->getFilter($name); + } + + /** * Removes specified filter from filters list * * @param string $name filter name (for internal use) Index: trunk/core/units/general/helpers/helpers_config.php =================================================================== diff -u -N -r7997 -r8067 --- trunk/core/units/general/helpers/helpers_config.php (.../helpers_config.php) (revision 7997) +++ trunk/core/units/general/helpers/helpers_config.php (.../helpers_config.php) (revision 8067) @@ -19,5 +19,6 @@ Array('pseudo'=>'CaptchaHelper','class'=>'kCaptchaHelper','file'=>'captcha_helper.php','build_event'=>'','require_classes'=>'kHelper'), Array('pseudo'=>'PriorityHelper','class'=>'kPriorityHelper','file'=>'priority_helper.php','build_event'=>'','require_classes'=>'kHelper'), Array('pseudo' => 'CurlHelper', 'class' => 'kCurlHelper','file' => 'curl_helper.php', 'build_event' => '', 'require_classes' => Array('kHelper')), + Array('pseudo'=>'CountHelper','class'=>'kCountHelper','file'=>'count_helper.php','build_event'=>'','require_classes'=>'kHelper'), ), ); \ No newline at end of file Index: trunk/core/kernel/application.php =================================================================== diff -u -N -r8029 -r8067 --- trunk/core/kernel/application.php (.../application.php) (revision 8029) +++ trunk/core/kernel/application.php (.../application.php) (revision 8067) @@ -2461,6 +2461,36 @@ { return $this->Conn->TableFound($table_name); } + + /** + * Returns counter value + * + * @param string $name counter name + * @param Array $params counter parameters + * @param string $query_name specify query name directly (don't generate from parmeters) + * @param bool $multiple_results + * @return mixed + */ + function getCounter($name, $params = Array (), $query_name = null, $multiple_results = false) + { + $count_helper =& $this->Application->recallObject('CountHelper'); + /* @var $count_helper kCountHelper */ + + return $count_helper->getCounter($name, $params, $query_name, $multiple_results); + } + + /** + * Resets counter, whitch are affected by one of specified tables + * + * @param string $tables comma separated tables list used in counting sqls + */ + function resetCounters($tables) + { + $count_helper =& $this->Application->recallObject('CountHelper'); + /* @var $count_helper kCountHelper */ + + return $count_helper->resetCounters($tables); + } } ?> \ No newline at end of file Index: trunk/core/kernel/utility/temp_handler.php =================================================================== diff -u -N -r8061 -r8067 --- trunk/core/kernel/utility/temp_handler.php (.../temp_handler.php) (revision 8061) +++ trunk/core/kernel/utility/temp_handler.php (.../temp_handler.php) (revision 8067) @@ -601,6 +601,7 @@ } }*/ $this->DropTempTable($master['TableName']); + $this->Application->resetCounters($master['TableName']); if (!isset($this->savedIDs[ $master['Prefix'] ])) { $this->savedIDs[ $master['Prefix'] ] = Array(); @@ -688,6 +689,7 @@ array_push($this->DroppedTables, $table); $this->DroppedTables = array_unique($this->DroppedTables); $this->Conn->Query($query); + return true; } Index: trunk/core/units/general/helpers/search_helper.php =================================================================== diff -u -N -r7702 -r8067 --- trunk/core/units/general/helpers/search_helper.php (.../search_helper.php) (revision 7702) +++ trunk/core/units/general/helpers/search_helper.php (.../search_helper.php) (revision 8067) @@ -509,9 +509,60 @@ $this->Application->RemovePersistentVar($event->getPrefixSpecial().'_custom_filter.'.$view_name); } - - - + /** + * Creates filters based on "types" & "except" parameters from PrintList + * + * @param kEvent $event + * @param Array $type_clauses + * @param string $types + * @param string $except_types + */ + function SetComplexFilter(&$event, &$type_clauses, $types, $except_types) + { + $includes_or_filter =& $this->Application->makeClass('kMultipleFilter', FLT_TYPE_OR); + $excepts_and_filter =& $this->Application->makeClass('kMultipleFilter', FLT_TYPE_AND); + + $includes_or_filter_h =& $this->Application->makeClass('kMultipleFilter', FLT_TYPE_OR); + $excepts_and_filter_h =& $this->Application->makeClass('kMultipleFilter', FLT_TYPE_AND); + + if ($types) { + $types = explode(',', $types); + foreach ($types as $type) { + $type = trim($type); + + if (isset($type_clauses[$type])) { + if ($type_clauses[$type]['having_filter']) { + $includes_or_filter_h->addFilter('filter_'.$type, $type_clauses[$type]['include']); + } else { + $includes_or_filter->addFilter('filter_'.$type, $type_clauses[$type]['include']); + } + } + } + } + + if ($except_types) { + $except_types = explode(',', $except_types); + foreach ($except_types as $type) { + $type = trim($type); + + if (isset($type_clauses[$type])) { + if ($type_clauses[$type]['having_filter']) { + $excepts_and_filter_h->addFilter('filter_'.$type, $type_clauses[$type]['except']); + } else { + $excepts_and_filter->addFilter('filter_'.$type, $type_clauses[$type]['except']); + } + } + } + } + + $object =& $event->getObject(); + + $object->addFilter('includes_filter', $includes_or_filter); + $object->addFilter('excepts_filter', $excepts_and_filter); + + $object->addFilter('includes_filter_h', $includes_or_filter_h, HAVING_FILTER); + $object->addFilter('excepts_filter_h', $excepts_and_filter_h, HAVING_FILTER); + } } ?> \ No newline at end of file Index: trunk/core/units/general/helpers/count_helper.php =================================================================== diff -u -N --- trunk/core/units/general/helpers/count_helper.php (revision 0) +++ trunk/core/units/general/helpers/count_helper.php (revision 8067) @@ -0,0 +1,102 @@ + 0) AND (LastCounted < '.adodb_mktime().' - LifeTime)'; + $this->Conn->Query($sql); + } + + /** + * Returns counter value + * + * @param string $name counter name + * @param Array $params counter parameters + * @param string $query_name specify query name directly (don't generate from parmeters) + * @param bool $multiple_results + * @return mixed + */ + function getCounter($name, $params = Array (), $query_name = null, $multiple_results = false) + { + $clone_counter = false; + $query_name = isset($query_name) ? $query_name : rtrim($name.'-'.implode('-', array_values($params)), '-'); + $sql = 'SELECT * + FROM '.TABLE_PREFIX.'Counters + WHERE Name = '.$this->Conn->qstr($query_name); + $count_data = $this->Conn->GetRow($sql); + + if (!$count_data && ($query_name != $name)) { + // cloned record not found -> search for origial one + $sql = 'SELECT * + FROM '.TABLE_PREFIX.'Counters + WHERE Name = '.$this->Conn->qstr($name); + $count_data = $this->Conn->GetRow($sql); + $clone_counter = true; + } + + if (is_null($count_data['CountValue'])) { + $params['PREFIX'] = TABLE_PREFIX; + $count_sql = $count_data['CountQuery']; + + foreach ($params as $replace_from => $replace_to) { + $count_sql = str_replace('<%'.$replace_from.'%>', $replace_to, $count_sql); + } + + if ($multiple_results) { + $count_data['CountValue'] = serialize($this->Conn->GetCol($count_sql)); + } + else { + $count_data['CountValue'] = $this->Conn->GetOne($count_sql); + } + + if ($clone_counter && !$count_data['IsClone']) { + // don't clone clones + $count_data['CounterId'] = 0; + $count_data['Name'] = $query_name; + $count_data['CountQuery'] = $count_sql; + $count_data['IsClone'] = 1; + } + + $count_data['LastCounted'] = adodb_mktime(); + $this->Conn->doInsert($count_data, TABLE_PREFIX.'Counters', 'REPLACE'); + } + + return $multiple_results ? unserialize($count_data['CountValue']) : $count_data['CountValue']; + } + + /** + * Resets counter, whitch are affected by one of specified tables + * + * @param string $tables comma separated tables list used in counting sqls + */ + function resetCounters($tables) + { + echo 'resetting counters ['.$tables.']
'; + + $tables = explode(',', $tables); + $prefix_length = strlen(TABLE_PREFIX); + foreach ($tables as $index => $table) { + // remove prefixes + if (substr($table, 0, $prefix_length) == TABLE_PREFIX) { + $table = substr($table, $prefix_length); + } + $tables[$index] = '(TablesAffected LIKE "%|'.$table.'|%")'; + } + + $sql = 'UPDATE '.TABLE_PREFIX.'Counters + SET CountValue = NULL + WHERE '.implode(' OR ', $tables); + + $this->Conn->Query($sql); + } + + } + +?> \ No newline at end of file Index: trunk/core/kernel/db/dbitem.php =================================================================== diff -u -N -r8065 -r8067 --- trunk/core/kernel/db/dbitem.php (.../dbitem.php) (revision 8065) +++ trunk/core/kernel/db/dbitem.php (.../dbitem.php) (revision 8067) @@ -396,6 +396,9 @@ $this->saveCustomFields(); $this->raiseEvent('OnAfterItemUpdate'); $this->Loaded = true; + if ($this->mode != 't') { + $this->Application->resetCounters($this->TableName); + } return true; } @@ -725,6 +728,9 @@ } $this->saveCustomFields(); + if ($this->mode != 't') { + $this->Application->resetCounters($this->TableName); + } $this->raiseEvent('OnAfterItemCreate'); $this->Loaded = true; return true; @@ -749,7 +755,9 @@ $this->setModifiedFlag(); $this->raiseEvent('OnAfterItemDelete'); - + if ($this->mode != 't') { + $this->Application->resetCounters($this->TableName); + } return $ret; } Index: trunk/core/units/users/users_event_handler.php =================================================================== diff -u -N -r7855 -r8067 --- trunk/core/units/users/users_event_handler.php (.../users_event_handler.php) (revision 7855) +++ trunk/core/units/users/users_event_handler.php (.../users_event_handler.php) (revision 8067) @@ -109,6 +109,8 @@ function OnSessionExpire() { + $this->Application->resetCounters('UserSession'); + if ($this->Application->IsAdmin()) { $this->Application->Redirect('index', Array('expired' => 1), '', 'index.php'); } @@ -300,6 +302,7 @@ $sync_manager =& $this->Application->recallObjectP('UsersSyncronizeManager', null, Array(), 'InPortalSyncronize'); $sync_manager->performAction('LoginUser', $object->GetDBField('Login'), $password); + $this->Application->resetCounters('UserSession'); } /** @@ -351,6 +354,7 @@ $event->SetRedirectParam('js_redirect', 1); } + $this->Application->resetCounters('UserSession'); $event->SetRedirectParam('pass', 'm'); } @@ -447,7 +451,7 @@ if($user_email) { // check if is subscriber - $verify_user =& $this->Application->recallObject('u.verify', null, Array('skup_autoload' => true) ); + $verify_user =& $this->Application->recallObject('u.verify', null, Array('skip_autoload' => true) ); $verify_user->Load($user_email, 'Email'); if( $verify_user->isLoaded() && $verify_user->isSubscriberOnly() ) { Index: trunk/core/units/custom_fields/custom_fields_config.php =================================================================== diff -u -N -r8061 -r8067 --- trunk/core/units/custom_fields/custom_fields_config.php (.../custom_fields_config.php) (revision 8061) +++ trunk/core/units/custom_fields/custom_fields_config.php (.../custom_fields_config.php) (revision 8067) @@ -88,6 +88,7 @@ 'Value' => Array('type' => 'string', 'default' => ''), 'OriginalValue' => Array('type' => 'string', 'default' => ''), 'Error' => Array('type' => 'string', 'default' => ''), + 'DirectOptions' => Array('type' => 'string', 'default' => '') ), Index: trunk/core/units/configuration/configuration_config.php =================================================================== diff -u -N -r8015 -r8067 --- trunk/core/units/configuration/configuration_config.php (.../configuration_config.php) (revision 8015) +++ trunk/core/units/configuration/configuration_config.php (.../configuration_config.php) (revision 8067) @@ -72,6 +72,7 @@ 'DisplayOrder' => Array('type' => 'double', 'not_null' => '1', 'default' => 0), 'GroupDisplayOrder' => Array('type' => 'double', 'not_null' => '1', 'default' => 0), 'Install' => Array('type' => 'int', 'not_null' => '1', 'default' => 1), + 'DirectOptions' => Array('type' => 'string', 'default' => ''), ), 'Grids' => Array(), Index: trunk/core/units/configuration/configuration_tag_processor.php =================================================================== diff -u -N -r6093 -r8067 --- trunk/core/units/configuration/configuration_tag_processor.php (.../configuration_tag_processor.php) (revision 6093) +++ trunk/core/units/configuration/configuration_tag_processor.php (.../configuration_tag_processor.php) (revision 8067) @@ -59,6 +59,7 @@ if ($field_values) { $list->SetDBField('VariableValue', $field_values[$list->GetDBField('VariableName')]['VariableValue']); } + $list->SetDBField('DirectOptions', ''); $o.= $this->Application->ParseBlock($block_params, 1); $prev_heading = $list->GetDBField('heading'); Index: trunk/core/kernel/utility/filters.php =================================================================== diff -u -N -r2600 -r8067 --- trunk/core/kernel/utility/filters.php (.../filters.php) (revision 2600) +++ trunk/core/kernel/utility/filters.php (.../filters.php) (revision 8067) @@ -59,6 +59,17 @@ } /** + * Returns filter by name + * + * @param string $name + * @return string + */ + function getFilter($name) + { + return isset($this->filters[$name]) ? $this->filters[$name] : false; + } + + /** * Removes specified filter from filters list * * @param string $name Index: trunk/core/units/custom_fields/custom_fields_tag_processor.php =================================================================== diff -u -N -r6583 -r8067 --- trunk/core/units/custom_fields/custom_fields_tag_processor.php (.../custom_fields_tag_processor.php) (revision 6583) +++ trunk/core/units/custom_fields/custom_fields_tag_processor.php (.../custom_fields_tag_processor.php) (revision 8067) @@ -74,6 +74,8 @@ $source_prefix = getArrayValue($params, 'SourcePrefix'); if ($source_prefix) { $source_object =& $this->Application->recallObject($source_prefix); + /* @var $source_object kCatDBItem */ + $display_original = $this->Application->ProcessParsedTag($source_prefix, 'DisplayOriginal', Array('display_original' => $this->setParamValue($params, 'display_original'))); } @@ -98,6 +100,9 @@ } $block_params['field'] = $block_params['virtual_field'] = 'cust_'.$list->GetDBField('FieldName'); $block_params['show_heading'] = ($prev_heading != $list->GetDBField('Heading') ) ? 1 : 0; + + $options = $source_object->GetFieldOptions('cust_'.$list->GetDBField('FieldName')); + $list->SetDBField('DirectOptions', isset($options['options']) ? $options['options'] : false); } $o.= $this->Application->ParseBlock($block_params, 1); Index: trunk/core/kernel/kbase.php =================================================================== diff -u -N -r8061 -r8067 --- trunk/core/kernel/kbase.php (.../kbase.php) (revision 8061) +++ trunk/core/kernel/kbase.php (.../kbase.php) (revision 8067) @@ -225,6 +225,7 @@ function SwitchToLive() { $this->TableName = $this->Application->getUnitOption($this->Prefix, 'TableName'); + $this->mode = ''; } /**