Index: admin/system_presets/simple/system_event_subscriptions_system-event-subscription.php =================================================================== --- admin/system_presets/simple/system_event_subscriptions_system-event-subscription.php (revision 0) +++ admin/system_presets/simple/system_event_subscriptions_system-event-subscription.php (revision 0) @@ -0,0 +1,52 @@ + Array ('new_item', 'edit', 'delete', 'view', 'dbl-click'), + +// General" tab during adding/editing +// 'system_event_subscription_edit' => Array ('select', 'cancel', 'reset_edit', 'prev', 'next'), + ); + + // fields to hide + $hidden_fields = Array ( + /*'SubscriptionId', 'EmailEventId', 'SubscriberEmail', 'UserId', 'CategoryId', + 'ItemId', 'ParentItemId', 'SubscribedOn',*/ + ); + + // virtual fields to hide + $virtual_hidden_fields = Array ( + /*'Username', 'EmailEventName', 'CategoryName',*/ + ); + + // fields to make required + $required_fields = Array ( + /*'SubscriptionId',*/ 'EmailEventId', /*'SubscriberEmail', 'UserId', 'CategoryId', + 'ItemId', 'ParentItemId',*/ 'SubscribedOn', + ); + + // virtual fields to make required + $virtual_required_fields = Array ( + /*'Username', 'EmailEventName', 'CategoryName',*/ + ); + + // hide columns in grids + $hide_columns = Array ( + /*'Default' => Array ( + 'SubscriptionId', 'EmailEventId', 'EmailEventName', 'SubscriberEmail', 'UserId', 'Username', 'CategoryId', + 'CategoryName', 'ItemId', 'ItemName', 'ParentItemId', 'ParentItemName', 'SubscribedOn', + ),*/ + ); \ No newline at end of file Property changes on: admin\system_presets\simple\system_event_subscriptions_system-event-subscription.php ___________________________________________________________________ Added: svn:keywords + Id Added: svn:eol-style + LF Property changes on: core\admin_templates\system_event_subscriptions ___________________________________________________________________ Added: tsvn:autoprops + *.php = svn:eol-style=LF;svn:keywords=Id *.tpl = svn:eol-style=LF *.sql = svn:eol-style=LF *.lang = svn:eol-style=LF *.sh = svn:eol-style=LF;svn:executable *.txt = svn:eol-style=LF *.html = svn:eol-style=LF *.htm = svn:eol-style=LF *.css = svn:eol-style=LF *.js = svn:eol-style=LF *.xml = svn:eol-style=LF .htaccess = svn:eol-style=LF .smsignore = svn:eol-style=LF COPYRIGHT = svn:eol-style=LF CREDITS = svn:eol-style=LF INSTALL = svn:eol-style=LF LICENSE = svn:eol-style=LF LICENSES = svn:eol-style=LF README = svn:eol-style=LF Added: bugtraq:url + http://tracker.in-portal.org/view.php?id=%BUGID% Added: bugtraq:number + true Added: bugtraq:logregex + (?:[Bb]ugs?|[Ii]ssues?|[Rr]eports?|[Ff]ixe?s?|[Rr]esolves?)+\s+(?:#?(?:\d+)[,\.\s]*)+ (\d+) Index: core/admin_templates/system_event_subscriptions/system_event_subscription_edit.tpl =================================================================== --- core/admin_templates/system_event_subscriptions/system_event_subscription_edit.tpl (revision 0) +++ core/admin_templates/system_event_subscriptions/system_event_subscription_edit.tpl (revision 0) @@ -0,0 +1,76 @@ + + + + + + + + + + + + +
+ +
+ + + + +
+ + + + + + + + + + + +
+
+ + \ No newline at end of file Property changes on: core\admin_templates\system_event_subscriptions\system_event_subscription_edit.tpl ___________________________________________________________________ Added: svn:eol-style + LF Index: core/admin_templates/system_event_subscriptions/system_event_subscription_list.tpl =================================================================== --- core/admin_templates/system_event_subscriptions/system_event_subscription_list.tpl (revision 0) +++ core/admin_templates/system_event_subscriptions/system_event_subscription_list.tpl (revision 0) @@ -0,0 +1,63 @@ + + + + + + + + + + + +
+ +
+ + + + + + + + + + + + + + + + + + + \ No newline at end of file Property changes on: core\admin_templates\system_event_subscriptions\system_event_subscription_list.tpl ___________________________________________________________________ Added: svn:eol-style + LF Index: core/install/english.lang =================================================================== --- core/install/english.lang (revision 15257) +++ core/install/english.lang (working copy) @@ -336,7 +336,7 @@ QmFja2dyb3VuZCBQb3NpdGlvbg== QmFja2dyb3VuZCBSZXBlYXQ= QmNj - QmluZCB0byBTeXN0ZW0gRXZlbnQ= + QmluZCB0byBTeXN0ZW0gRXZlbnQ= RWxlbWVudCBQb3NpdGlvbg== Qm9yZGVyIEJvdHRvbQ== Qm9yZGVyIExlZnQ= @@ -348,7 +348,7 @@ Qm91bmNlIEluZm8= U2VjdGlvbg== U2VjdGlvbiBGb3JtYXQ= - U2VjdGlvbiBJRA== + U2VjdGlvbiBJRA== U2VjdGlvbiBzZXBhcmF0b3I= U2VjdGlvbiBUZW1wbGF0ZQ== Q2M= @@ -390,6 +390,7 @@ RWxhcHNlZCBUaW1l RS1tYWls RS1tYWlsIENvbW11bmljYXRpb24gUm9sZQ== + RS1tYWlsIEV2ZW50 RS1tYWlsIG9yIFVzZXJuYW1l RS1tYWlsICI8c3Ryb25nPntwYXNzd29yZH08L3N0cm9uZz4iIHBhc3N3b3JkIHRvIHVzZXI= RW1haWxzIGluIFF1ZXVl @@ -552,6 +553,8 @@ Q2FjaGUgRXhwaXJhdGlvbiBpbiBzZWNvbmRz VGl0bGUgKE1lbnUgSXRlbSk= U2VjdGlvbiBUaXRsZQ== + UGFyZW50IEl0ZW0gSUQ= + UGFyZW50IEl0ZW0gTmFtZQ== UGFyZW50IFNlY3Rpb24= UGFzc3dvcmQ= UGVyY2VudHMgQ29tcGxldGVk @@ -630,9 +633,11 @@ U3ViamVjdA== U3VibWl0dGVkIE9u U3VibWlzc2lvbiBOb3RpZmljYXRpb24gRW1haWw= + U3Vic2NyaWJlZCBPbg== U3VnZ2VzdGVkIENvcnJlY3Rpb24= UG9pbnRzIHRvIFNlY3Rpb24= U3luY2hyb25pemUgTGFuZ3VhZ2U= + U3lzdGVtIEV2ZW50 VGFibGUgTmFtZSBpbiBEYXRhYmFzZSA= VGFn SXRlbQ== @@ -1260,6 +1265,7 @@ QWRkaW5nIFNraW4= QWRkaW5nIFNwZWxsaW5nIERpY3Rpb25hcnk= QWRkaW5nIFN0b3AgV29yZA== + QWRkaW5nIFN5c3RlbSBFdmVudCBTdWJzY3JpcHRpb24= QWRkaW5nIFRoZW1lIFRlbXBsYXRl QWRkaW5nIFRoZXNhdXJ1cw== QWRkaW5nIEJhc2UgU3R5bGU= @@ -1315,6 +1321,7 @@ RWRpdGluZyBTcGVsbGluZyBEaWN0aW9uYXJ5 RWRpdGluZyBTdG9wIFdvcmQ= RWRpdGluZyBTdHlsZQ== + RWRpdGluZyBTeXN0ZW0gRXZlbnQgU3Vic2NyaXB0aW9u RWRpdGluZyBUaGVtZSBGaWxl RWRpdGluZyBUaGVzYXVydXM= RWRpdGluZyBUcmFuc2xhdGlvbg== @@ -1395,6 +1402,7 @@ U3BlbGxpbmcgRGljdGlvbmFyeQ== U3RvcCBXb3Jkcw== U3RydWN0dXJlICYgRGF0YQ== + VXNlciBTdWJzY3JpcHRpb25z U3lzdGVtIFRvb2xz Q2xlYXIgVGVtcGxhdGVzIENhY2hl Q29tbW9ubHkgVXNlZCBLZXlz Index: core/install/install_data.sql =================================================================== --- core/install/install_data.sql (revision 15235) +++ core/install/install_data.sql (working copy) @@ -702,6 +702,11 @@ INSERT INTO Permissions VALUES (DEFAULT, 'in-portal:mailing_lists.edit', 11, 1, 1, 0); INSERT INTO Permissions VALUES (DEFAULT, 'in-portal:mailing_lists.delete', 11, 1, 1, 0); +INSERT INTO Permissions VALUES (DEFAULT, 'in-portal:system_event_subscriptions.view', 11, 1, 1, 0); +INSERT INTO Permissions VALUES (DEFAULT, 'in-portal:system_event_subscriptions.add', 11, 1, 1, 0); +INSERT INTO Permissions VALUES (DEFAULT, 'in-portal:system_event_subscriptions.edit', 11, 1, 1, 0); +INSERT INTO Permissions VALUES (DEFAULT, 'in-portal:system_event_subscriptions.delete', 11, 1, 1, 0); + INSERT INTO Permissions VALUES (DEFAULT, 'in-portal:email_queue.view', 11, 1, 1, 0); INSERT INTO Permissions VALUES (DEFAULT, 'in-portal:email_queue.delete', 11, 1, 1, 0); INSERT INTO Permissions VALUES (DEFAULT, 'in-portal:session_logs.view', 11, 1, 1, 0); Index: core/install/install_schema.sql =================================================================== --- core/install/install_schema.sql (revision 15252) +++ core/install/install_schema.sql (working copy) @@ -140,7 +140,7 @@ KEY l5_PlainTextBody (l5_PlainTextBody(5)) ); -CREATE TABLE EmailEventSubscribers ( +CREATE TABLE SystemEventSubscriptions ( SubscriptionId int(11) NOT NULL AUTO_INCREMENT, EmailEventId int(11) DEFAULT NULL, SubscriberEmail varchar(255) NOT NULL DEFAULT '', Index: core/install/remove_schema.sql =================================================================== --- core/install/remove_schema.sql (revision 15252) +++ core/install/remove_schema.sql (working copy) @@ -4,7 +4,7 @@ DROP TABLE SystemSettings; DROP TABLE EmailQueue; DROP TABLE EmailEvents; -DROP TABLE EmailEventSubscribers; +DROP TABLE SystemEventSubscriptions; DROP TABLE IdGenerator; DROP TABLE Languages; DROP TABLE Modules; Index: core/install/upgrades.sql =================================================================== --- core/install/upgrades.sql (revision 15253) +++ core/install/upgrades.sql (working copy) @@ -2712,7 +2712,7 @@ ALTER TABLE EmailEvents ADD BindToSystemEvent VARCHAR(255) NOT NULL DEFAULT ''; -CREATE TABLE EmailEventSubscribers ( +CREATE TABLE SystemEventSubscriptions ( SubscriptionId int(11) NOT NULL AUTO_INCREMENT, EmailEventId int(11) DEFAULT NULL, SubscriberEmail varchar(255) NOT NULL DEFAULT '', @@ -2724,3 +2724,17 @@ PRIMARY KEY (SubscriptionId), KEY EmailEventId (EmailEventId) ); + +INSERT INTO Permissions VALUES (DEFAULT, 'in-portal:system_event_subscriptions.view', 11, 1, 1, 0); +INSERT INTO Permissions VALUES (DEFAULT, 'in-portal:system_event_subscriptions.add', 11, 1, 1, 0); +INSERT INTO Permissions VALUES (DEFAULT, 'in-portal:system_event_subscriptions.edit', 11, 1, 1, 0); +INSERT INTO Permissions VALUES (DEFAULT, 'in-portal:system_event_subscriptions.delete', 11, 1, 1, 0); + +UPDATE LanguageLabels +SET + l1_ColumnTranslation = l1_Translation, + l2_ColumnTranslation = l2_Translation, + l3_ColumnTranslation = l3_Translation, + l4_ColumnTranslation = l4_Translation, + l5_ColumnTranslation = l5_Translation +WHERE PhraseKey IN ('LA_FLD_BINDTOSYSTEMEVENT', 'LA_FLD_CATEGORYID'); Index: core/kernel/db/db_event_handler.php =================================================================== --- core/kernel/db/db_event_handler.php (revision 15252) +++ core/kernel/db/db_event_handler.php (working copy) @@ -2446,17 +2446,52 @@ $object = $event->getObject(); /* @var $object kDBItem */ + // 1. delete direct subscriptions to item, that was deleted + $this->_deleteSubscriptions($event->Prefix, 'ItemId', $object->GetID()); + + $sub_items = $this->Application->getUnitOption($event->Prefix, 'SubItems', Array ()); + /* @var $sub_items Array */ + + // 2. delete this item sub-items subscriptions, that reference item, that was deleted + foreach ($sub_items as $sub_prefix) { + $this->_deleteSubscriptions($sub_prefix, 'ParentItemId', $object->GetID()); + } + } + + /** + * Deletes all subscriptions, associated with given item + * + * @param string $prefix + * @param string $field + * @param int $value + * @return void + * @access protected + */ + protected function _deleteSubscriptions($prefix, $field, $value) + { $sql = 'SELECT EventId FROM ' . TABLE_PREFIX . 'EmailEvents - WHERE BindToSystemEvent REGEXP "' . $this->Conn->escape($event->Prefix) . '[.]{0,1}([^:]*):(.*)"'; + WHERE BindToSystemEvent REGEXP "' . $this->Conn->escape($prefix) . '(\\\\.[^:]*:.*|:.*)"'; $email_event_ids = $this->Conn->GetCol($sql); - if ( $email_event_ids ) { - // e-mail events, connected to that unit prefix are found - $sql = 'DELETE FROM ' . TABLE_PREFIX . 'EmailEventSubscribers - WHERE ItemId = ' . $object->GetID() . ' AND EmailEventId IN (' . implode(',', $email_event_ids) . ')'; - $this->Conn->Query($sql); + if ( !$email_event_ids ) { + return; } + + // e-mail events, connected to that unit prefix are found + $sql = 'SELECT SubscriptionId + FROM ' . TABLE_PREFIX . 'SystemEventSubscriptions + WHERE ' . $field . ' = ' . $value . ' AND EmailEventId IN (' . implode(',', $email_event_ids) . ')'; + $ids = $this->Conn->GetCol($sql); + + if ( !$ids ) { + return; + } + + $temp_handler = $this->Application->recallObject('system-event-subscription_TempHandler', 'kTempTablesHandler'); + /* @var $temp_handler kTempTablesHandler */ + + $temp_handler->DeleteItems('system-event-subscription', '', $ids); } /** Index: core/kernel/db/dblist.php =================================================================== --- core/kernel/db/dblist.php (revision 15226) +++ core/kernel/db/dblist.php (working copy) @@ -18,7 +18,7 @@ * DBList * */ -class kDBList extends kDBBase { +class kDBList extends kDBBase implements Iterator, Countable { // kDBList filter types (then, types are divided into classes) @@ -1493,6 +1493,79 @@ { $this->mainList = true; } + + /** + * Moves recordset pointer to first element + * + * @return void + * @access public + * @implements Iterator::rewind + */ + public function rewind() + { + $this->Query(); + $this->GoFirst(); + } + + /** + * Returns value at current position + * + * @return mixed + * @access public + * @implements Iterator::current + */ + function current() + { + return $this->getCurrentRecord(); + } + + /** + * Returns key at current position + * + * @return mixed + * @access public + * @implements Iterator::key + */ + function key() + { + return $this->CurrentIndex; + } + + /** + * Moves recordset pointer to next position + * + * @return void + * @access public + * @implements Iterator::next + */ + function next() + { + $this->GoNext(); + } + + /** + * Detects if current position is within recordset bounds + * + * @return bool + * @access public + * @implements Iterator::valid + */ + public function valid() + { + return !$this->EOL(); + } + + /** + * Counts recordset rows + * + * @return int + * @access public + * @implements Countable::count + */ + public function count() + { + return $this->SelectedCount; + } } Index: core/kernel/event_handler.php =================================================================== --- core/kernel/event_handler.php (revision 15252) +++ core/kernel/event_handler.php (working copy) @@ -219,7 +219,7 @@ protected function OnGetEventSubscribersQuery(kEvent $event) { $sql = 'SELECT SubscriberEmail, UserId - FROM ' . TABLE_PREFIX . 'EmailEventSubscribers + FROM ' . $this->Application->getUnitOption('system-event-subscription', 'TableName') . ' WHERE (' . implode(') AND (', $event->getEventParam('where_clause')) . ')'; $event->setEventParam('sql', $sql); } Index: core/units/categories/categories_event_handler.php =================================================================== --- core/units/categories/categories_event_handler.php (revision 15260) +++ core/units/categories/categories_event_handler.php (working copy) @@ -953,6 +953,19 @@ SET SymLinkCategoryId = NULL WHERE SymLinkCategoryId = ' . $object->GetID(); $this->Conn->Query($sql); + + // delete direct subscriptions to category, that was deleted + $sql = 'SELECT SubscriptionId + FROM ' . TABLE_PREFIX . 'SystemEventSubscriptions + WHERE CategoryId = ' . $object->GetID(); + $ids = $this->Conn->GetCol($sql); + + if ( $ids ) { + $temp_handler = $this->Application->recallObject('system-event-subscription_TempHandler', 'kTempTablesHandler'); + /* @var $temp_handler kTempTablesHandler */ + + $temp_handler->DeleteItems('system-event-subscription', '', $ids); + } } /** Index: core/units/email_events/email_events_event_handler.php =================================================================== --- core/units/email_events/email_events_event_handler.php (revision 15252) +++ core/units/email_events/email_events_event_handler.php (working copy) @@ -709,8 +709,18 @@ $object = $event->getObject(); /* @var $object kDBItem */ - $sql = 'DELETE FROM ' . TABLE_PREFIX . 'EmailEventSubscribers + $sql = 'SELECT SubscriptionId + FROM ' . TABLE_PREFIX . 'SystemEventSubscriptions WHERE EmailEventId = ' . $object->GetID(); - $this->Conn->Query($sql); + $ids = $this->Conn->GetCol($sql); + + if ( !$ids ) { + return; + } + + $temp_handler = $this->Application->recallObject('system-event-subscription_TempHandler', 'kTempTablesHandler'); + /* @var $temp_handler kTempTablesHandler */ + + $temp_handler->DeleteItems('system-event-subscription', '', $ids); } } \ No newline at end of file Property changes on: core\units\system_event_subscriptions ___________________________________________________________________ Added: tsvn:autoprops + *.php = svn:eol-style=LF;svn:keywords=Id *.tpl = svn:eol-style=LF *.sql = svn:eol-style=LF *.lang = svn:eol-style=LF *.sh = svn:eol-style=LF;svn:executable *.txt = svn:eol-style=LF *.html = svn:eol-style=LF *.htm = svn:eol-style=LF *.css = svn:eol-style=LF *.js = svn:eol-style=LF *.xml = svn:eol-style=LF .htaccess = svn:eol-style=LF .smsignore = svn:eol-style=LF COPYRIGHT = svn:eol-style=LF CREDITS = svn:eol-style=LF INSTALL = svn:eol-style=LF LICENSE = svn:eol-style=LF LICENSES = svn:eol-style=LF README = svn:eol-style=LF Added: bugtraq:url + http://tracker.in-portal.org/view.php?id=%BUGID% Added: bugtraq:number + true Added: bugtraq:logregex + (?:[Bb]ugs?|[Ii]ssues?|[Rr]eports?|[Ff]ixe?s?|[Rr]esolves?)+\s+(?:#?(?:\d+)[,\.\s]*)+ (\d+) Index: core/units/system_event_subscriptions/system_event_subscription_eh.php =================================================================== --- core/units/system_event_subscriptions/system_event_subscription_eh.php (revision 0) +++ core/units/system_event_subscriptions/system_event_subscription_eh.php (revision 0) @@ -0,0 +1,102 @@ +_setRequired($event); + } + + /** + * Makes either user or e-mail required + * + * @param kEvent $event + * @return void + * @access protected + */ + protected function OnPreCreate(kEvent $event) + { + parent::OnPreCreate($event); + + $this->_setRequired($event); + } + + /** + * Makes either user or e-mail required + * + * @param kEvent $event + * @return void + * @access protected + */ + protected function OnBeforeItemCreate(kEvent $event) + { + parent::OnBeforeItemCreate($event); + + $this->_itemChanged($event); + } + + /** + * Makes either user or e-mail required + * + * @param kEvent $event + * @return void + * @access protected + */ + protected function OnBeforeItemUpdate(kEvent $event) + { + parent::OnBeforeItemUpdate($event); + + $this->_itemChanged($event); + } + + /** + * Makes either user or e-mail required + * + * @param kEvent $event + * @return void + * @access protected + */ + protected function _itemChanged(kEvent $event) + { + $this->_setRequired($event); + } + + /** + * Makes either user or e-mail required + * + * @param kEvent $event + * @return void + * @access protected + */ + protected function _setRequired(kEvent $event) + { + $object = $event->getObject(); + /* @var $object kDBItem */ + + $object->setRequired('UserId', !$object->GetDBField('SubscriberEmail')); + $object->setRequired('SubscriberEmail', !$object->GetDBField('UserId')); + } +} \ No newline at end of file Property changes on: core\units\system_event_subscriptions\system_event_subscription_eh.php ___________________________________________________________________ Added: svn:keywords + Id Added: svn:eol-style + LF Index: core/units/system_event_subscriptions/system_event_subscription_tp.php =================================================================== --- core/units/system_event_subscriptions/system_event_subscription_tp.php (revision 0) +++ core/units/system_event_subscriptions/system_event_subscription_tp.php (revision 0) @@ -0,0 +1,252 @@ +getObject($params); + /* @var $object kDBItem */ + + $category_id = $object->GetDBField('CategoryId'); + + if ( !is_numeric($category_id) ) { + return ''; + } + + $params['cat_id'] = $category_id; + + return $this->Application->ProcessParsedTag('c', 'CategoryPath', $params); + } + + /** + * Prints item name + * + * @param Array $params + * @return string + * @access protected + */ + protected function ItemName($params) + { + $object = $this->getObject($params); + /* @var $object kDBList */ + + if ( !isset($this->_analyzer) ) { + $this->_analyzer = new kSubscriptionAnalyzer($object); + $this->_analyzer->run(); + } + + return $this->_analyzer->getTitle($this->SelectParam($params, 'name,field')); + } +} + + +class kSubscriptionAnalyzer extends kBase { + + /** + * Reference to a list object + * + * @var kDBList + * @access protected + */ + protected $_subscriptions = null; + + /** + * Remember what to what ids subscription exists for each of subscribed prefixes + * + * @var Array + * @access protected + */ + protected $_prefixToIdsMap = Array (); + + /** + * Reverse index that remembers what prefix is used in what row (fields: ItemId, ParentItemId) + * + * @var Array + * @access protected + */ + protected $_prefixToRowMap = Array (); + + /** + * Holds title of each item in list in format [prefix][id] = title + * + * @var Array + * @access protected + */ + protected $_itemTitles = Array (); + + /** + * Set's references to kApplication and kDBConnection class instances + * + * @param kDBList $subscriptions + * @access public + * @see kApplication + * @see kDBConnection + */ + public function __construct($subscriptions) + { + parent::__construct(); + + $this->_subscriptions = $subscriptions; + } + + /** + * Analyzes list + * + * @return void + * @access public + */ + public function run() + { + foreach ($this->_subscriptions as $subscription) { + $prefix = $this->_getPrefix(); + $parent_prefix = $this->Application->getUnitOption($prefix, 'ParentPrefix'); + + $this->_addIdToPrefix($prefix, 'ItemId'); + $this->_addIdToPrefix($parent_prefix, 'ParentItemId'); + } + + $this->_queryItemTitles(); + $this->_subscriptions->GoFirst(); + } + + /** + * Returns item title, associated with item's ID in given field + * + * @param string $field + * @return string + */ + public function getTitle($field) + { + $row_index = $this->_subscriptions->key(); + + if ( !isset($this->_prefixToRowMap[$row_index][$field]) ) { + return ''; + } + + $prefix = $this->_prefixToRowMap[$row_index][$field]; + $value = $this->_subscriptions->GetDBField($field); + + return $this->_itemTitles[$prefix][$value]; + } + + /** + * Queries titles for each of subscribed items + * + * @return void + * @access protected + */ + protected function _queryItemTitles() + { + foreach ($this->_prefixToIdsMap as $prefix => $ids) { + $id_field = $this->Application->getUnitOption($prefix, 'IDField'); + + $sql = 'SELECT ' . $this->_getTitleField($prefix) . ', ' . $id_field . ' + FROM ' . $this->Application->getUnitOption($prefix, 'TableName') . ' + WHERE ' . $id_field . ' IN (' . implode(',', $ids) . ')'; + $this->_itemTitles[$prefix] = $this->Conn->GetCol($sql, $id_field); + } + } + + /** + * Adds ID from a gvein field (when it isn't NULL) to prefix ids + * + * @param string $prefix + * @param string $field + * @return void + * @access protected + */ + protected function _addIdToPrefix($prefix, $field) + { + $id = $this->_subscriptions->GetDBField($field); + + if ( !$id || !$prefix ) { + return; + } + + // add id to prefix ids list + if ( !isset($this->_prefixToIdsMap[$prefix]) ) { + $this->_prefixToIdsMap[$prefix] = Array (); + } + + if ( !in_array($id, $this->_prefixToIdsMap[$prefix]) ) { + $this->_prefixToIdsMap[$prefix][] = $id; + } + + // remeber prefix associated with this field + $row_index = $this->_subscriptions->key(); + + if ( !isset($this->_prefixToRowMap[$row_index]) ) { + $this->_prefixToRowMap[$row_index] = Array (); + } + + $this->_prefixToRowMap[$row_index][$field] = $prefix; + } + + /** + * Returns prefix of main item in current row + * + * @return string + * @access protected + */ + protected function _getPrefix() + { + $event = new kEvent($this->_subscriptions->GetDBField('BindToSystemEvent')); + + return $event->Prefix; + } + + /** + * Returns title field of given prefix + * + * @param string $prefix + * @return array + */ + protected function _getTitleField($prefix) + { + $lang_prefix = ''; + $title_field = $this->Application->getUnitOption($prefix, 'TitleField'); + + if ( preg_match('/^(l[\d]+_)(.*)/', $title_field, $regs) ) { + // object was initialized and we have lang prefix in unit config + $lang_prefix = $regs[1]; + $title_field = $regs[2]; + } + else { + // object wasn't initialized -> check other way OR not ml title field + $fields = $this->Application->getUnitOption($prefix, 'Fields'); + + if ( isset($fields[$title_field]['formatter']) && $fields[$title_field]['formatter'] == 'kMultiLanguage' ) { + $lang_prefix = 'l' . $this->Application->GetVar('m_lang') . '_'; + } + } + + return $lang_prefix . $title_field; + } +} \ No newline at end of file Property changes on: core\units\system_event_subscriptions\system_event_subscription_tp.php ___________________________________________________________________ Added: svn:keywords + Id Added: svn:eol-style + LF Index: core/units/system_event_subscriptions/system_event_subscriptions_config.php =================================================================== --- core/units/system_event_subscriptions/system_event_subscriptions_config.php (revision 0) +++ core/units/system_event_subscriptions/system_event_subscriptions_config.php (revision 0) @@ -0,0 +1,136 @@ + 'system-event-subscription', + 'ItemClass' => Array ('class' => 'kDBItem', 'file' => '', 'build_event' => 'OnItemBuild'), + 'ListClass' => Array ('class' => 'kDBList', 'file' => '', 'build_event' => 'OnListBuild'), + 'EventHandlerClass' => Array ('class' => 'SystemEventSubscriptionEventHandler', 'file' => 'system_event_subscription_eh.php', 'build_event' => 'OnBuild'), + 'TagProcessorClass' => Array ('class' => 'SystemEventSubscriptionTagProcessor', 'file' => 'system_event_subscription_tp.php', 'build_event' => 'OnBuild'), + + 'AutoLoad' => true, + + 'QueryString' => Array ( + 1 => 'id', + 2 => 'Page', + 3 => 'PerPage', + 4 => 'event', + 5 => 'mode', + ), + + 'IDField' => 'SubscriptionId', + + 'TableName' => TABLE_PREFIX . 'SystemEventSubscriptions', + + 'TitleField' => 'SubscriptionId', + + 'TitlePresets' => Array ( + 'default' => Array ( + 'new_status_labels' => Array ('system-event-subscription' => '!la_title_AddingSystemEventSubscription!'), + 'edit_status_labels' => Array ('system-event-subscription' => '!la_title_EditingSystemEventSubscription!'), + ), + + 'system_event_subscription_list' => Array ( + 'prefixes' => Array ('system-event-subscription_List'), 'format' => "!la_title_SystemEventSubscriptions!", + 'toolbar_buttons' => Array ('new_item', 'edit', 'delete', 'view', 'dbl-click'), + ), + + 'system_event_subscription_edit' => Array ( + 'prefixes' => Array ('system-event-subscription'), 'format' => "#system-event-subscription_status# '#system-event-subscription_titlefield#'", + 'toolbar_buttons' => Array ('select', 'cancel', 'reset_edit', 'prev', 'next'), + ), + ), + + 'PermSection' => Array('main' => 'in-portal:system_event_subscriptions'), + + 'Sections' => Array ( + 'in-portal:system_event_subscriptions' => Array ( + 'parent' => 'in-portal:users', + 'icon' => 'system_event_subscriptions', + 'label' => 'la_title_SystemEventSubscriptions', + 'url' => Array('t' => 'system_event_subscriptions/system_event_subscription_list', 'pass' => 'm'), + 'permissions' => Array('view', 'add', 'edit', 'delete'), + 'priority' => 6, + 'type' => stTREE, + ), + ), + + 'ListSQLs' => Array ( + '' => ' SELECT %1$s.* %2$s + FROM %1$s + LEFT JOIN ' . TABLE_PREFIX . 'EmailEvents ee ON %1$s.EmailEventId = ee.EventId + LEFT JOIN ' . TABLE_PREFIX . 'Users u ON %1$s.UserId = u.PortalUserId + LEFT JOIN ' . TABLE_PREFIX . 'Categories c ON %1$s.CategoryId = c.CategoryId', + ), + + 'CalculatedFields' => Array ( + '' => Array ( + 'BindToSystemEvent' => 'ee.BindToSystemEvent', + 'EmailEventName' => 'ee.Event', + 'Username' => 'CASE %1$s.UserId WHEN ' . USER_ROOT . ' THEN "root" WHEN ' . USER_GUEST . ' THEN "Guest" ELSE IF(CONCAT(u.FirstName, u.LastName) <> "", CONCAT(u.FirstName, " ", u.LastName), IF(%1$s.UserId IS NULL, "Guest", u.Username)) END', + 'CategoryName' => 'c.l%2$s_Name', + 'ItemName' => '%1$s.ItemId', + 'ParentItemName' => '%1$s.ParentItemId', + ), + ), + + 'ListSortings' => Array ( + '' => Array ( + 'Sorting' => Array ('SubscriptionId' => 'desc'), + ) + ), + + 'Fields' => Array ( + 'SubscriptionId' => Array ('type' => 'int', 'not_null' => 1, 'default' => 0), + 'EmailEventId' => Array ( + 'type' => 'int', + 'formatter' => 'kOptionsFormatter', 'options_sql' => 'SELECT %s FROM ' . TABLE_PREFIX . 'EmailEvents WHERE BindToSystemEvent <> "" ORDER BY Event ASC', 'option_key_field' => 'EventId', 'option_title_field' => 'BindToSystemEvent', + 'required' => 1, 'default' => NULL + ), + 'SubscriberEmail' => Array ('type' => 'string', 'max_len' => 255, 'not_null' => 1, 'default' => ''), + 'UserId' => Array ('type' => 'int', 'formatter' => 'kLEFTFormatter', 'error_msgs' => Array ('invalid_option' => '!la_error_UserNotFound!'), 'options' => Array (USER_ROOT => 'root', USER_GUEST => 'Guest'), 'left_sql' => 'SELECT %s FROM ' . TABLE_PREFIX . 'Users WHERE `%s` = \'%s\'', 'left_key_field' => 'PortalUserId', 'left_title_field' => 'Username', 'default' => NULL), + 'CategoryId' => Array ('type' => 'int', 'default' => NULL), + 'ItemId' => Array ('type' => 'int', 'default' => NULL), + 'ParentItemId' => Array ('type' => 'int', 'default' => NULL), + 'SubscribedOn' => Array ('type' => 'int', 'formatter' => 'kDateFormatter', 'required' => 1, 'default' => '#NOW#') + ), + + 'VirtualFields' => Array ( + 'Username' => Array ('type' => 'string', 'default' => ''), + 'EmailEventName' => Array ('type' => 'string', 'default' => ''), + 'CategoryName' => Array ('type' => 'string', 'formatter' => 'kMultiLanguage', 'default' => ''), + ), + + 'Grids' => Array ( + 'Default' => Array ( + 'Fields' => Array ( + 'SubscriptionId' => Array ('title' => 'column:la_fld_Id', 'filter_block' => 'grid_range_filter', 'width' => 80), + 'EmailEventId' => Array ('title' => 'column:la_fld_SystemEvent', 'filter_block' => 'grid_options_filter', 'width' => 170), + 'EmailEventName' => Array ('title' => 'column:la_fld_EmailEvent', 'filter_block' => 'grid_like_filter', 'width' => 170), + 'SubscriberEmail' => Array ('title' => 'column:la_fld_Email', 'filter_block' => 'grid_like_filter'), + 'UserId' => Array ('title' => 'la_col_PortalUserId', 'filter_block' => 'grid_range_filter', 'width' => 80), + 'Username' => Array ('filter_block' => 'grid_like_filter'), + 'CategoryId' => Array ('title' => 'column:la_fld_CategoryId', /*'data_block' => 'grid_category_td',*/ 'filter_block' => 'grid_range_filter', 'width' => 100), + 'CategoryName' => Array ('title' => 'column:la_fld_Category', 'filter_block' => 'grid_like_filter', 'width' => 200), + 'ItemId' => Array ('filter_block' => 'grid_range_filter', 'width' => 80), + 'ItemName' => Array ('data_block' => 'grid_item_name_td', 'associated_field' => 'ItemId', 'filter_block' => 'grid_like_filter', 'width' => 120), + 'ParentItemId' => Array ('filter_block' => 'grid_range_filter', 'width' => 80), + 'ParentItemName' => Array ('data_block' => 'grid_item_name_td', 'associated_field' => 'ParentItemId', 'filter_block' => 'grid_like_filter', 'width' => 120), + 'SubscribedOn' => Array ('filter_block' => 'grid_date_range_filter', 'width' => 170) + ), + ), + ), +); \ No newline at end of file Property changes on: core\units\system_event_subscriptions\system_event_subscriptions_config.php ___________________________________________________________________ Added: svn:keywords + Id Added: svn:eol-style + LF