Index: trunk/core/kernel/db/db_event_handler.php
===================================================================
diff -u -N -r5431 -r6093
--- trunk/core/kernel/db/db_event_handler.php (.../db_event_handler.php) (revision 5431)
+++ trunk/core/kernel/db/db_event_handler.php (.../db_event_handler.php) (revision 6093)
@@ -65,7 +65,6 @@
}
}
-
$section = $event->getSection();
if (!preg_match('/^CATEGORY:(.*)/', $section)) {
// only if not category item events
@@ -106,34 +105,35 @@
'OnMassClone' => Array('self' => 'add', 'subitem' => 'add|edit'),
'OnSelectItems' => Array('self' => 'add|edit', 'subitem' => 'add|edit'),
+ 'OnProcessSelected' => Array('self' => 'add|edit', 'subitem' => 'add|edit'),
'OnSelectUser' => Array('self' => 'add|edit', 'subitem' => 'add|edit'),
- 'OnMassApprove' => Array('self' => 'advanced:approve|add|edit', 'subitem' => 'advanced:approve|add|edit'),
- 'OnMassDecline' => Array('self' => 'advanced:decline|add|edit', 'subitem' => 'advanced:decline|add|edit'),
- 'OnMassMoveUp' => Array('self' => 'advanced:move_up|add|edit', 'subitem' => 'advanced:move_up|add|edit'),
- 'OnMassMoveDown' => Array('self' => 'advanced:move_down|add|edit', 'subitem' => 'advanced:move_down|add|edit'),
+ 'OnMassApprove' => Array('self' => 'advanced:approve|edit', 'subitem' => 'advanced:approve|add|edit'),
+ 'OnMassDecline' => Array('self' => 'advanced:decline|edit', 'subitem' => 'advanced:decline|add|edit'),
+ 'OnMassMoveUp' => Array('self' => 'advanced:move_up|edit', 'subitem' => 'advanced:move_up|add|edit'),
+ 'OnMassMoveDown' => Array('self' => 'advanced:move_down|edit', 'subitem' => 'advanced:move_down|add|edit'),
- 'OnPreCreate' => Array('self' => 'add'),
- 'OnEdit' => Array('self' => 'edit'),
+ 'OnPreCreate' => Array('self' => 'add|add.pending'),
+ 'OnEdit' => Array('self' => 'edit|edit.pending'),
// theese event do not harm, but just in case check them too :)
- 'OnCancelEdit' => Array('self' => 'add|edit'),
- 'OnCancel' => Array('self' => 'add|edit', 'subitem' => 'add|edit'),
+ 'OnCancelEdit' => Array('self' => true, 'subitem' => true),
+ 'OnCancel' => Array('self' => true, 'subitem' => true),
- 'OnSetSorting' => Array('self' => 'view', 'subitem' => 'view'),
- 'OnSetSortingDirect' => Array('self' => 'view', 'subitem' => 'view'),
+ 'OnSetSorting' => Array('self' => true, 'subitem' => true),
+ 'OnSetSortingDirect' => Array('self' => true, 'subitem' => true),
- 'OnSetFilter' => Array('self' => 'view', 'subitem' => 'view'),
- 'OnApplyFilters' => Array('self' => 'view', 'subitem' => 'view'),
- 'OnRemoveFilters' => Array('self' => 'view', 'subitem' => 'view'),
+ 'OnSetFilter' => Array('self' => true, 'subitem' => true),
+ 'OnApplyFilters' => Array('self' => true, 'subitem' => true),
+ 'OnRemoveFilters' => Array('self' => true, 'subitem' => true),
- 'OnSetPerPage' => Array('self' => 'view', 'subitem' => 'view'),
+ 'OnSetPerPage' => Array('self' => true, 'subitem' => true),
- 'OnSearch' => Array('self' => 'view', 'subitem' => 'view'),
- 'OnSearchReset' => Array('self' => 'view', 'subitem' => 'view'),
+ 'OnSearch' => Array('self' => true, 'subitem' => true),
+ 'OnSearchReset' => Array('self' => true, 'subitem' => true),
'OnGoBack' => Array('self' => true, 'subitem' => true),
);
@@ -228,6 +228,9 @@
// this smells... needs to be refactored
$first_id = getArrayValue($ret,0);
if (($first_id === false) && ($event->getEventParam('raise_warnings') == 1)) {
+ if ($this->Application->isDebugMode()) {
+ $this->Application->Debugger->appendTrace();
+ }
trigger_error('Requested ID for prefix '.$event->getPrefixSpecial().' not passed',E_USER_NOTICE);
}
$this->Application->SetVar($event->getPrefixSpecial(true).'_id', $first_id);
@@ -290,12 +293,13 @@
* @param kEvent $event
* @access private
*/
- function dbBuild(&$object,&$event)
+ function dbBuild(&$object, &$event)
{
$object->Configure();
$this->PrepareObject($object, $event);
- $live_table = $event->getEventParam('live_table');
+ // force live table if specified or is original item
+ $live_table = $event->getEventParam('live_table') || $event->Special == 'original';
if( $this->UseTempTables($event) && !$live_table )
{
@@ -375,6 +379,11 @@
return $this->UseTempTables($event) ? $this->Application->GetTempTablePrefix().TABLE_PREFIX : TABLE_PREFIX;
}
+ /**
+ * Load item if id is available
+ *
+ * @param kEvent $event
+ */
function LoadItem(&$event)
{
$object =& $event->getObject();
@@ -383,6 +392,11 @@
{
$actions =& $this->Application->recallObject('kActions');
$actions->Set($event->Prefix_Special.'_id', $object->GetID() );
+
+ $use_pending_editing = $this->Application->getUnitOption($event->Prefix, 'UsePendingEditing');
+ if ($use_pending_editing && $event->Special != 'original') {
+ $this->Application->SetVar($event->Prefix.'.original_id', $object->GetDBField('OrgId'));
+ }
}
else
{
@@ -413,7 +427,7 @@
$this->SetPagination($event);
$this->SetSorting($event);
- $object->CalculateTotals();
+// $object->CalculateTotals(); // Now called in getTotals to avoid extra query
$actions =& $this->Application->recallObject('kActions');
$actions->Set('remove_specials['.$event->Prefix_Special.']', '0');
@@ -884,7 +898,7 @@
$table_info = $object->getLinkedInfo();
$object->SetDBField($table_info['ForeignKey'], $table_info['ParentId']);
-
+
$event->redirect = false;
}
@@ -979,7 +993,12 @@
$temp =& $this->Application->recallObject($event->getPrefixSpecial().'_TempHandler', 'kTempTablesHandler');
if (!$this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 1)) {
- $temp->SaveEdit($skip_master);
+ $live_ids = $temp->SaveEdit($event->getEventParam('master_ids') ? $event->getEventParam('master_ids') : Array());
+ if ($live_ids) {
+ // ensure, that newly created item ids are avalable as if they were selected from grid
+ // NOTE: only works if main item has subitems !!!
+ $this->Application->StoreVar($event->getPrefixSpecial().'_selected_ids', implode(',', $live_ids));
+ }
}
$this->clearSelectedIDs($event);
@@ -1016,6 +1035,7 @@
*/
function isNewItemCreate(&$event)
{
+ $event->setEventParam('raise_warnings', 0);
$item_id = $this->getPassedID($event);
return ($item_id == '') ? true : false;
}
@@ -1041,7 +1061,7 @@
}
return;
}
-
+
$object =& $event->getObject( Array('skip_autoload' => true) );
$items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) );
@@ -1398,7 +1418,7 @@
$pass_events = $event->getEventParam('pass_events');
$redirect_params = array_merge_recursive2($event->redirect_params, Array('m_opener' => 'u', '__URLENCODE__' => 1));
- $new_level = 'index4.php|'.ltrim($this->Application->BuildEnv($t, $redirect_params, 'all', $pass_events), ENV_VAR_NAME.'=');
+ $new_level = 'index.php|'.ltrim($this->Application->BuildEnv($t, $redirect_params, 'all', $pass_events), ENV_VAR_NAME.'=');
array_push($opener_stack, $new_level);
$this->Application->StoreVar('opener_stack', serialize($opener_stack));
}
@@ -1736,6 +1756,7 @@
$fields = $this->Application->getUnitOption($event->Prefix, 'Fields', Array());
$field_options = Array('type' => 'string', 'formatter' => 'kMultiLanguage', 'not_null' => 1, 'db_type' => 'text', 'default' => '');
foreach ($custom_fields as $custom_id => $custom_params) {
+ if (isset($fields['cust_'.$custom_id])) continue;
$fields['cust_'.$custom_id] = $field_options;
}
$this->Application->setUnitOption($event->Prefix, 'Fields', $fields);
@@ -1747,15 +1768,27 @@
$cf_helper =& $this->Application->recallObject('InpCustomFieldsHelper');
$field_options = Array('type' => 'string', 'not_null' => 1, 'default' => '');
$ml_formatter =& $this->Application->recallObject('kMultiLanguage');
- $option_types = Array('select', 'radio');
+
foreach ($custom_fields as $custom_id => $custom_params) {
- if (in_array($custom_params['ElementType'], $option_types) && $custom_params['ValueList']) {
- $field_options['options'] = $cf_helper->GetValuesHash($custom_params['ValueList']);
- $field_options['formatter'] = 'kOptionsFormatter';
+ switch ($custom_params['ElementType']) {
+ case 'date':
+ case 'datetime':
+ unset($field_options['options']);
+ $field_options['formatter'] = 'kDateFormatter';
+ break;
+
+ case 'select':
+ case 'radio':
+ if ($custom_params['ValueList']) {
+ $field_options['options'] = $cf_helper->GetValuesHash($custom_params['ValueList']);
+ $field_options['formatter'] = 'kOptionsFormatter';
+ }
+ break;
+
+ default:
+ unset($field_options['options'], $field_options['formatter']);
+ break;
}
- else {
- unset($field_options['options'], $field_options['formatter']);
- }
$custom_name = $custom_params['FieldName'];
$calculated_fields['cust_'.$custom_name] = 'cust.'.$ml_formatter->LangFieldName('cust_'.$custom_id);