Index: trunk/core/kernel/db/db_tag_processor.php =================================================================== diff -u -N -r3163 -r3307 --- trunk/core/kernel/db/db_tag_processor.php (.../db_tag_processor.php) (revision 3163) +++ trunk/core/kernel/db/db_tag_processor.php (.../db_tag_processor.php) (revision 3307) @@ -825,7 +825,35 @@ return $this->PrintPages($params); } + /** + * Returns field name (processed by kMultiLanguage formatter + * if required) and item's id from it's IDField or field required + * + * @param Array $params + * @return Array (id,field) + * @access private + */ + function prepareInputName($params) + { + $field = $params['field']; + $object =& $this->Application->recallObject($this->getPrefixSpecial(), $this->Prefix, $params); + + $formatter_class = getArrayValue($object->Fields, $field, 'formatter'); + if ($formatter_class == 'kMultiLanguage') + { + $formatter =& $this->Application->recallObject($formatter_class); + $field = $formatter->LangFieldName($field); + } + + $id_field = getArrayValue($params, 'IdField'); + $id = $id_field ? $object->GetDBField($id_field) : $object->GetID(); + + return Array($id, $field); + } + + + /** * Returns input field name to * be placed on form (for correct * event processing) @@ -836,30 +864,30 @@ */ function InputName($params) { - $prefix_special=$this->getPrefixSpecial(); - $object =& $this->Application->recallObject($prefix_special); + list($id, $field) = $this->prepareInputName($params); - if ( $formatter = getArrayValue($object->Fields, $params['field'], 'formatter') ) { - if ( $formatter == 'kMultiLanguage' ) { - $formatter =& $this->Application->recallObject($formatter); - $params['field'] = $formatter->LangFieldName($params['field']); - } - } + $ret = $this->getPrefixSpecial().'['.$id.']['.$field.']'; + if( getArrayValue($params, 'as_preg') ) $ret = preg_quote($ret, '/'); + return $ret; + } + + /** + * Allows to override various field options through hidden fields with specific names in submit. + * This tag generates this special names + * + * @param Array $params + * @return string + * @author Alex + */ + function FieldModifier($params) + { + list($id, $field) = $this->prepareInputName($params); - if ( $idfield = getArrayValue($params, 'IdField') ) { - $id = $object->GetDBField($idfield); - } - else { - $id = $object->GetID(); - } - - $ret = $prefix_special.'['.$id.']['.$params['field'].']'; + $ret = 'field_modifiers['.$this->getPrefixSpecial().']['.$field.']['.$params['type'].']'; if( getArrayValue($params, 'as_preg') ) $ret = preg_quote($ret, '/'); return $ret; } - - /** * Returns index where 1st changable sorting field begins * @@ -1399,6 +1427,7 @@ } return '../../'.$module_folder.'/admin_templates/'; } + } ?> \ No newline at end of file Index: trunk/core/units/users/users_item.php =================================================================== diff -u -N -r3306 -r3307 --- trunk/core/units/users/users_item.php (.../users_item.php) (revision 3306) +++ trunk/core/units/users/users_item.php (.../users_item.php) (revision 3307) @@ -13,16 +13,16 @@ } - function Configure() + function defineFields() { - parent::Configure(); + parent::defineFields(); + // add custom fields definitions (as virtual fields) $add_fields = Array(); $custom_field_options = Array('default' => '', 'not_null' => 1); foreach ($this->CustomFields as $custom_field => $custom_id) { $add_fields[$custom_field] = $custom_field_options; - $this->SetDBField($custom_field, ''); } if($add_fields) Index: trunk/index.php =================================================================== diff -u -N -r3216 -r3307 --- trunk/index.php (.../index.php) (revision 3216) +++ trunk/index.php (.../index.php) (revision 3307) @@ -11,6 +11,9 @@ $application->Run(); $application->Done(); +/*$application->Debugger->appendHTML('Objects if kDBItem, kDBList class created ('.count($application->APCalled).'):'); +print_pre($application->APCalled);*/ + $end = getmicrotime(); if ( $application->isDebugMode() ) Index: trunk/kernel/units/users/users_item.php =================================================================== diff -u -N -r3306 -r3307 --- trunk/kernel/units/users/users_item.php (.../users_item.php) (revision 3306) +++ trunk/kernel/units/users/users_item.php (.../users_item.php) (revision 3307) @@ -13,16 +13,16 @@ } - function Configure() + function defineFields() { - parent::Configure(); + parent::defineFields(); + // add custom fields definitions (as virtual fields) $add_fields = Array(); $custom_field_options = Array('default' => '', 'not_null' => 1); foreach ($this->CustomFields as $custom_field => $custom_id) { $add_fields[$custom_field] = $custom_field_options; - $this->SetDBField($custom_field, ''); } if($add_fields) Index: trunk/kernel/units/languages/languages_event_handler.php =================================================================== diff -u -N -r3282 -r3307 --- trunk/kernel/units/languages/languages_event_handler.php (.../languages_event_handler.php) (revision 3282) +++ trunk/kernel/units/languages/languages_event_handler.php (.../languages_event_handler.php) (revision 3307) @@ -47,7 +47,14 @@ } } } - if($sqls) $this->Conn->Query( implode("\n",$sqls) ); + + if($sqls) + { + foreach ($sqls as $sql_query) + { + $this->Conn->Query($sql_query); + } + } } /** Index: trunk/core/units/languages/languages_event_handler.php =================================================================== diff -u -N -r3282 -r3307 --- trunk/core/units/languages/languages_event_handler.php (.../languages_event_handler.php) (revision 3282) +++ trunk/core/units/languages/languages_event_handler.php (.../languages_event_handler.php) (revision 3307) @@ -47,7 +47,14 @@ } } } - if($sqls) $this->Conn->Query( implode("\n",$sqls) ); + + if($sqls) + { + foreach ($sqls as $sql_query) + { + $this->Conn->Query($sql_query); + } + } } /** Index: trunk/core/kernel/kbase.php =================================================================== diff -u -N -r3282 -r3307 --- trunk/core/kernel/kbase.php (.../kbase.php) (revision 3282) +++ trunk/core/kernel/kbase.php (.../kbase.php) (revision 3307) @@ -304,11 +304,23 @@ { $this->setTableName( $this->Application->getUnitOption($this->Prefix, 'TableName') ); $this->setIDField( $this->Application->getUnitOption($this->Prefix, 'IDField') ); + + $this->defineFields(); + + $this->ApplyFieldModifiers(); // should be called only after all fields definitions been set + $this->prepareConfigOptions(); // this should go last, but before setDefaultValues, order is significant! + $this->SetDefaultValues(); + } + + /** + * Add field definitions from all possible sources (DB Fields, Virtual Fields, Calcualted Fields, e.t.c.) + * + */ + function defineFields() + { $this->setConfigFields( $this->Application->getUnitOption($this->Prefix, 'Fields') ); $this->setVirtualFields( $this->Application->getUnitOption($this->Prefix, 'VirtualFields') ); $this->setCalculatedFields( $this->Application->getUnitOption($this->Prefix, 'CalculatedFields') ); - $this->prepareConfigOptions(); // this should go last, but before setDefaultValues, order is significant! - $this->SetDefaultValues(); } function setCalculatedFields($fields) @@ -325,10 +337,38 @@ */ function setConfigFields($fields) { - $this->Fields=$fields; + $this->Fields = $fields; } /** + * Override field options with ones defined in submit via "field_modfiers" array (common for all prefixes) + * + * @access private + * @author Alex + */ + function ApplyFieldModifiers() + { +// $this->Application->APCalled[] = $this->getPrefixSpecial(); + + $allowed_modifiers = Array('required'); + + $field_modifiers = $this->Application->GetVar('field_modifiers'); + if(!$field_modifiers) return false; + + $field_modifiers = getArrayValue($field_modifiers, $this->getPrefixSpecial()); + if(!$field_modifiers) return false; + + foreach ($field_modifiers as $field => $field_options) + { + foreach ($field_options as $option_name => $option_value) + { + if ( !in_array(strtolower($option_name), $allowed_modifiers) ) continue; + $this->Fields[$field][$option_name] = $option_value; + } + } + } + + /** * Set fields (+options) for fields that physically doesn't exist in database * * @param Array $fields