Index: branches/5.2.x/core/kernel/db/cat_event_handler.php =================================================================== diff -u -N -r13840 -r14092 --- branches/5.2.x/core/kernel/db/cat_event_handler.php (.../cat_event_handler.php) (revision 13840) +++ branches/5.2.x/core/kernel/db/cat_event_handler.php (.../cat_event_handler.php) (revision 14092) @@ -1,6 +1,6 @@ Application->findModule('Name', 'Core', 'RootCat'); + $parent_cat_id = $this->Application->getBaseCategory(); } if ((string)$parent_cat_id != 'any') { @@ -968,10 +968,10 @@ $this->setCustomExportColumns($event); } - if (!$this->Application->isAdminUser) { - $object =& $event->getObject(); - /* @var $object kDBItem */ + $object =& $event->getObject(); + /* @var $object kDBItem */ + if (!$this->Application->isAdminUser) { $image_helper =& $this->Application->recallObject('ImageHelper'); /* @var $image_helper ImageHelper */ @@ -989,6 +989,19 @@ $this->processAdditionalCategories($object, 'update'); } } + + $recycle_bin = $this->Application->ConfigValue('RecycleBinFolder'); + + if ($this->Application->isAdminUser && $recycle_bin) { + $sql = 'SELECT CategoryId + FROM ' . $this->Application->getUnitOption('ci', 'TableName') . ' + WHERE ItemResourceId = ' . $object->GetDBField('ResourceId') . ' AND PrimaryCat = 1'; + $primary_category = $this->Conn->GetOne($sql); + + if ($primary_category == $recycle_bin) { + $event->CallSubEvent('OnAfterItemDelete'); + } + } } /** @@ -2047,7 +2060,7 @@ */ function OnResetSettings(&$event) { - $this->Application->StoreVar('ImportCategory', $this->Application->findModule('Name', 'Core', 'RootCat')); + $this->Application->StoreVar('ImportCategory', $this->Application->getBaseCategory()); } function OnCancelAction(&$event) @@ -2197,29 +2210,54 @@ */ function OnBeforeItemCreate(&$event) { - if ($this->Application->isAdminUser) { - // don't set permission-based status, when creating categories in admin - return true; + $object =& $event->getObject(); + /* @var $object kDBItem */ + + $is_admin = $this->Application->isAdminUser; + $owner_field = $this->getOwnerField($event->Prefix); + + if ((!$object->IsTempTable() && !$is_admin) || ($is_admin && !$object->GetDBField($owner_field))) { + // Front-end OR owner not specified -> set to currently logged-in user + $object->SetDBField($owner_field, $this->Application->RecallVar('user_id')); } + if ( $object->Validate() ) { + $object->SetDBField('ResourceId', $this->Application->NextResourceId()); + } + + if (!$this->Application->isAdmin) { + $this->setItemStatusByPermission($event); + } + } + + /** + * Sets category item status based on user permissions (only on Front-end) + * + * @param kEvent $event + */ + function setItemStatusByPermission(&$event) + { $use_pending_editing = $this->Application->getUnitOption($event->Prefix, 'UsePendingEditing'); - if ($use_pending_editing) { - $object =& $event->getObject(); - /* @var $object kDBItem */ - $perm_helper =& $this->Application->recallObject('PermissionsHelper'); - /* @var $perm_helper kPermissionsHelper */ + if (!$use_pending_editing) { + return ; + } - $primary_category = $object->GetDBField('CategoryId') > 0 ? $object->GetDBField('CategoryId') : $this->Application->GetVar('m_cat_id'); - $item_status = $perm_helper->AddCheckPermission($primary_category, $event->Prefix); - if ($item_status == STATUS_DISABLED) { - $event->status = erFAIL; - return false; - } - else { - $object->SetDBField('Status', $item_status); - } + $object =& $event->getObject(); + /* @var $object kDBItem */ + + $perm_helper =& $this->Application->recallObject('PermissionsHelper'); + /* @var $perm_helper kPermissionsHelper */ + + $primary_category = $object->GetDBField('CategoryId') > 0 ? $object->GetDBField('CategoryId') : $this->Application->GetVar('m_cat_id'); + $item_status = $perm_helper->AddCheckPermission($primary_category, $event->Prefix); + + if ($item_status == STATUS_DISABLED) { + $event->status = erFAIL; } + else { + $object->SetDBField('Status', $item_status); + } } /** @@ -2404,19 +2442,21 @@ // send email events $perm_prefix = $this->Application->getUnitOption($event->Prefix, 'PermItemPrefix'); + $owner_field = $this->getOwnerField($event->Prefix); + $owner_id = $object->GetDBField($owner_field); + switch ($event->Name) { case 'OnCreate': $event_suffix = $is_active ? 'ADD' : 'ADD.PENDING'; - $owner_field = $this->getOwnerField($event->Prefix); - $this->Application->EmailEventAdmin($perm_prefix.'.'.$event_suffix); // there are no ADD.PENDING event for admin :( - $this->Application->EmailEventUser($perm_prefix.'.'.$event_suffix, $object->GetDBField($owner_field)); + $this->Application->EmailEventUser($perm_prefix.'.'.$event_suffix, $owner_id); break; case 'OnUpdate': $event_suffix = $is_active ? 'MODIFY' : 'MODIFY.PENDING'; + $user_id = is_numeric( $object->GetDBField('ModifiedById') ) ? $object->GetDBField('ModifiedById') : $owner_id; $this->Application->EmailEventAdmin($perm_prefix.'.'.$event_suffix); // there are no ADD.PENDING event for admin :( - $this->Application->EmailEventUser($perm_prefix.'.'.$event_suffix, $object->GetDBField('ModifiedById')); + $this->Application->EmailEventUser($perm_prefix.'.'.$event_suffix, $user_id); break; } } @@ -2571,7 +2611,7 @@ // add EditorsPick to ForcedSorting if needed $config_mapping = $this->Application->getUnitOption($event->Prefix, 'ConfigMapping'); if (array_key_exists('ForceEditorPick', $config_mapping) && $this->Application->ConfigValue($config_mapping['ForceEditorPick'])) { - $list_sortings = $this->Application->getUnitOption($event->Prefix, 'ListSortings'); + $list_sortings = $this->Application->getUnitOption($event->Prefix, 'ListSortings', Array ()); $new_forced_sorting = Array ('EditorsPick' => 'DESC');