Index: branches/5.0.x/core/units/categories/categories_event_handler.php =================================================================== diff -u -r12458 -r12466 --- branches/5.0.x/core/units/categories/categories_event_handler.php (.../categories_event_handler.php) (revision 12458) +++ branches/5.0.x/core/units/categories/categories_event_handler.php (.../categories_event_handler.php) (revision 12466) @@ -1,6 +1,6 @@ getSelectedIDs($event, true); + $is_editing = implode('', $ids); + + if ($is_editing) { + $old_statuses = $this->_getCategoryStatus($ids); + } + $object =& $event->getObject(); + /* @var $object kDBItem */ + if ($object->IsRoot()) { $event->setEventParam('master_ids', Array(0)); $this->RemoveRequiredFields($object); @@ -749,9 +758,41 @@ $this->Application->StoreVar('RefreshStructureTree', 1); $event->CallSubEvent('OnResetMenuCache'); + + if ($is_editing) { + // 2. send email event to category owner, when it's status is changed (from admin) + $object->SwitchToLive(); + $new_statuses = $this->_getCategoryStatus($ids); + $process_statuses = Array (STATUS_ACTIVE, STATUS_DISABLED); + + foreach ($new_statuses as $category_id => $new_status) { + if ($new_status != $old_statuses[$category_id] && in_array($new_status, $process_statuses)) { + $object->Load($category_id); + $email_event = $new_status == STATUS_ACTIVE ? 'CATEGORY.APPROVE' : 'CATEGORY.DENY'; + $this->Application->EmailEventUser($email_event, $object->GetDBField('CreatedById')); + } + } + } } /** + * Returns statuses of given categories + * + * @param Array $category_ids + * @return Array + */ + function _getCategoryStatus($category_ids) + { + $id_field = $this->Application->getUnitOption($this->Prefix, 'IDField'); + $table_name = $this->Application->getUnitOption($this->Prefix, 'TableName'); + + $sql = 'SELECT Status, ' . $id_field . ' + FROM ' . $table_name . ' + WHERE ' . $id_field . ' IN (' . implode(',', $category_ids) . ')'; + return $this->Conn->GetCol($sql, $id_field); + } + + /** * Creates a new item in temp table and * stores item id in App vars and Session on succsess *