Index: branches/unlabeled/unlabeled-1.64.2/kernel/units/general/cat_event_handler.php =================================================================== diff -u -r5868 -r5869 --- branches/unlabeled/unlabeled-1.64.2/kernel/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 5868) +++ branches/unlabeled/unlabeled-1.64.2/kernel/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 5869) @@ -13,9 +13,11 @@ { parent::mapPermissions(); $permissions = Array( - 'OnExport' => Array('self' => 'view|advanced:export'), - 'OnExportBegin' => Array('self' => 'view|advanced:export'), - 'OnSaveSettings' => Array('self' => 'add|edit|advanced:import'), + 'OnExport' => Array('self' => 'view|advanced:export'), + 'OnExportBegin' => Array('self' => 'view|advanced:export'), + 'OnSaveSettings' => Array('self' => 'add|edit|advanced:import'), + 'OnBeforeDeleteOriginal' => Array('self' => 'edit|advanced:approve'), + ); $this->permMapping = array_merge($this->permMapping, $permissions); } @@ -337,7 +339,12 @@ } $view_filter = implode(' OR ', $view_filters); $object->addFilter('perm_filter2', $view_filter); + $object->addFilter('status_filter', $object->TableName.'.Status = 1'); + if ($this->Application->getUnitOption($event->Prefix, 'UsePendingEditing')) { + // if category item uses pending editing abilities, then in no cases show pending copies on front + $object->addFilter('original_filter', '%1$s.OrgId = 0 OR %1$s.OrgId IS NULL'); + } } $types = $event->getEventParam('types'); @@ -1799,7 +1806,59 @@ $object->SetDBField('CreatedById', $this->Application->GetVar('u_id')); } } + + /** + * Occures before original item of item in pending editing got deleted (for hooking only) + * + * @param kEvent $event + */ + function OnBeforeDeleteOriginal(&$event) + { + + } + + /** + * Apply same processing to each item beeing selected in grid + * + * @param kEvent $event + * @access private + */ + function iterateItems(&$event) + { + if ($event->Name != 'OnMassApprove' && $event->Name != 'OnMassDecline') { + return parent::iterateItems($event); + } + + if ($this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 1)) { + return; + } + + $object =& $event->getObject( Array('skip_autoload' => true) ); + $ids = $this->StoreSelectedIDs($event); + if ($ids) { + foreach ($ids as $id) { + $object->Load($id); + + switch ($event->Name) { + case 'OnMassApprove': + $ret = $object->ApproveChanges(); + break; + + case 'OnMassDecline': + $ret = $object->DeclineChanges(); + break; + } + + if (!$ret) { + $event->status = erFAIL; + $event->redirect = false; + break; + } + } + } + } + } ?> \ No newline at end of file Index: branches/unlabeled/unlabeled-1.64.2/core/units/general/cat_event_handler.php =================================================================== diff -u -r5868 -r5869 --- branches/unlabeled/unlabeled-1.64.2/core/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 5868) +++ branches/unlabeled/unlabeled-1.64.2/core/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 5869) @@ -13,9 +13,11 @@ { parent::mapPermissions(); $permissions = Array( - 'OnExport' => Array('self' => 'view|advanced:export'), - 'OnExportBegin' => Array('self' => 'view|advanced:export'), - 'OnSaveSettings' => Array('self' => 'add|edit|advanced:import'), + 'OnExport' => Array('self' => 'view|advanced:export'), + 'OnExportBegin' => Array('self' => 'view|advanced:export'), + 'OnSaveSettings' => Array('self' => 'add|edit|advanced:import'), + 'OnBeforeDeleteOriginal' => Array('self' => 'edit|advanced:approve'), + ); $this->permMapping = array_merge($this->permMapping, $permissions); } @@ -337,7 +339,12 @@ } $view_filter = implode(' OR ', $view_filters); $object->addFilter('perm_filter2', $view_filter); + $object->addFilter('status_filter', $object->TableName.'.Status = 1'); + if ($this->Application->getUnitOption($event->Prefix, 'UsePendingEditing')) { + // if category item uses pending editing abilities, then in no cases show pending copies on front + $object->addFilter('original_filter', '%1$s.OrgId = 0 OR %1$s.OrgId IS NULL'); + } } $types = $event->getEventParam('types'); @@ -1799,7 +1806,59 @@ $object->SetDBField('CreatedById', $this->Application->GetVar('u_id')); } } + + /** + * Occures before original item of item in pending editing got deleted (for hooking only) + * + * @param kEvent $event + */ + function OnBeforeDeleteOriginal(&$event) + { + + } + + /** + * Apply same processing to each item beeing selected in grid + * + * @param kEvent $event + * @access private + */ + function iterateItems(&$event) + { + if ($event->Name != 'OnMassApprove' && $event->Name != 'OnMassDecline') { + return parent::iterateItems($event); + } + + if ($this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 1)) { + return; + } + + $object =& $event->getObject( Array('skip_autoload' => true) ); + $ids = $this->StoreSelectedIDs($event); + if ($ids) { + foreach ($ids as $id) { + $object->Load($id); + + switch ($event->Name) { + case 'OnMassApprove': + $ret = $object->ApproveChanges(); + break; + + case 'OnMassDecline': + $ret = $object->DeclineChanges(); + break; + } + + if (!$ret) { + $event->status = erFAIL; + $event->redirect = false; + break; + } + } + } + } + } ?> \ No newline at end of file Index: branches/unlabeled/unlabeled-1.11.2/kernel/units/general/cat_tag_processor.php =================================================================== diff -u -r5858 -r5869 --- branches/unlabeled/unlabeled-1.11.2/kernel/units/general/cat_tag_processor.php (.../cat_tag_processor.php) (revision 5858) +++ branches/unlabeled/unlabeled-1.11.2/kernel/units/general/cat_tag_processor.php (.../cat_tag_processor.php) (revision 5869) @@ -214,7 +214,11 @@ { // original id found & greather then zero + show original $display_original = isset($params['display_original']) && $params['display_original']; - return $display_original && $this->Application->GetVar($this->Prefix.'.original_id'); + + $object =& $this->getObject($params); + $perm_value = $this->PermHelper->ModifyCheckPermission($object->GetDBField('CreatedById'), $object->GetDBField('CategoryId'), $this->Prefix); + + return $display_original && ($perm_value == 1) && $this->Application->GetVar($this->Prefix.'.original_id'); } } Index: branches/unlabeled/unlabeled-1.11.2/core/units/general/cat_tag_processor.php =================================================================== diff -u -r5858 -r5869 --- branches/unlabeled/unlabeled-1.11.2/core/units/general/cat_tag_processor.php (.../cat_tag_processor.php) (revision 5858) +++ branches/unlabeled/unlabeled-1.11.2/core/units/general/cat_tag_processor.php (.../cat_tag_processor.php) (revision 5869) @@ -214,7 +214,11 @@ { // original id found & greather then zero + show original $display_original = isset($params['display_original']) && $params['display_original']; - return $display_original && $this->Application->GetVar($this->Prefix.'.original_id'); + + $object =& $this->getObject($params); + $perm_value = $this->PermHelper->ModifyCheckPermission($object->GetDBField('CreatedById'), $object->GetDBField('CategoryId'), $this->Prefix); + + return $display_original && ($perm_value == 1) && $this->Application->GetVar($this->Prefix.'.original_id'); } } Index: branches/unlabeled/unlabeled-1.73.2/core/kernel/db/db_event_handler.php =================================================================== diff -u -r5858 -r5869 --- branches/unlabeled/unlabeled-1.73.2/core/kernel/db/db_event_handler.php (.../db_event_handler.php) (revision 5858) +++ branches/unlabeled/unlabeled-1.73.2/core/kernel/db/db_event_handler.php (.../db_event_handler.php) (revision 5869) @@ -108,8 +108,8 @@ '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'), + 'OnMassApprove' => Array('self' => 'advanced:approve|add|edit|edit.pending', 'subitem' => 'advanced:approve|add|edit|edit.pending'), + 'OnMassDecline' => Array('self' => 'advanced:decline|add|edit|edit.pending', 'subitem' => 'advanced:decline|add|edit|edit.pending'), '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'), Index: branches/unlabeled/unlabeled-1.32.2/core/units/general/cat_dbitem.php =================================================================== diff -u -r5858 -r5869 --- branches/unlabeled/unlabeled-1.32.2/core/units/general/cat_dbitem.php (.../cat_dbitem.php) (revision 5858) +++ branches/unlabeled/unlabeled-1.32.2/core/units/general/cat_dbitem.php (.../cat_dbitem.php) (revision 5869) @@ -16,12 +16,32 @@ */ var $useFilenames = true; + /** + * Use pending editing abilities during item (delegated by permissions) + * + * @var bool + */ + var $usePendingEditing = false; + function Clear() { parent::Clear(); $this->CategoryPath = Array(); } + /** + * Set's prefix and special + * + * @param string $prefix + * @param string $special + * @access public + */ + function Init($prefix, $special, $event_params = null) + { + parent::Init($prefix, $special, $event_params); + $this->usePendingEditing = $this->Application->getUnitOption($this->Prefix, 'UsePendingEditing'); + } + function Create($force_id=false, $system_create=false) { if (!$this->Validate()) return false; @@ -380,6 +400,59 @@ } return $image_data; } + + function ChangeStatus($new_status) + { + $status_field = array_shift( $this->Application->getUnitOption($this->Prefix,'StatusField') ); + $this->SetDBField($status_field, $new_status); + return $this->Update(); + } + + /** + * Approves changes made to category item + * + * @return bool + */ + function ApproveChanges() + { + $original_id = $this->GetDBField('OrgId'); + + if (!($this->usePendingEditing && $original_id)) { + // non-pending copy of original link + return $this->ChangeStatus(STATUS_ACTIVE); + } + + $this->raiseEvent('OnBeforeDeleteOriginal', null, Array('original_id' => $original_id)); + + // delete original item, because changes made in pending copy (this item) got to be approved in this method + $temp_handler =& $this->Application->recallObject($this->getPrefixSpecial().'_TempHandler', 'kTempTablesHandler'); + $temp_handler->DeleteItems($this->Prefix, $this->Special, Array($original_id)); + + $this->SetDBField('OrgId', 0); + return $this->ChangeStatus(STATUS_ACTIVE); + } + + /** + * Decline changes made to category item + * + * @return bool + */ + function DeclineChanges() + { + $original_id = $this->GetDBField('OrgId'); + + if (!($this->usePendingEditing && $original_id)) { + // non-pending copy of original link + return $this->ChangeStatus(STATUS_DISABLED); + } + + // delete this item, because changes made in pending copy (this item) will be declined in this method + $temp_handler =& $this->Application->recallObject($this->getPrefixSpecial().'_TempHandler', 'kTempTablesHandler'); + $temp_handler->DeleteItems($this->Prefix, $this->Special, Array($this->GetID())); + + // original item is not changed here, because it is already enabled (thrus pending copy is visible to item's owner or admin with permission) + return true; + } } ?> \ No newline at end of file Index: branches/unlabeled/unlabeled-1.32.2/kernel/units/general/cat_dbitem.php =================================================================== diff -u -r5858 -r5869 --- branches/unlabeled/unlabeled-1.32.2/kernel/units/general/cat_dbitem.php (.../cat_dbitem.php) (revision 5858) +++ branches/unlabeled/unlabeled-1.32.2/kernel/units/general/cat_dbitem.php (.../cat_dbitem.php) (revision 5869) @@ -16,12 +16,32 @@ */ var $useFilenames = true; + /** + * Use pending editing abilities during item (delegated by permissions) + * + * @var bool + */ + var $usePendingEditing = false; + function Clear() { parent::Clear(); $this->CategoryPath = Array(); } + /** + * Set's prefix and special + * + * @param string $prefix + * @param string $special + * @access public + */ + function Init($prefix, $special, $event_params = null) + { + parent::Init($prefix, $special, $event_params); + $this->usePendingEditing = $this->Application->getUnitOption($this->Prefix, 'UsePendingEditing'); + } + function Create($force_id=false, $system_create=false) { if (!$this->Validate()) return false; @@ -380,6 +400,59 @@ } return $image_data; } + + function ChangeStatus($new_status) + { + $status_field = array_shift( $this->Application->getUnitOption($this->Prefix,'StatusField') ); + $this->SetDBField($status_field, $new_status); + return $this->Update(); + } + + /** + * Approves changes made to category item + * + * @return bool + */ + function ApproveChanges() + { + $original_id = $this->GetDBField('OrgId'); + + if (!($this->usePendingEditing && $original_id)) { + // non-pending copy of original link + return $this->ChangeStatus(STATUS_ACTIVE); + } + + $this->raiseEvent('OnBeforeDeleteOriginal', null, Array('original_id' => $original_id)); + + // delete original item, because changes made in pending copy (this item) got to be approved in this method + $temp_handler =& $this->Application->recallObject($this->getPrefixSpecial().'_TempHandler', 'kTempTablesHandler'); + $temp_handler->DeleteItems($this->Prefix, $this->Special, Array($original_id)); + + $this->SetDBField('OrgId', 0); + return $this->ChangeStatus(STATUS_ACTIVE); + } + + /** + * Decline changes made to category item + * + * @return bool + */ + function DeclineChanges() + { + $original_id = $this->GetDBField('OrgId'); + + if (!($this->usePendingEditing && $original_id)) { + // non-pending copy of original link + return $this->ChangeStatus(STATUS_DISABLED); + } + + // delete this item, because changes made in pending copy (this item) will be declined in this method + $temp_handler =& $this->Application->recallObject($this->getPrefixSpecial().'_TempHandler', 'kTempTablesHandler'); + $temp_handler->DeleteItems($this->Prefix, $this->Special, Array($this->GetID())); + + // original item is not changed here, because it is already enabled (thrus pending copy is visible to item's owner or admin with permission) + return true; + } } ?> \ No newline at end of file Index: branches/unlabeled/unlabeled-1.26.2/core/kernel/db/dbitem.php =================================================================== diff -u -r5858 -r5869 --- branches/unlabeled/unlabeled-1.26.2/core/kernel/db/dbitem.php (.../dbitem.php) (revision 5858) +++ branches/unlabeled/unlabeled-1.26.2/core/kernel/db/dbitem.php (.../dbitem.php) (revision 5869) @@ -776,11 +776,18 @@ $this->SetDBField($title_field, $new_name); } - function raiseEvent($name, $id=null) + function raiseEvent($name, $id = null, $additional_params = Array()) { if( !isset($id) ) $id = $this->GetID(); $event = new kEvent( Array('name'=>$name,'prefix'=>$this->Prefix,'special'=>$this->Special) ); $event->setEventParam('id', $id); + + if ($additional_params) { + foreach ($additional_params as $ap_name => $ap_value) { + $event->setEventParam($ap_name, $ap_value); + } + } + $this->Application->HandleEvent($event); return $event->status == erSUCCESS ? true : false; }