Index: trunk/kernel/units/custom_fields/custom_fields_event_handler.php =================================================================== diff -u -N -r4017 -r4029 --- trunk/kernel/units/custom_fields/custom_fields_event_handler.php (.../custom_fields_event_handler.php) (revision 4017) +++ trunk/kernel/units/custom_fields/custom_fields_event_handler.php (.../custom_fields_event_handler.php) (revision 4029) @@ -12,9 +12,19 @@ { $object =& $event->getObject(); - $item_type=$this->Application->GetVar('cf_type'); - $object->addFilter('itemtype_filter', '%1$s.Type = '.$item_type); - //$object->AddOrderField('DisplayOrder', 'ASC'); + $item_type = $this->Application->GetVar('cf_type'); + if (!$item_type) { + $prefix = $event->getEventParam('SourcePrefix'); + $item_type = $this->Application->getUnitOption($prefix, 'ItemType'); + } + + if ($event->Special == 'general') { + $object->addFilter('generaltab_filter', '%1$s.OnGeneralTab = 1'); + } + + if ($item_type) { + $object->addFilter('itemtype_filter', '%1$s.Type = '.$item_type); + } } /** Index: trunk/kernel/units/custom_values/custom_values_config.php =================================================================== diff -u -N --- trunk/kernel/units/custom_values/custom_values_config.php (revision 3210) +++ trunk/kernel/units/custom_values/custom_values_config.php (revision 0) @@ -1,135 +0,0 @@ - 'cv', - 'ItemClass' => Array('class'=>'kDBItem','file'=>'','build_event'=>'OnItemBuild'), - 'ListClass' => Array('class'=>'kDBList','file'=>'','build_event'=>'OnListBuild'), - 'EventHandlerClass' => Array('class'=>'CustomValuesEventHandler','file'=>'custom_value_event_handler.php','build_event'=>'OnBuild'), - 'TagProcessorClass' => Array('class'=>'kDBTagProcessor','file'=>'','build_event'=>'OnBuild'), - - 'Clones' => Array( - 'cv-l' => Array( - 'ParentPrefix' => 'l', - 'Hooks' => Array( - Array( - 'Mode' => hAFTER, - 'Conditional' => true, - 'HookToPrefix' => 'l', - 'HookToSpecial' => '', - 'HookToEvent' => Array( 'onPreSave' ), - 'DoPrefix' => '', - 'DoSpecial' => '', - 'DoEvent' => 'onPreSave', - ), - Array( - 'Mode' => hAFTER, - 'Conditional' => true, - 'HookToPrefix' => 'l', - 'HookToSpecial' => '', - 'HookToEvent' => Array( 'onPreSave' ), - 'DoPrefix' => '', - 'DoSpecial' => 'general', - 'DoEvent' => 'onPreSave', - ), - ), - ), - - 'cv' => Array( - 'Hooks' => Array( - Array( - 'Mode' => hAFTER, - 'Conditional' => true, - 'HookToPrefix' => 'p', - 'HookToSpecial' => '', - 'HookToEvent' => Array( 'onPreSave' ), - 'DoPrefix' => '', - 'DoSpecial' => '', - 'DoEvent' => 'onPreSave', - ), - Array( - 'Mode' => hAFTER, - 'Conditional' => true, - 'HookToPrefix' => 'p', - 'HookToSpecial' => '', - 'HookToEvent' => Array( 'onPreSave' ), - 'DoPrefix' => '', - 'DoSpecial' => 'general', - 'DoEvent' => 'onPreSave', - ), - ), - ), - ), - - 'AutoLoad' => true, - - 'QueryString' => Array( - 1 => 'id', - 2 => 'page', - 3 => 'event', - ), - - 'TableName' => TABLE_PREFIX.'CustomMetaData', - 'IDField' => 'CustomDataId', // in this case idfield doesn't exit in destination table - - 'ParentTableKey'=> 'ResourceId', - 'ForeignKey' => 'ResourceId', - 'ParentPrefix' => 'p', - 'AutoDelete' => true, - 'AutoClone' => true, - - 'CalculatedFields' => Array( - '' => Array ( - 'FieldName' => 'cf.FieldName', - 'Prompt' => 'cf.Prompt', - 'CustomFieldId' => 'cf.CustomFieldId', - 'ElementType' => 'cf.ElementType', - 'ValueList' => 'cf.ValueList', - 'DisplayOrder' => 'cf.DisplayOrder', - 'CustomDataId' => '%1$s.CustomDataId', - ) - ), - - 'ListSQLs' => Array( - '' => ' SELECT %1$s.l1_Value AS l1_Value, #ITEM_RESOURCE_ID# AS ResourceId %2$s - FROM '.TABLE_PREFIX.'CustomField AS cf - LEFT JOIN %1$s ON %1$s.CustomFieldId = cf.CustomFieldId AND ResourceId = #ITEM_RESOURCE_ID#', - ), // key - special, value - list select sql - - - - 'ItemSQLs' => Array( ''=>'SELECT * FROM %s', - ), - 'ListSortings' => Array( - '' => Array( - 'ForcedSorting' => Array('DisplayOrder' => 'asc', 'FieldName' => 'asc'), - ) - ), - - 'Fields' => Array( - 'CustomDataId' => Array(), - 'CustomFieldId' => Array('not_null' => '1', 'default'=>''), - 'ResourceId' => Array('not_null' => 1, 'default' => 0), - 'Value' => Array('not_null' => true, 'formatter' => 'kMultiLanguage', 'default' => ''), - ), - 'VirtualFields' => Array( - 'FieldName' => Array(), - 'Prompt' => Array(), - 'ElementType' => Array(), - 'ValueList' => Array(), - 'DisplayOrder' => Array('type' => 'float', 'default' => 0), - - ), - - 'Grids' => Array( - 'Default' => Array( - 'Icons' => Array('default'=>'icon16_custom.gif'), // icons for each StatusField values, if no matches or no statusfield selected, then "default" icon is used - 'Fields' => Array( - 'FieldName' => Array( 'title'=>'la_col_FieldName', 'data_block' => 'grid_icon_td'), - 'Prompt' => Array( 'title'=>'la_col_Prompt', 'data_block' => 'grid_data_label_ml_td' ), - 'Value' => Array( 'title'=>'la_col_Value', 'data_block' => 'edit_custom_td'), - ), - ), - ), - ); - -?> \ No newline at end of file Index: trunk/kernel/units/custom_values/custom_value_event_handler.php =================================================================== diff -u -N --- trunk/kernel/units/custom_values/custom_value_event_handler.php (revision 3723) +++ trunk/kernel/units/custom_values/custom_value_event_handler.php (revision 0) @@ -1,96 +0,0 @@ -getObject(); - - $top_prefix = $this->Application->GetTopmostPrefix($event->Prefix); - $item_type = $this->Application->getUnitOption($top_prefix, 'ItemType'); - - $item_resource_id = $this->GetParentResourceId($event); - - // there is no ResourceId when creating new item, but we need some id for SQL to work - if (!$item_resource_id) $item_resource_id = 0; - - $sql = str_replace('#ITEM_RESOURCE_ID#',$item_resource_id,$object->SelectClause); - $object->setSelectSQL($sql); - - $object->removeFilter('parent_filter'); - $object->addFilter('itemtype_filter', 'Type = '.$item_type); - if ($event->Special=='general') $object->addFilter('generaltab_filter','OnGeneralTab = 1'); - - $object->SetPerPage(-1); - } - - /** - * Enter description here... - * - * @param kEvent $event - * @return unknown - */ - function GetParentResourceId(&$event) - { - $object =& $event->getObject(); - $top_object =& $this->Application->RecallObject( $this->Application->GetTopmostPrefix($event->Prefix) ); - return $top_object->GetDBField('ResourceId'); - } - - function OnPreSave(&$event) - { - $object =& $event->getObject(); - - $items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) ); - if($items_info) - { - $lang_id = $this->Application->GetVar('m_lang'); - foreach($items_info as $custom_field_id => $values) - { - $set_values = Array( - 'CustomFieldId' => $custom_field_id, - 'l'.$lang_id.'_Value' => $values['l'.$lang_id.'_Value'], - 'ResourceId' => $values['ResourceId'] != 0 ? $values['ResourceId'] : $this->GetParentResourceId($event), - ); - - // ResourceId will be -1 if we are creating new product, then we get ID directly, - // because it should be already set by parent' event, as we are in hAFTER hook - - $id = $values['CustomDataId']; - if ($id) { //if it's already existing custom field record - update id - $object->SetDefaultValues(); - $object->Load($id); - $object->SetFieldsFromHash($set_values); - if( $object->Update($id) ) - { - $event->status=erSUCCESS; - } - else - { - $event->status=erFAIL; - $event->redirect=false; - break; - } - } - else { //new custom field record - create it and set temp id! - $object->SetDefaultValues(); - $object->SetFieldsFromHash($set_values); - if( $object->Create(null, true) ) - { - $object->setTempID(); - $event->status=erSUCCESS; - } - } - } - } - - // this is critical, as the object here is Item, but if something fails, the template could use the same name as grid - // the problem appeared on products general tab, when validation does not go through for product, - // and the templates is getting parsed - $this->Application->removeObject($event->Prefix_Special); - - } -} - -?> \ No newline at end of file Index: trunk/core/kernel/parser/template_parser.php =================================================================== diff -u -N -r3556 -r4029 --- trunk/core/kernel/parser/template_parser.php (.../template_parser.php) (revision 3556) +++ trunk/core/kernel/parser/template_parser.php (.../template_parser.php) (revision 4029) @@ -81,6 +81,12 @@ return isset($this->Params[$name]) ? $this->Params[$name] : false; } + /** + * Set's template parser parameter, that could be retrieved from template + * + * @param string $name + * @param mixed $value + */ function SetParam($name, $value) { $this->Params[strtolower($name)] = $value; @@ -257,8 +263,13 @@ //getting prefix_tag upto first space, tab or line break into regs[1] preg_match("/^([^ \t\n]*)(.*)/", $tag, $regs); $tag_part = $regs[1]; + if (strpos($tag_part, '_') !== false) { list($prefix, $the_tag) = explode('_', $tag, 2); + /*preg_match('/(.*)_(.*)/', $tag_part, $rets); + $prefix = $rets[1]; + $the_tag = $rets[2].$regs[2];*/ + $tag = $prefix.':'.$the_tag; } else { Index: trunk/core/kernel/db/dbitem.php =================================================================== diff -u -N -r3868 -r4029 --- trunk/core/kernel/db/dbitem.php (.../dbitem.php) (revision 3868) +++ trunk/core/kernel/db/dbitem.php (.../dbitem.php) (revision 4029) @@ -45,7 +45,7 @@ * @access public */ var $ID; - + function kDBItem() { parent::kDBBase(); @@ -372,7 +372,8 @@ if (!$system_update && $affected == 1){ $this->setModifiedFlag(); } - + + $this->saveCustomFields(); $this->raiseEvent('OnAfterItemUpdate'); return true; } @@ -651,7 +652,6 @@ $this->FieldValues[$this->IDField] = $this->generateID(); } - $fields_sql = ''; $values_sql = ''; foreach ($this->FieldValues as $field_name => $field_value) @@ -692,6 +692,7 @@ $this->setModifiedFlag(); } + $this->saveCustomFields(); $this->raiseEvent('OnAfterItemCreate'); return true; } @@ -889,6 +890,26 @@ } trigger_error('Query method is called in class '.get_class($this).' for prefix '.$this->getPrefixSpecial().'', E_USER_ERROR); } + + function saveCustomFields() + { + if (!$this->customFields) { + return true; + } + + $cdata_key = rtrim($this->Prefix.'-cdata.'.$this->Special, '.'); + $cdata =& $this->Application->recallObject($cdata_key, null, Array('skip_autoload' => true)); + + $resource_id = $this->GetDBField('ResourceId'); + $cdata->Load($resource_id, 'ResourceId'); + $cdata->SetDBField('ResourceId', $resource_id); + + $ml_formatter =& $this->Application->recallObject('kMultiLanguage'); + foreach ($this->customFields as $custom_id => $custom_name) { + $cdata->SetDBField($ml_formatter->LangFieldName('cust_'.$custom_id), $this->GetDBField('cust_'.$custom_name)); + } + return $cdata->isLoaded() ? $cdata->Update() : $cdata->Create(); + } } Index: trunk/kernel/admin_templates/incs/script.js =================================================================== diff -u -N -r3624 -r4029 --- trunk/kernel/admin_templates/incs/script.js (.../script.js) (revision 3624) +++ trunk/kernel/admin_templates/incs/script.js (.../script.js) (revision 4029) @@ -216,7 +216,7 @@ submit_event(split_prefix[0],'OnPreSaveAndOpenTranslator'); } -function PreSaveAndOpenTranslatorCV(prefix,field,t,cf_id,multi_line) +function PreSaveAndOpenTranslatorCV(prefix,field,t,resource_id,multi_line) { if(!isset($window_name)) var $window_name = 'select_'+t.replace(/(\/|-)/g, '_'); if(!isset(multi_line)) multi_line=0; @@ -225,9 +225,9 @@ set_hidden_field('translator_field', field); set_hidden_field('translator_t', t); set_hidden_field('translator_prefixes', prefix); - set_hidden_field('translator_cf_id', cf_id); + set_hidden_field('translator_resource_id', resource_id); set_hidden_field('translator_multi_line', multi_line); - document.kernel_form.target=$window_name; + document.kernel_form.target = $window_name; var split_prefix = prefix.split(','); submit_event(split_prefix[0],'OnPreSaveAndOpenTranslator'); Index: trunk/core/units/custom_data/custom_data_event_handler.php =================================================================== diff -u -N --- trunk/core/units/custom_data/custom_data_event_handler.php (revision 0) +++ trunk/core/units/custom_data/custom_data_event_handler.php (revision 4029) @@ -0,0 +1,7 @@ + \ No newline at end of file Index: trunk/core/units/categories/categories_config.php =================================================================== diff -u -N -r3787 -r4029 --- trunk/core/units/categories/categories_config.php (.../categories_config.php) (revision 3787) +++ trunk/core/units/categories/categories_config.php (.../categories_config.php) (revision 4029) @@ -21,7 +21,7 @@ ), 'IDField' => 'CategoryId', 'TitleField' => 'Name', // field, used in bluebar when editing existing item - 'ItemType' => 0, // this is used when relation to product is added from in-portal and via-versa + 'ItemType' => 1, // used for custom fields only 'TableName' => TABLE_PREFIX.'Category', 'ViewMenuPhrase' => 'la_text_Categories', @@ -31,18 +31,14 @@ ), - 'ListSQLs' => Array( ''=> 'SELECT %1$s.* %2$s, - IF(%1$s.NewItem = 2, - IF(%1$s.CreatedOn >= (UNIX_TIMESTAMP() - 10*3600*24), 1, 0), - %1$s.NewItem) AS IsNew '. // 10 - Category_NewDays value from ConfigurationValues table - 'FROM %1$s - LEFT JOIN '.TABLE_PREFIX.'PermCache ON '.TABLE_PREFIX.'PermCache.CategoryId = %1$s.CategoryId'), - // key - special, value - list select sql - 'ItemSQLs' => Array( ''=> 'SELECT *, - IF(%1$s.NewItem = 2, - IF(%1$s.CreatedOn >= (UNIX_TIMESTAMP() - 10*3600*24), 1, 0), - %1$s.NewItem) AS IsNew '. // 10 - Category_NewDays value from ConfigurationValues table - 'FROM %s'), + 'ListSQLs' => Array( ''=> ' SELECT %1$s.* %2$s + FROM %1$s + LEFT JOIN '.TABLE_PREFIX.'PermCache ON '.TABLE_PREFIX.'PermCache.CategoryId = %1$s.CategoryId + LEFT JOIN '.TABLE_PREFIX.'%3$sCategoryCustomData cust ON %1$s.ResourceId = cust.ResourceId'), + + 'ItemSQLs' => Array( ''=> ' SELECT %1$s.* %2$s + FROM %1$s + LEFT JOIN '.TABLE_PREFIX.'%3$sCategoryCustomData cust ON %1$s.ResourceId = cust.ResourceId'), 'ListSortings' => Array( '' => Array( @@ -87,6 +83,7 @@ 'VirtualFields' => Array( 'CurrentSort' => Array('type' => 'string', 'default' => ''), + 'IsNew' => Array('type' => 'int', 'default' => 0), ), 'Grids' => Array( Index: trunk/kernel/units/custom_fields/custom_fields_tag_processor.php =================================================================== diff -u -N --- trunk/kernel/units/custom_fields/custom_fields_tag_processor.php (revision 0) +++ trunk/kernel/units/custom_fields/custom_fields_tag_processor.php (revision 4029) @@ -0,0 +1,90 @@ +getObject($params); + $parent_item =& $this->Application->recallObject($params['SourcePrefix']); + + $field = $this->SelectParam($params, 'name,field'); + return $parent_item->GetField('cust_'.$object->GetField($field)); + } + + function CustomInputName($params) + { + $object =& $this->getObject($params); + $source_prefix = $this->Application->Parser->GetParam('SourcePrefix'); + + $source_tp =& $this->Application->recallTagProcessor($source_prefix); + $params['name'] = 'cust_'.$object->GetDBField('FieldName'); + return $source_tp->InputName($params); + } + + /** + * Prints list content using block specified + * + * @param Array $params + * @return string + * @access public + */ + function PrintList($params) + { + $list =& $this->GetList($params); + $id_field = $this->Application->getUnitOption($this->Prefix,'IDField'); + + $list->Query(); + $o = ''; + $list->GoFirst(); + + $block_params=$this->prepareTagParams($params); + $block_params['name'] = $this->SelectParam($params, 'render_as,block'); + $block_params['pass_params'] = 'true'; + + $prev_heading = ''; + $source_prefix = getArrayValue($params, 'SourcePrefix'); + if ($source_prefix) { + $source_object =& $this->Application->recallObject($source_prefix); + } + + if ($this->Special == 'general') { + $this->sortCustomFields($list->Records); + } + + while (!$list->EOL()) + { + $this->Application->SetVar( $this->getPrefixSpecial().'_id', $list->GetDBField($id_field) ); // for edit/delete links using GET + + if ($source_prefix) { + $list->SetDBField($params['value_field'], $source_object->GetDBField('cust_'.$list->GetDBField('FieldName'))); + $block_params['show_heading'] = ($prev_heading != $list->GetDBField('Heading') ) ? 1 : 0; + } + + $o.= $this->Application->ParseBlock($block_params, 1); + $prev_heading = $list->GetDBField('Heading'); + $list->GoNext(); + } + + $this->Application->SetVar( $this->getPrefixSpecial().'_id', ''); + return $o; + } + + + + function sortCustomFields(&$records) + { + $sorted = Array(); + $i = 0; $record_count = count($records); + while ($i < $record_count) { + $sorted[ $records[$i]['Heading'] ][] = $records[$i]; + $i++; + } + + $records = Array(); + foreach ($sorted as $heading => $heading_records) { + $records = array_merge_recursive($records, $heading_records); + } + } + } + +?> \ No newline at end of file Index: trunk/core/kernel/parser/tags.php =================================================================== diff -u -N -r3456 -r4029 --- trunk/core/kernel/parser/tags.php (.../tags.php) (revision 3456) +++ trunk/core/kernel/parser/tags.php (.../tags.php) (revision 4029) @@ -13,7 +13,8 @@ } - function &GetTag($tag_data, &$parser, $inp_tag=0) { + function &GetTag($tag_data, &$parser, $inp_tag = 0) + { if (!isset($this->_Tag)) { $this->_Tag =& new Tag($tag_data, $parser, $inp_tag); } Index: trunk/kernel/admin_templates/incs/custom_blocks.tpl =================================================================== diff -u -N -r2716 -r4029 --- trunk/kernel/admin_templates/incs/custom_blocks.tpl (.../custom_blocks.tpl) (revision 2716) +++ trunk/kernel/admin_templates/incs/custom_blocks.tpl (.../custom_blocks.tpl) (revision 4029) @@ -1,46 +1,44 @@ - - " value="" /> - + + " /> + - - " id="" value="" /> - " id="verify_" value="" /> -  "> - + + + +   + - + - + - - + - + - - " name="" value=""> - " type="checkbox" id="_cb_" name="_cb_" class="" onclick="update_checkbox(this, document.getElementById(''))"> - + + "> + " type="checkbox" id="_cb_" name="_cb_" class="" onclick="update_checkbox(this, document.getElementById(''))"> + - - - + + + - - name="" id="_" value="">  - + + name="" id="_" value="">  + - - - + + + - + - - + " id="" value=""> + " id="" value=""> + - \ No newline at end of file +--> \ No newline at end of file Index: trunk/core/units/categories/categories_event_handler.php =================================================================== diff -u -N -r3445 -r4029 --- trunk/core/units/categories/categories_event_handler.php (.../categories_event_handler.php) (revision 3445) +++ trunk/core/units/categories/categories_event_handler.php (.../categories_event_handler.php) (revision 4029) @@ -230,6 +230,25 @@ $this->Application->StoreVar('PermCache_UpdateRequired', 1); $event->SetRedirectParam('index_file', 'category/category_maint.php'); } + + /** + * Adds calculates fields for item statuses + * + * @param kCatDBItem $object + * @param kEvent $event + */ + function prepareObject(&$object, &$event) + { + $object =& $event->getObject( Array('skip_autoload' => true) ); + + $object->addCalculatedField('IsNew', ' IF(%1$s.NewItem = 2, + IF(%1$s.CreatedOn >= (UNIX_TIMESTAMP() - '. + $this->Application->ConfigValue('Category_DaysNew'). + '*3600*24), 1, 0), + %1$s.NewItem + )'); + + } } ?> \ No newline at end of file Index: trunk/core/units/translator/translator_event_handler.php =================================================================== diff -u -N -r3723 -r4029 --- trunk/core/units/translator/translator_event_handler.php (.../translator_event_handler.php) (revision 3723) +++ trunk/core/units/translator/translator_event_handler.php (.../translator_event_handler.php) (revision 4029) @@ -7,24 +7,14 @@ { $field = $this->Application->GetVar($event->getPrefixSpecial(true).'_field'); - if( strpos($field,':') !== false ) - { + if (strpos($field,':') !== false) { list($obj_prefix,$field) = explode(':', $field); } - else - { + else { $obj_prefix = $this->Application->GetVar($event->getPrefixSpecial(true).'_prefix'); } $object =& $this->Application->recallObject($obj_prefix); - - /*$items_info = $this->Application->GetVar( $obj_prefix ); - if($items_info) $field_values = array_shift($items_info); - $object->SetFieldsFromHash($field_values); - $object->Update();*/ - - - $translator =& $this->Application->recallObject($event->getPrefixSpecial()); $def_lang = $this->Application->GetDefaultLanguageId(); @@ -37,8 +27,7 @@ }*/ $this->Application->StoreVar('trans_lang', $current_lang); //remember translation language for user friendlyness - - $translator->SetId(1); + $translator->SetID(1); $translator->SetDBField('Original', $object->GetDBField('l'.$this->Application->GetVar('m_lang').'_'.$field)); $translator->SetDBField('Language', $current_lang); $translator->SetDBField('SwitchLanguage', $current_lang); Index: trunk/core/units/general/cat_event_handler.php =================================================================== diff -u -N -r3852 -r4029 --- trunk/core/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 3852) +++ trunk/core/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 4029) @@ -112,42 +112,36 @@ $object =& $event->getObject(); $this->RemoveRequiredFields($object); $event->CallSubEvent('OnPreSave'); + if ($event->status == erSUCCESS) { -// $url = $this->Application->HREF($t, '', Array('pass'=>'all', $event->getPrefixSpecial(true).'_id' => $object->GetId())); -// $field = $this->Application->GetVar('translator_field'); - $cf_id = $this->Application->GetVar('translator_cf_id'); - if($cf_id) - { - $cv =& $this->Application->recallObject('cv.-item', null, Array('skip_autoload' => true) ); - $load_params = Array('CustomFieldId' => $cf_id, 'ResourceId'=> $object->GetDBField('ResourceId') ); - if( !$cv->Load($load_params) ) - { - $cv->SetFieldsFromHash($load_params); - $cv->Create(); + + $resource_id = $this->Application->GetVar('translator_resource_id'); + if ($resource_id) { + $t_prefixes = explode(',', $this->Application->GetVar('translator_prefixes')); + + $cdata =& $this->Application->recallObject($t_prefixes[1], null, Array('skip_autoload' => true)); + $cdata->Load($resource_id, 'ResourceId'); + if (!$cdata->isLoaded()) { + $cdata->SetDBField('ResourceId', $resource_id); + $cdata->Create(); } - $this->Application->SetVar('cv_id', $cv->getID() ); + $this->Application->SetVar($cdata->getPrefixSpecial().'_id', $cdata->GetID()); } $event->redirect = $this->Application->GetVar('translator_t'); $event->redirect_params = Array('pass'=>'all,trans,'.$this->Application->GetVar('translator_prefixes'), - $event->getPrefixSpecial(true).'_id' => $object->GetId(), - 'trans_event'=>'OnLoad', - 'trans_prefix'=> $this->Application->GetVar('translator_prefixes'), - 'trans_field'=>$this->Application->GetVar('translator_field'), - 'trans_multi_line'=>$this->Application->GetVar('translator_multi_line'), + $event->getPrefixSpecial(true).'_id' => $object->GetID(), + 'trans_event' => 'OnLoad', + 'trans_prefix' => $this->Application->GetVar('translator_prefixes'), + 'trans_field' => $this->Application->GetVar('translator_field'), + 'trans_multi_line' => $this->Application->GetVar('translator_multi_line'), ); // 1. SAVE LAST TEMPLATE TO SESSION $last_template = $this->Application->RecallVar('last_template'); preg_match('/index4\.php\|'.$this->Application->GetSID().'-(.*):/U', $last_template, $rets); -// $this->Application->StoreVar('return_template', $rets[1]); $this->Application->StoreVar('return_template', $this->Application->GetVar('t')); - - //$after_script = "openTranslator('".$event->getPrefixSpecial()."', '".$field."', '".$url."', '".$wnd_name."')"; } - -// $this->Application->SetVar('after_script', $after_script); -// $event->redirect = false; } /** Index: trunk/core/units/custom_data/custom_data_config.php =================================================================== diff -u -N -r4016 -r4029 --- trunk/core/units/custom_data/custom_data_config.php (.../custom_data_config.php) (revision 4016) +++ trunk/core/units/custom_data/custom_data_config.php (.../custom_data_config.php) (revision 4029) @@ -10,6 +10,11 @@ 'ParentPrefix' => 'u', ), + 'c-cdata' => Array( + 'TableName' => TABLE_PREFIX.'CategoryCustomData', + 'ParentPrefix' => 'c', + ), + 'l-cdata' => Array( 'TableName' => TABLE_PREFIX.'LinkCustomData', 'ParentPrefix' => 'l', @@ -31,7 +36,11 @@ ), ), - + 'QueryString' => Array( + 1 => 'id', + 2 => 'event', + ), + 'ItemClass' => Array('class' => 'kDBItem', 'file' => '','build_event' => 'OnItemBuild'), 'ListClass' => Array('class' => 'kDBList', 'file' => '','build_event' => 'OnListBuild'), 'EventHandlerClass' => Array('class' => 'kDBEventHandler', 'file' => '', 'build_event' => 'OnBuild'), Index: trunk/admin/install/inportal_schema.sql =================================================================== diff -u -N -r4010 -r4029 --- trunk/admin/install/inportal_schema.sql (.../inportal_schema.sql) (revision 4010) +++ trunk/admin/install/inportal_schema.sql (.../inportal_schema.sql) (revision 4029) @@ -712,4 +712,10 @@ ResourceId int(10) unsigned NOT NULL default '0', PRIMARY KEY (CustomDataId) ) -# -------------------------------------------------------- \ No newline at end of file +# -------------------------------------------------------- +CREATE TABLE CategoryCustomData ( + CustomDataId int(11) NOT NULL auto_increment, + ResourceId int(10) unsigned NOT NULL default '0', + PRIMARY KEY (`CustomDataId`) +) +# -------------------------------------------------------- Index: trunk/kernel/units/users/users_config.php =================================================================== diff -u -N -r3907 -r4029 --- trunk/kernel/units/users/users_config.php (.../users_config.php) (revision 3907) +++ trunk/kernel/units/users/users_config.php (.../users_config.php) (revision 4029) @@ -50,10 +50,14 @@ 'ItemType' => 6, // used for custom fields only (on user's case) 'TableName' => TABLE_PREFIX.'PortalUser', - 'ListSQLs' => Array( ''=>'SELECT * FROM %s', - ), // key - special, value - list select sql - 'ItemSQLs' => Array( ''=>'SELECT * FROM %s', - ), + 'ListSQLs' => Array( '' => ' SELECT %1$s.* %2$s FROM %1$s + LEFT JOIN '.TABLE_PREFIX.'%3$sPortalUserCustomData cust ON %1$s.ResourceId = cust.ResourceId', + ), + + 'ItemSQLs' => Array( '' => ' SELECT %1$s.* %2$s FROM %1$s + LEFT JOIN '.TABLE_PREFIX.'%3$sPortalUserCustomData cust ON %1$s.ResourceId = cust.ResourceId', + ), + 'ListSortings' => Array( '' => Array( 'Sorting' => Array('Login' => 'asc'), Index: trunk/kernel/admin/include/navmenu.php =================================================================== diff -u -N -r2388 -r4029 --- trunk/kernel/admin/include/navmenu.php (.../navmenu.php) (revision 2388) +++ trunk/kernel/admin/include/navmenu.php (.../navmenu.php) (revision 4029) @@ -52,8 +52,8 @@ NULL,"in-portal:site", "in-portal:configuration_search", "in-portal:configuration_custom",0,"",1, NULL,NULL,NULL,$admin."/icons/icon46_list_settings_email.gif","la_updating_config"); -$objSections->AddSection("in-portal:configuration_custom","la_tab_ConfigCustom","la_tab_ConfigCustom",$admin."/config/", - "edit_customfields.php?§ion=in-portal:configuration_custom&DataType=1", +$objSections->AddSection("in-portal:configuration_custom","la_tab_ConfigCustom","la_tab_ConfigCustom",$admin.'/index4.php', + 'kernel4:custom_fields/custom_fields_list:cf----1-', $admin."/icons/icon46_settings_custom.gif",$admin."/icons/icon24_settings_custom.gif", NULL, "in-portal:site", "in-portal:configuration_email", NULL,0,"",1,NULL,NULL,NULL,$admin."/icons/icon46_list_settings_custom.gif","la_updating_config"); @@ -219,8 +219,8 @@ NULL,"in-link", "in-portal:configure_users", "in-portal:user_custom",0,"",1, NULL,NULL,NULL,$admin."/icons/icon46_list_settings_email.gif","la_updating_config"); -$objSections->AddSection("in-portal:user_custom","la_tab_ConfigCustom","la_tab_ConfigCustom",$admin."/config/", - "edit_customfields.php?§ion=in-portal:user_custom&DataType=6", +$objSections->AddSection("in-portal:user_custom","la_tab_ConfigCustom","la_tab_ConfigCustom",$admin.'/index4.php', + 'kernel4:custom_fields/custom_fields_list:cf----6-', $admin."/icons/icon46_settings_custom.gif",$admin."/icons/icon24_settings_custom.gif", NULL, "in-portal:users", "in-portal:user_email", "in-portal:user_banlist",0,"",1, NULL,NULL,NULL,$admin."/icons/icon46_list_settings_custom.gif","la_updating_config"); Index: trunk/core/kernel/db/db_event_handler.php =================================================================== diff -u -N -r4008 -r4029 --- trunk/core/kernel/db/db_event_handler.php (.../db_event_handler.php) (revision 4008) +++ trunk/core/kernel/db/db_event_handler.php (.../db_event_handler.php) (revision 4029) @@ -1579,6 +1579,9 @@ WHERE Type = '.$item_type.' ORDER BY CustomFieldId'; $custom_fields = $this->Conn->GetCol($sql, 'CustomFieldId'); + if (!$custom_fields) { + return false; + } // 2. create fields (for customdata item) $fields = $this->Application->getUnitOption($event->Prefix, 'Fields', Array()); @@ -1587,12 +1590,20 @@ $fields['cust_'.$custom_id] = $field_options; } $this->Application->setUnitOption($event->Prefix, 'Fields', $fields); - - - /*// 3. create virtual & calculated fields (for main item) + + // 3. create virtual & calculated fields (for main item) $calculated_fields = $this->Application->getUnitOption($main_prefix.'.', 'CalculatedFields', Array()); - $virtual_fields = $this->Application->getUnitOption($main_prefix, 'VirtualFields', Array());*/ + $virtual_fields = $this->Application->getUnitOption($main_prefix, 'VirtualFields', Array()); + $ml_formatter =& $this->Application->recallObject('kMultiLanguage'); + $field_options = Array('type' => 'string', 'not_null' => 1, 'default' => ''); + foreach ($custom_fields as $custom_id => $custom_name) { + $calculated_fields['cust_'.$custom_name] = 'cust.'.$ml_formatter->LangFieldName('cust_'.$custom_id); + $virtual_fields['cust_'.$custom_name] = $field_options; + } + $this->Application->setUnitOption($main_prefix, 'CustomFields', $custom_fields); + $this->Application->setUnitOption($main_prefix.'.', 'CalculatedFields', $calculated_fields); + $this->Application->setUnitOption($main_prefix, 'VirtualFields', $virtual_fields); } } Index: trunk/kernel/units/custom_fields/custom_fields_config.php =================================================================== diff -u -N -r4000 -r4029 --- trunk/kernel/units/custom_fields/custom_fields_config.php (.../custom_fields_config.php) (revision 4000) +++ trunk/kernel/units/custom_fields/custom_fields_config.php (.../custom_fields_config.php) (revision 4029) @@ -5,7 +5,7 @@ 'ItemClass' => Array('class'=>'kDBItem','file'=>'','build_event'=>'OnItemBuild'), 'ListClass' => Array('class'=>'kDBList','file'=>'','build_event'=>'OnListBuild'), 'EventHandlerClass' => Array('class'=>'CustomFieldsEventHandler','file'=>'custom_fields_event_handler.php','build_event'=>'OnBuild'), - 'TagProcessorClass' => Array('class'=>'kDBTagProcessor','file'=>'','build_event'=>'OnBuild'), + 'TagProcessorClass' => Array('class'=>'CustomFieldsTagProcessor','file'=>'custom_fields_tag_processor.php','build_event'=>'OnBuild'), 'AutoLoad' => true, 'hooks' => Array(), 'QueryString' => Array( @@ -57,10 +57,15 @@ ), // key - special, value - list select sql 'ListSortings' => Array( - '' => Array( - 'ForcedSorting' => Array('DisplayOrder' => 'asc'), - 'Sorting' => Array('FieldName' => 'asc'), - ) + '' => Array( + 'ForcedSorting' => Array('DisplayOrder' => 'asc'), + 'Sorting' => Array('FieldName' => 'asc'), + ), + + 'general' => Array( + 'Sorting' => Array('DisplayOrder' => 'asc') + ), + ), 'ItemSQLs' => Array( ''=>'SELECT * FROM %s', @@ -79,7 +84,9 @@ 'DisplayOrder' => Array('type' => 'int','not_null' => '1','default' => '0'), 'OnGeneralTab' => Array('type' => 'int','not_null' => '1','default' => '0'), ), - 'VirtualFields' => Array(), + 'VirtualFields' => Array( + 'Value' => Array('type' => 'string', 'default' => ''), + ), 'Grids' => Array( 'Default' => Array( @@ -92,6 +99,15 @@ ), ), + 'SeparateTab' => Array( + 'Icons' => Array('default'=>'icon16_custom.gif'), + 'Fields' => Array( + 'FieldName' => Array( 'title'=>'la_col_FieldName', 'data_block' => 'grid_icon_td'), + 'Prompt' => Array( 'title'=>'la_col_Prompt', 'data_block' => 'grid_data_label_ml_td' ), + 'Value' => Array( 'title'=>'la_col_Value', 'data_block' => 'edit_custom_td'), + ), + ), + ), ); Index: trunk/kernel/admin_templates/incs/grid_blocks.tpl =================================================================== diff -u -N -r3863 -r4029 --- trunk/kernel/admin_templates/incs/grid_blocks.tpl (.../grid_blocks.tpl) (revision 3863) +++ trunk/kernel/admin_templates/incs/grid_blocks.tpl (.../grid_blocks.tpl) (revision 4029) @@ -150,9 +150,9 @@ :
- , 1);" title=""> + ,-cdata', '-cdata:cust_', 'popups/translator', , 1);" title=""> - );" title=""> + ,-cdata', '-cdata:cust_', 'popups/translator', );" title=""> @@ -236,10 +236,12 @@ - + @@ -273,7 +275,7 @@ - + Index: trunk/core/kernel/utility/formatters.php =================================================================== diff -u -N -r3983 -r4029 --- trunk/core/kernel/utility/formatters.php (.../formatters.php) (revision 3983) +++ trunk/core/kernel/utility/formatters.php (.../formatters.php) (revision 4029) @@ -742,7 +742,7 @@ $this->Application->setUnitOption($object->Prefix, 'VirtualFields', $virtual_fields); //substitude grid fields - $grids = $this->Application->getUnitOption($object->Prefix, 'Grids'); + $grids = $this->Application->getUnitOption($object->Prefix, 'Grids', Array()); foreach ($grids as $name => $grid) { if ( getArrayValue($grid, 'Fields', $field_name) ) { array_rename_key($grids[$name]['Fields'], $field_name, $lang_field_name); @@ -751,7 +751,7 @@ $this->Application->setUnitOption($object->Prefix, 'Grids', $grids); //substitude default sortings - $sortings = $this->Application->getUnitOption($object->Prefix, 'ListSortings'); + $sortings = $this->Application->getUnitOption($object->Prefix, 'ListSortings', Array()); foreach ($sortings as $special => $the_sortings) { if (isset($the_sortings['ForcedSorting'])) { array_rename_key($sortings[$special]['ForcedSorting'], $field_name, $lang_field_name); Index: trunk/core/units/general/helpers/multilanguage.php =================================================================== diff -u -N -r4017 -r4029 --- trunk/core/units/general/helpers/multilanguage.php (.../multilanguage.php) (revision 4017) +++ trunk/core/units/general/helpers/multilanguage.php (.../multilanguage.php) (revision 4029) @@ -185,7 +185,12 @@ } } } - $ret .= 'ADD COLUMN '.sprintf($field_mask, $start_index).' AFTER `'.$prev_field.'`, '; + + $field_expression = sprintf($field_mask, $start_index); + $ret .= 'ADD COLUMN '.$field_expression.' AFTER `'.$prev_field.'`, '; + + list($field_name, $field_params) = explode(' ', $field_expression, 2); + $ret .= 'ADD INDEX (`'.$field_name.'` (5) ), '; $start_index++; } return preg_replace('/, $/',';',$ret); Index: trunk/core/kernel/db/db_tag_processor.php =================================================================== diff -u -N -r3983 -r4029 --- trunk/core/kernel/db/db_tag_processor.php (.../db_tag_processor.php) (revision 3983) +++ trunk/core/kernel/db/db_tag_processor.php (.../db_tag_processor.php) (revision 4029) @@ -553,7 +553,19 @@ return $value; } - + + function SetField($params) + { + // + + $object =& $this->getObject($params); + $dst_field = $this->SelectParam($params, 'name,field'); + + list($prefix_special, $src_field) = explode(':', $params['src']); + $src_object =& $this->Application->recallObject($prefix_special); + $object->SetDBField($dst_field, $src_object->GetDBField($src_field)); + } + /** * Checks if parameter is passed * Note: works like Tag and line simple method too @@ -860,7 +872,7 @@ */ function prepareInputName($params) { - $field = $params['field']; + $field = $this->SelectParam($params, 'name,field'); $object =& $this->getObject($params); $formatter_class = getArrayValue($object->Fields, $field, 'formatter'); @@ -1257,28 +1269,19 @@ */ function CustomField($params) { - $object =& $this->getObject($params); - - $field = $this->SelectParam($params, 'name,field'); - - $lang_id = $this->Application->GetVar('m_lang'); - - $sql = ' SELECT cv.l'.$lang_id.'_Value FROM '.TABLE_PREFIX.'CustomField cf - LEFT JOIN '.TABLE_PREFIX.'CustomMetaData cv - ON cf.CustomFieldId = cv.CustomFieldId - WHERE cf.Type = '.$this->Application->getUnitOption($this->Prefix, 'ItemType').' - AND cv.ResourceId = '.$object->GetDBField('ResourceId').' - AND cf.FieldName = "'.$field.'"'; - return $this->Conn->GetOne($sql); + $params['name'] = 'cust_'.$this->SelectParam($params, 'name,field'); + return $this->Field($params); } function CustomFieldLabel($params) { - $object =& $this->Application->recallObject($this->Prefix); // not using Special here (for what purpose ?) + $object =& $this->getObject($params); $field = $this->SelectParam($params, 'name,field'); - $sql = ' SELECT FieldLabel FROM '.TABLE_PREFIX.'CustomField WHERE FieldName = "'.$field.'"'; + $sql = 'SELECT FieldLabel + FROM '.$this->Application->getUnitOption('cf', 'TableName').' + WHERE FieldName = '.$this->Conn->qstr($field); return $this->Application->Phrase($this->Conn->GetOne($sql)); } Index: trunk/kernel/units/custom_data/custom_data_event_handler.php =================================================================== diff -u -N --- trunk/kernel/units/custom_data/custom_data_event_handler.php (revision 0) +++ trunk/kernel/units/custom_data/custom_data_event_handler.php (revision 4029) @@ -0,0 +1,7 @@ + \ No newline at end of file Index: trunk/core/units/custom_fields/custom_fields_event_handler.php =================================================================== diff -u -N -r4017 -r4029 --- trunk/core/units/custom_fields/custom_fields_event_handler.php (.../custom_fields_event_handler.php) (revision 4017) +++ trunk/core/units/custom_fields/custom_fields_event_handler.php (.../custom_fields_event_handler.php) (revision 4029) @@ -12,9 +12,19 @@ { $object =& $event->getObject(); - $item_type=$this->Application->GetVar('cf_type'); - $object->addFilter('itemtype_filter', '%1$s.Type = '.$item_type); - //$object->AddOrderField('DisplayOrder', 'ASC'); + $item_type = $this->Application->GetVar('cf_type'); + if (!$item_type) { + $prefix = $event->getEventParam('SourcePrefix'); + $item_type = $this->Application->getUnitOption($prefix, 'ItemType'); + } + + if ($event->Special == 'general') { + $object->addFilter('generaltab_filter', '%1$s.OnGeneralTab = 1'); + } + + if ($item_type) { + $object->addFilter('itemtype_filter', '%1$s.Type = '.$item_type); + } } /** Index: trunk/kernel/units/categories/categories_config.php =================================================================== diff -u -N -r3787 -r4029 --- trunk/kernel/units/categories/categories_config.php (.../categories_config.php) (revision 3787) +++ trunk/kernel/units/categories/categories_config.php (.../categories_config.php) (revision 4029) @@ -21,7 +21,7 @@ ), 'IDField' => 'CategoryId', 'TitleField' => 'Name', // field, used in bluebar when editing existing item - 'ItemType' => 0, // this is used when relation to product is added from in-portal and via-versa + 'ItemType' => 1, // used for custom fields only 'TableName' => TABLE_PREFIX.'Category', 'ViewMenuPhrase' => 'la_text_Categories', @@ -31,18 +31,14 @@ ), - 'ListSQLs' => Array( ''=> 'SELECT %1$s.* %2$s, - IF(%1$s.NewItem = 2, - IF(%1$s.CreatedOn >= (UNIX_TIMESTAMP() - 10*3600*24), 1, 0), - %1$s.NewItem) AS IsNew '. // 10 - Category_NewDays value from ConfigurationValues table - 'FROM %1$s - LEFT JOIN '.TABLE_PREFIX.'PermCache ON '.TABLE_PREFIX.'PermCache.CategoryId = %1$s.CategoryId'), - // key - special, value - list select sql - 'ItemSQLs' => Array( ''=> 'SELECT *, - IF(%1$s.NewItem = 2, - IF(%1$s.CreatedOn >= (UNIX_TIMESTAMP() - 10*3600*24), 1, 0), - %1$s.NewItem) AS IsNew '. // 10 - Category_NewDays value from ConfigurationValues table - 'FROM %s'), + 'ListSQLs' => Array( ''=> ' SELECT %1$s.* %2$s + FROM %1$s + LEFT JOIN '.TABLE_PREFIX.'PermCache ON '.TABLE_PREFIX.'PermCache.CategoryId = %1$s.CategoryId + LEFT JOIN '.TABLE_PREFIX.'%3$sCategoryCustomData cust ON %1$s.ResourceId = cust.ResourceId'), + + 'ItemSQLs' => Array( ''=> ' SELECT %1$s.* %2$s + FROM %1$s + LEFT JOIN '.TABLE_PREFIX.'%3$sCategoryCustomData cust ON %1$s.ResourceId = cust.ResourceId'), 'ListSortings' => Array( '' => Array( @@ -87,6 +83,7 @@ 'VirtualFields' => Array( 'CurrentSort' => Array('type' => 'string', 'default' => ''), + 'IsNew' => Array('type' => 'int', 'default' => 0), ), 'Grids' => Array( Index: trunk/core/units/custom_fields/custom_fields_tag_processor.php =================================================================== diff -u -N --- trunk/core/units/custom_fields/custom_fields_tag_processor.php (revision 0) +++ trunk/core/units/custom_fields/custom_fields_tag_processor.php (revision 4029) @@ -0,0 +1,90 @@ +getObject($params); + $parent_item =& $this->Application->recallObject($params['SourcePrefix']); + + $field = $this->SelectParam($params, 'name,field'); + return $parent_item->GetField('cust_'.$object->GetField($field)); + } + + function CustomInputName($params) + { + $object =& $this->getObject($params); + $source_prefix = $this->Application->Parser->GetParam('SourcePrefix'); + + $source_tp =& $this->Application->recallTagProcessor($source_prefix); + $params['name'] = 'cust_'.$object->GetDBField('FieldName'); + return $source_tp->InputName($params); + } + + /** + * Prints list content using block specified + * + * @param Array $params + * @return string + * @access public + */ + function PrintList($params) + { + $list =& $this->GetList($params); + $id_field = $this->Application->getUnitOption($this->Prefix,'IDField'); + + $list->Query(); + $o = ''; + $list->GoFirst(); + + $block_params=$this->prepareTagParams($params); + $block_params['name'] = $this->SelectParam($params, 'render_as,block'); + $block_params['pass_params'] = 'true'; + + $prev_heading = ''; + $source_prefix = getArrayValue($params, 'SourcePrefix'); + if ($source_prefix) { + $source_object =& $this->Application->recallObject($source_prefix); + } + + if ($this->Special == 'general') { + $this->sortCustomFields($list->Records); + } + + while (!$list->EOL()) + { + $this->Application->SetVar( $this->getPrefixSpecial().'_id', $list->GetDBField($id_field) ); // for edit/delete links using GET + + if ($source_prefix) { + $list->SetDBField($params['value_field'], $source_object->GetDBField('cust_'.$list->GetDBField('FieldName'))); + $block_params['show_heading'] = ($prev_heading != $list->GetDBField('Heading') ) ? 1 : 0; + } + + $o.= $this->Application->ParseBlock($block_params, 1); + $prev_heading = $list->GetDBField('Heading'); + $list->GoNext(); + } + + $this->Application->SetVar( $this->getPrefixSpecial().'_id', ''); + return $o; + } + + + + function sortCustomFields(&$records) + { + $sorted = Array(); + $i = 0; $record_count = count($records); + while ($i < $record_count) { + $sorted[ $records[$i]['Heading'] ][] = $records[$i]; + $i++; + } + + $records = Array(); + foreach ($sorted as $heading => $heading_records) { + $records = array_merge_recursive($records, $heading_records); + } + } + } + +?> \ No newline at end of file Index: trunk/core/admin_templates/incs/custom_blocks.tpl =================================================================== diff -u -N -r2716 -r4029 --- trunk/core/admin_templates/incs/custom_blocks.tpl (.../custom_blocks.tpl) (revision 2716) +++ trunk/core/admin_templates/incs/custom_blocks.tpl (.../custom_blocks.tpl) (revision 4029) @@ -1,46 +1,44 @@ - - " value="" /> - + + " /> + - - " id="" value="" /> - " id="verify_" value="" /> -  "> - + + + +   + - + - + - - + - + - - " name="" value=""> - " type="checkbox" id="_cb_" name="_cb_" class="" onclick="update_checkbox(this, document.getElementById(''))"> - + + "> + " type="checkbox" id="_cb_" name="_cb_" class="" onclick="update_checkbox(this, document.getElementById(''))"> + - - - + + + - - name="" id="_" value="">  - + + name="" id="_" value="">  + - - - + + + - + - - + " id="" value=""> + " id="" value=""> + - \ No newline at end of file +--> \ No newline at end of file Index: trunk/kernel/units/translator/translator_event_handler.php =================================================================== diff -u -N -r3723 -r4029 --- trunk/kernel/units/translator/translator_event_handler.php (.../translator_event_handler.php) (revision 3723) +++ trunk/kernel/units/translator/translator_event_handler.php (.../translator_event_handler.php) (revision 4029) @@ -7,24 +7,14 @@ { $field = $this->Application->GetVar($event->getPrefixSpecial(true).'_field'); - if( strpos($field,':') !== false ) - { + if (strpos($field,':') !== false) { list($obj_prefix,$field) = explode(':', $field); } - else - { + else { $obj_prefix = $this->Application->GetVar($event->getPrefixSpecial(true).'_prefix'); } $object =& $this->Application->recallObject($obj_prefix); - - /*$items_info = $this->Application->GetVar( $obj_prefix ); - if($items_info) $field_values = array_shift($items_info); - $object->SetFieldsFromHash($field_values); - $object->Update();*/ - - - $translator =& $this->Application->recallObject($event->getPrefixSpecial()); $def_lang = $this->Application->GetDefaultLanguageId(); @@ -37,8 +27,7 @@ }*/ $this->Application->StoreVar('trans_lang', $current_lang); //remember translation language for user friendlyness - - $translator->SetId(1); + $translator->SetID(1); $translator->SetDBField('Original', $object->GetDBField('l'.$this->Application->GetVar('m_lang').'_'.$field)); $translator->SetDBField('Language', $current_lang); $translator->SetDBField('SwitchLanguage', $current_lang); Index: trunk/kernel/units/general/cat_event_handler.php =================================================================== diff -u -N -r3852 -r4029 --- trunk/kernel/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 3852) +++ trunk/kernel/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 4029) @@ -112,42 +112,36 @@ $object =& $event->getObject(); $this->RemoveRequiredFields($object); $event->CallSubEvent('OnPreSave'); + if ($event->status == erSUCCESS) { -// $url = $this->Application->HREF($t, '', Array('pass'=>'all', $event->getPrefixSpecial(true).'_id' => $object->GetId())); -// $field = $this->Application->GetVar('translator_field'); - $cf_id = $this->Application->GetVar('translator_cf_id'); - if($cf_id) - { - $cv =& $this->Application->recallObject('cv.-item', null, Array('skip_autoload' => true) ); - $load_params = Array('CustomFieldId' => $cf_id, 'ResourceId'=> $object->GetDBField('ResourceId') ); - if( !$cv->Load($load_params) ) - { - $cv->SetFieldsFromHash($load_params); - $cv->Create(); + + $resource_id = $this->Application->GetVar('translator_resource_id'); + if ($resource_id) { + $t_prefixes = explode(',', $this->Application->GetVar('translator_prefixes')); + + $cdata =& $this->Application->recallObject($t_prefixes[1], null, Array('skip_autoload' => true)); + $cdata->Load($resource_id, 'ResourceId'); + if (!$cdata->isLoaded()) { + $cdata->SetDBField('ResourceId', $resource_id); + $cdata->Create(); } - $this->Application->SetVar('cv_id', $cv->getID() ); + $this->Application->SetVar($cdata->getPrefixSpecial().'_id', $cdata->GetID()); } $event->redirect = $this->Application->GetVar('translator_t'); $event->redirect_params = Array('pass'=>'all,trans,'.$this->Application->GetVar('translator_prefixes'), - $event->getPrefixSpecial(true).'_id' => $object->GetId(), - 'trans_event'=>'OnLoad', - 'trans_prefix'=> $this->Application->GetVar('translator_prefixes'), - 'trans_field'=>$this->Application->GetVar('translator_field'), - 'trans_multi_line'=>$this->Application->GetVar('translator_multi_line'), + $event->getPrefixSpecial(true).'_id' => $object->GetID(), + 'trans_event' => 'OnLoad', + 'trans_prefix' => $this->Application->GetVar('translator_prefixes'), + 'trans_field' => $this->Application->GetVar('translator_field'), + 'trans_multi_line' => $this->Application->GetVar('translator_multi_line'), ); // 1. SAVE LAST TEMPLATE TO SESSION $last_template = $this->Application->RecallVar('last_template'); preg_match('/index4\.php\|'.$this->Application->GetSID().'-(.*):/U', $last_template, $rets); -// $this->Application->StoreVar('return_template', $rets[1]); $this->Application->StoreVar('return_template', $this->Application->GetVar('t')); - - //$after_script = "openTranslator('".$event->getPrefixSpecial()."', '".$field."', '".$url."', '".$wnd_name."')"; } - -// $this->Application->SetVar('after_script', $after_script); -// $event->redirect = false; } /** Index: trunk/kernel/units/categories/categories_event_handler.php =================================================================== diff -u -N -r3445 -r4029 --- trunk/kernel/units/categories/categories_event_handler.php (.../categories_event_handler.php) (revision 3445) +++ trunk/kernel/units/categories/categories_event_handler.php (.../categories_event_handler.php) (revision 4029) @@ -230,6 +230,25 @@ $this->Application->StoreVar('PermCache_UpdateRequired', 1); $event->SetRedirectParam('index_file', 'category/category_maint.php'); } + + /** + * Adds calculates fields for item statuses + * + * @param kCatDBItem $object + * @param kEvent $event + */ + function prepareObject(&$object, &$event) + { + $object =& $event->getObject( Array('skip_autoload' => true) ); + + $object->addCalculatedField('IsNew', ' IF(%1$s.NewItem = 2, + IF(%1$s.CreatedOn >= (UNIX_TIMESTAMP() - '. + $this->Application->ConfigValue('Category_DaysNew'). + '*3600*24), 1, 0), + %1$s.NewItem + )'); + + } } ?> \ No newline at end of file Index: trunk/core/units/users/users_config.php =================================================================== diff -u -N -r3907 -r4029 --- trunk/core/units/users/users_config.php (.../users_config.php) (revision 3907) +++ trunk/core/units/users/users_config.php (.../users_config.php) (revision 4029) @@ -50,10 +50,14 @@ 'ItemType' => 6, // used for custom fields only (on user's case) 'TableName' => TABLE_PREFIX.'PortalUser', - 'ListSQLs' => Array( ''=>'SELECT * FROM %s', - ), // key - special, value - list select sql - 'ItemSQLs' => Array( ''=>'SELECT * FROM %s', - ), + 'ListSQLs' => Array( '' => ' SELECT %1$s.* %2$s FROM %1$s + LEFT JOIN '.TABLE_PREFIX.'%3$sPortalUserCustomData cust ON %1$s.ResourceId = cust.ResourceId', + ), + + 'ItemSQLs' => Array( '' => ' SELECT %1$s.* %2$s FROM %1$s + LEFT JOIN '.TABLE_PREFIX.'%3$sPortalUserCustomData cust ON %1$s.ResourceId = cust.ResourceId', + ), + 'ListSortings' => Array( '' => Array( 'Sorting' => Array('Login' => 'asc'), Index: trunk/kernel/units/custom_data/custom_data_config.php =================================================================== diff -u -N -r4016 -r4029 --- trunk/kernel/units/custom_data/custom_data_config.php (.../custom_data_config.php) (revision 4016) +++ trunk/kernel/units/custom_data/custom_data_config.php (.../custom_data_config.php) (revision 4029) @@ -10,6 +10,11 @@ 'ParentPrefix' => 'u', ), + 'c-cdata' => Array( + 'TableName' => TABLE_PREFIX.'CategoryCustomData', + 'ParentPrefix' => 'c', + ), + 'l-cdata' => Array( 'TableName' => TABLE_PREFIX.'LinkCustomData', 'ParentPrefix' => 'l', @@ -31,7 +36,11 @@ ), ), - + 'QueryString' => Array( + 1 => 'id', + 2 => 'event', + ), + 'ItemClass' => Array('class' => 'kDBItem', 'file' => '','build_event' => 'OnItemBuild'), 'ListClass' => Array('class' => 'kDBList', 'file' => '','build_event' => 'OnListBuild'), 'EventHandlerClass' => Array('class' => 'kDBEventHandler', 'file' => '', 'build_event' => 'OnBuild'), Index: trunk/core/units/custom_fields/custom_fields_config.php =================================================================== diff -u -N -r4000 -r4029 --- trunk/core/units/custom_fields/custom_fields_config.php (.../custom_fields_config.php) (revision 4000) +++ trunk/core/units/custom_fields/custom_fields_config.php (.../custom_fields_config.php) (revision 4029) @@ -5,7 +5,7 @@ 'ItemClass' => Array('class'=>'kDBItem','file'=>'','build_event'=>'OnItemBuild'), 'ListClass' => Array('class'=>'kDBList','file'=>'','build_event'=>'OnListBuild'), 'EventHandlerClass' => Array('class'=>'CustomFieldsEventHandler','file'=>'custom_fields_event_handler.php','build_event'=>'OnBuild'), - 'TagProcessorClass' => Array('class'=>'kDBTagProcessor','file'=>'','build_event'=>'OnBuild'), + 'TagProcessorClass' => Array('class'=>'CustomFieldsTagProcessor','file'=>'custom_fields_tag_processor.php','build_event'=>'OnBuild'), 'AutoLoad' => true, 'hooks' => Array(), 'QueryString' => Array( @@ -57,10 +57,15 @@ ), // key - special, value - list select sql 'ListSortings' => Array( - '' => Array( - 'ForcedSorting' => Array('DisplayOrder' => 'asc'), - 'Sorting' => Array('FieldName' => 'asc'), - ) + '' => Array( + 'ForcedSorting' => Array('DisplayOrder' => 'asc'), + 'Sorting' => Array('FieldName' => 'asc'), + ), + + 'general' => Array( + 'Sorting' => Array('DisplayOrder' => 'asc') + ), + ), 'ItemSQLs' => Array( ''=>'SELECT * FROM %s', @@ -79,7 +84,9 @@ 'DisplayOrder' => Array('type' => 'int','not_null' => '1','default' => '0'), 'OnGeneralTab' => Array('type' => 'int','not_null' => '1','default' => '0'), ), - 'VirtualFields' => Array(), + 'VirtualFields' => Array( + 'Value' => Array('type' => 'string', 'default' => ''), + ), 'Grids' => Array( 'Default' => Array( @@ -92,6 +99,15 @@ ), ), + 'SeparateTab' => Array( + 'Icons' => Array('default'=>'icon16_custom.gif'), + 'Fields' => Array( + 'FieldName' => Array( 'title'=>'la_col_FieldName', 'data_block' => 'grid_icon_td'), + 'Prompt' => Array( 'title'=>'la_col_Prompt', 'data_block' => 'grid_data_label_ml_td' ), + 'Value' => Array( 'title'=>'la_col_Value', 'data_block' => 'edit_custom_td'), + ), + ), + ), ); Index: trunk/core/kernel/processors/main_processor.php =================================================================== diff -u -N -r3664 -r4029 --- trunk/core/kernel/processors/main_processor.php (.../main_processor.php) (revision 3664) +++ trunk/core/kernel/processors/main_processor.php (.../main_processor.php) (revision 4029) @@ -179,6 +179,22 @@ } /** + * Gets value of specified field from specified prefix_special and set it as parser param + * + * @param Array $params + */ + /*function SetParam($params) + { + // + list($prefix_special, $field_name) = explode(':', $params['src']); + + $object =& $this->Application->recallObject($prefix_special); + $name = $this->SelectParam($params, 'param,name,var'); + + $this->Application->Parser->SetParam($name, $object->GetField($field_name) ); + }*/ + + /** * Compares block parameter with value specified * * @param Array $params Index: trunk/kernel/units/general/helpers/multilanguage.php =================================================================== diff -u -N -r4017 -r4029 --- trunk/kernel/units/general/helpers/multilanguage.php (.../multilanguage.php) (revision 4017) +++ trunk/kernel/units/general/helpers/multilanguage.php (.../multilanguage.php) (revision 4029) @@ -185,7 +185,12 @@ } } } - $ret .= 'ADD COLUMN '.sprintf($field_mask, $start_index).' AFTER `'.$prev_field.'`, '; + + $field_expression = sprintf($field_mask, $start_index); + $ret .= 'ADD COLUMN '.$field_expression.' AFTER `'.$prev_field.'`, '; + + list($field_name, $field_params) = explode(' ', $field_expression, 2); + $ret .= 'ADD INDEX (`'.$field_name.'` (5) ), '; $start_index++; } return preg_replace('/, $/',';',$ret); Index: trunk/core/kernel/kbase.php =================================================================== diff -u -N -r3840 -r4029 --- trunk/core/kernel/kbase.php (.../kbase.php) (revision 3840) +++ trunk/core/kernel/kbase.php (.../kbase.php) (revision 4029) @@ -149,15 +149,22 @@ * @var Array * @access private */ - var $Fields=Array(); + var $Fields = Array(); /** + * Holds custom field names for item + * + * @var Array + */ + var $customFields = Array(); + + /** * All virtual field names * * @var Array * @access private */ - var $VirtualFields=Array(); + var $VirtualFields = Array(); /** * Fields that need to be queried using custom expression, e.g. IF(...) AS value @@ -245,10 +252,14 @@ $this->SelectClause = $sql; } - function GetSelectSQL($base_query=null) + function GetSelectSQL($base_query = null) { - if( !isset($base_query) ) $base_query = $this->SelectClause; - return $q = str_replace( Array('%1$s','%s'), $this->TableName, $base_query); + if (!isset($base_query)) { + $base_query = $this->SelectClause; + } + $query = str_replace( Array('%1$s','%s'), $this->TableName, $base_query); + $query = $this->replaceModePrefix($query); + return $query; } /** @@ -277,6 +288,19 @@ } /** + * Allows substables to be in same mode as main item (e.g. LEFT JOINED ones) + * + * @param string $query + * @return string + */ + function replaceModePrefix($query) + { + $live_table = substr(kTempTablesHandler::GetLiveName($this->TableName), strlen(TABLE_PREFIX)); + preg_match('/'.preg_quote(TABLE_PREFIX, '/').'(.*)'.preg_quote($live_table, '/').'/', $this->TableName, $rets); + return str_replace('%3$s', $rets[1], $query); + } + + /** * Adds calculated field declaration to object. * * @param string $name @@ -319,6 +343,7 @@ function defineFields() { $this->setConfigFields( $this->Application->getUnitOption($this->Prefix, 'Fields') ); + $this->setCustomFields( $this->Application->getUnitOption($this->Prefix, 'CustomFields', Array()) ); $this->setVirtualFields( $this->Application->getUnitOption($this->Prefix, 'VirtualFields') ); $this->setCalculatedFields( $this->Application->getUnitOption($this->Prefix, 'CalculatedFields') ); } @@ -335,6 +360,18 @@ * @param Array $fields * @access public */ + function setCustomFields($fields) + { + $this->customFields = $fields; + } + + /** + * Set's field names from table + * from config + * + * @param Array $fields + * @access public + */ function setConfigFields($fields) { $this->Fields = $fields;