Index: branches/5.0.x/core/kernel/db/cat_dbitem.php =================================================================== diff -u -r12343 -r12466 --- branches/5.0.x/core/kernel/db/cat_dbitem.php (.../cat_dbitem.php) (revision 12343) +++ branches/5.0.x/core/kernel/db/cat_dbitem.php (.../cat_dbitem.php) (revision 12466) @@ -1,6 +1,6 @@ Application->getUnitOption($this->Prefix,'StatusField') ); if ($new_status != $this->GetDBField($status_field)) { // status was changed - $this->sendEmailEvents($new_status); + $this->sendEmailEvents($new_status, $pending_editing); } $this->SetDBField($status_field, $new_status); return $this->Update(); } - function sendEmailEvents($new_status) + function sendEmailEvents($new_status, $pending_editing = false) { - $perm_prefix = $this->Application->getUnitOption($this->Prefix, 'PermItemPrefix'); $owner_field = $this->Application->getUnitOption($this->Prefix, 'OwnerField'); if (!$owner_field) { $owner_field = 'CreatedById'; } - $event_name = $perm_prefix.'.'.($new_status == STATUS_ACTIVE ? 'APPROVE' : 'DENY'); + $event_name = $this->Application->getUnitOption($this->Prefix, 'PermItemPrefix'); + if ($pending_editing) { + $event_name .= '.MODIFY'; + } + + $event_name .= $new_status == STATUS_ACTIVE ? '.APPROVE' : '.DENY'; $this->Application->EmailEventUser($event_name, $this->GetDBField($owner_field)); } @@ -508,7 +512,7 @@ $temp_handler->DeleteItems($this->Prefix, $this->Special, Array($original_id)); $this->SetDBField('OrgId', 0); - return $this->ChangeStatus(STATUS_ACTIVE); + return $this->ChangeStatus(STATUS_ACTIVE, true); } return false; @@ -532,6 +536,7 @@ $temp_handler =& $this->Application->recallObject($this->getPrefixSpecial().'_TempHandler', 'kTempTablesHandler'); $temp_handler->DeleteItems($this->Prefix, $this->Special, Array($this->GetID())); + $this->sendEmailEvents(STATUS_DISABLED, true); // 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; } Index: branches/5.0.x/core/install/upgrades.php =================================================================== diff -u -r12430 -r12466 --- branches/5.0.x/core/install/upgrades.php (.../upgrades.php) (revision 12430) +++ branches/5.0.x/core/install/upgrades.php (.../upgrades.php) (revision 12466) @@ -1,6 +1,6 @@ Conn->GetCol($sql); if ($event_ids) { - $sql = 'DELETE FROM ' . TABLE_PREFIX . 'EmailMessage - WHERE EventId IN (' . implode(',', $event_ids) . ')'; - $this->Conn->Query($sql); + $this->_deleteEvents($event_ids); - $sql = 'DELETE FROM ' . TABLE_PREFIX . 'Events - WHERE EventId IN (' . implode(',', $event_ids) . ')'; - $this->Conn->Query($sql); - $sql = 'DELETE FROM ' . TABLE_PREFIX . 'Phrase - WHERE Phrase IN ("la_event_category.modify", "la_event_category.delete")'; + WHERE Phrase IN ("la_event_category.modify", "la_event_category.delete")'; $this->Conn->Query($sql); } + + // partially delete events + $sql = 'SELECT EventId + FROM ' . TABLE_PREFIX . 'Events + WHERE (Event IN ("CATEGORY.APPROVE", "CATEGORY.DENY")) AND (Type = ' . EVENT_TYPE_ADMIN . ')'; + $event_ids = $this->Conn->GetCol($sql); + + if ($event_ids) { + $this->_deleteEvents($event_ids); + } } } + function _deleteEvents($ids) + { + $sql = 'DELETE FROM ' . TABLE_PREFIX . 'EmailMessage + WHERE EventId IN (' . implode(',', $ids) . ')'; + $this->Conn->Query($sql); + + $sql = 'DELETE FROM ' . TABLE_PREFIX . 'Events + WHERE EventId IN (' . implode(',', $ids) . ')'; + $this->Conn->Query($sql); + } } \ No newline at end of file Index: branches/5.0.x/core/units/email_events/email_events_event_handler.php =================================================================== diff -u -r12352 -r12466 --- branches/5.0.x/core/units/email_events/email_events_event_handler.php (.../email_events_event_handler.php) (revision 12352) +++ branches/5.0.x/core/units/email_events/email_events_event_handler.php (.../email_events_event_handler.php) (revision 12466) @@ -1,6 +1,6 @@ SetSubject($message_subject); + if ($this->Application->isDebugMode()) { + // set special header with event name, so it will be easier to determite what's actually was received + $message_headers['X-Event-Name'] = $email_event_name . ' - ' . ($event->getEventParam('EmailEventType') == 1 ? 'ADMIN' : 'USER'); + } + foreach ($message_headers as $header_name => $header_value) { $esender->SetEncodedHeader($header_name, $header_value); } 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 * Index: branches/5.0.x/core/units/users/users_event_handler.php =================================================================== diff -u -r12365 -r12466 --- branches/5.0.x/core/units/users/users_event_handler.php (.../users_event_handler.php) (revision 12365) +++ branches/5.0.x/core/units/users/users_event_handler.php (.../users_event_handler.php) (revision 12466) @@ -1,6 +1,6 @@ Application->RecallVar('user_id'); $email_event =& $this->Application->EmailEventUser('USER.SUGGEST', $user_id, $send_params); + $email_event =& $this->Application->EmailEventAdmin('USER.SUGGEST'); if ($email_event->status == erSUCCESS){ /*$fields_hash = Array ( Index: branches/5.0.x/core/units/reviews/reviews_event_handler.php =================================================================== diff -u -r12299 -r12466 --- branches/5.0.x/core/units/reviews/reviews_event_handler.php (.../reviews_event_handler.php) (revision 12299) +++ branches/5.0.x/core/units/reviews/reviews_event_handler.php (.../reviews_event_handler.php) (revision 12466) @@ -1,6 +1,6 @@ Application->GetTopmostPrefix($event->Prefix, true); // this will return LINK for l, ARTICLE for n, TOPIC for bb, PRODUCT for p - $item_prefix = $this->Application->getUnitOption($main_prefix, 'PermItemPrefix'); - return $item_prefix; + return $this->Application->getUnitOption($main_prefix, 'PermItemPrefix'); } /** @@ -328,21 +327,67 @@ $spam_helper->InitHelper($parent_info['ParentId'], 'Review', $review_settings); $spam_helper->AddToSpamControl(); + + $review_status = $object->GetDBField('Status'); + + if ($review_status == STATUS_ACTIVE || $review_status == STATUS_PENDING) { + $email_event = $this->getPermPrefix($event) . '.REVIEW.' . ($review_status == STATUS_ACTIVE ? 'ADD' : 'ADD.PENDING'); + $this->Application->EmailEventUser($email_event, $object->GetDBField('CreatedById')); + $this->Application->EmailEventAdmin($email_event); + } } } - /** * Updates item review counter * * @param kEvent $event */ function OnAfterItemUpdate(&$event) { + parent::OnAfterItemUpdate($event); + $this->updateSubitemCounters($event); + + $object =& $event->getObject(); + /* @var $object kDBItem */ + + if ($this->Application->IsAdmin() && !$object->IsTempTable()) { + // send email on review status change from reviews grid in admin + $review_status = $object->GetDBField('Status'); + $process_status = Array (STATUS_ACTIVE, STATUS_DISABLED); + + if (($review_status != $object->GetOriginalField('Status')) && in_array($review_status, $process_status)) { + $this->_loadMainObject($event); + + $email_event = $this->getPermPrefix($event) . '.REVIEW.' . ($review_status == STATUS_ACTIVE ? 'APPROVE' : 'DENY'); + $this->Application->EmailEventUser($email_event, $object->GetDBField('CreatedById')); + } + } } /** + * Loads main object of review (link, article, etc.) + * + * @param kEvent $event + * @return kCatDBItem + */ + function _loadMainObject(&$event) + { + $object =& $event->getObject(); + /* @var $object kDBItem */ + + $parent_prefix = $this->Application->getUnitOption($event->Prefix, 'ParentPrefix'); + $parent_table_key = $this->Application->getUnitOption($event->Prefix, 'ParentTableKey'); + $foreign_key = $this->Application->getUnitOption($event->Prefix, 'ForeignKey'); + + $main_object =& $this->Application->recallObject($parent_prefix, null, Array ('skip_autoload' => true)); + /* @var $main_object kDBItem */ + + $main_object->Load($object->GetDBField($foreign_key), $parent_table_key); + } + + /** * Updates total review counter, cached rating, votes count * * @param kEvent $event Index: branches/5.0.x/core/install/english.lang =================================================================== diff -u -r12422 -r12466 --- branches/5.0.x/core/install/english.lang (.../english.lang) (revision 12422) +++ branches/5.0.x/core/install/english.lang (.../english.lang) (revision 12466) @@ -2029,9 +2029,7 @@ U3ViamVjdDogU3VnZ2VzdGVkIENhdGVnb3J5ICI8aW5wMjpjX0ZpZWxkIG5hbWU9Ik5hbWUiLz4iIGlzIFBlbmRpbmcKClRoZSBjYXRlZ29yeSB5b3Ugc3VnZ2VzdGVkICI8aW5wMjpjX0ZpZWxkIG5hbWU9Ik5hbWUiLz4iIGlzIHBlbmRpbmcgZm9yIGFkbWluaXN0cmF0aXZlIGFwcHJvdmFsLg0KDQpUaGFuayB5b3Uh U3ViamVjdDogU3VnZ2VzdGVkIENhdGVnb3J5ICI8aW5wMjpjX0ZpZWxkIG5hbWU9Ik5hbWUiLz4iIGlzIFBlbmRpbmcKCkEgY2F0ZWdvcnkgIjxpbnAyOmNfRmllbGQgbmFtZT0iTmFtZSIvPiIgaGFzIGJlZW4gYWRkZWQsIHBlbmRpbmcgeW91ciBjb25maXJtYXRpb24uICBQbGVhc2UgcmV2aWV3IHRoZSBjYXRlZ29yeSBhbmQgYXBwcm92ZSBvciBkZW55IGl0Lg== U3ViamVjdDogQSBjYXRlZ29ye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c2lvbiE8L3A+ Index: branches/5.0.x/core/kernel/languages/phrases_cache.php =================================================================== diff -u -r12450 -r12466 --- branches/5.0.x/core/kernel/languages/phrases_cache.php (.../phrases_cache.php) (revision 12450) +++ branches/5.0.x/core/kernel/languages/phrases_cache.php (.../phrases_cache.php) (revision 12466) @@ -1,6 +1,6 @@ LanguageId . ') AND (UPPER(Phrase) = ' . $this->Conn->qstr($label) . ')'; + WHERE (LanguageId = ' . $this->LanguageId . ') AND (Phrase = ' . $this->Conn->qstr($label) . ')'; // UPPER(Phrase) $res = $this->Conn->GetRow($sql); if ($res === false || count($res) == 0) { Index: branches/5.0.x/core/install/install_data.sql =================================================================== diff -u -r12445 -r12466 --- branches/5.0.x/core/install/install_data.sql (.../install_data.sql) (revision 12445) +++ branches/5.0.x/core/install/install_data.sql (.../install_data.sql) (revision 12466) @@ -248,9 +248,7 @@ INSERT INTO Events VALUES(DEFAULT, 'CATEGORY.ADD.PENDING', NULL, 1, 1, NULL, 'Core:Category', 'la_event_category.add.pending', 1); INSERT INTO Events VALUES(DEFAULT, 'CATEGORY.ADD', NULL, 1, 1, NULL, 'Core:Category', 'la_event_category.add', 1); INSERT INTO Events VALUES(DEFAULT, 'CATEGORY.APPROVE', NULL, 1, 0, NULL, 'Core:Category', 'la_event_category.approve', 0); -INSERT INTO Events VALUES(DEFAULT, 'CATEGORY.APPROVE', NULL, 1, 1, NULL, 'Core:Category', 'la_event_category.approve', 1); INSERT INTO Events VALUES(DEFAULT, 'CATEGORY.DENY', NULL, 1, 0, NULL, 'Core:Category', 'la_event_category.deny', 0); -INSERT INTO Events VALUES(DEFAULT, 'CATEGORY.DENY', NULL, 1, 1, NULL, 'Core:Category', 'la_event_category.deny', 1); INSERT INTO Events VALUES(DEFAULT, 'USER.SUBSCRIBE', NULL, 1, 0, NULL, 'Core:Users', 'la_event_user.subscribe', 0); INSERT INTO Events VALUES(DEFAULT, 'USER.SUBSCRIBE', NULL, 1, 1, NULL, 'Core:Users', 'la_event_user.subscribe', 1); INSERT INTO Events VALUES(DEFAULT, 'USER.UNSUBSCRIBE', NULL, 1, 0, NULL, 'Core:Users', 'la_event_user.unsubscribe', 0);