diff --git a/assets/components/mxcalendars/connector.php b/assets/components/mxcalendars/connector.php index 77a5b59..31c71cd 100644 --- a/assets/components/mxcalendars/connector.php +++ b/assets/components/mxcalendars/connector.php @@ -1,20 +1,30 @@ getOption('mxcalendars.core_path', null, $modx->getOption('core_path') . 'components/mxcalendars/'); + +$modx->mxcalendars = $modx->getService( + 'mxCalendars', + 'mxCalendars', + $corePath . 'model/mxcalendars/', + array( + 'core_path' => $corePath + ) +); -require_once dirname(dirname(dirname(dirname(__FILE__)))).'/config.core.php'; -require_once MODX_CORE_PATH.'config/'.MODX_CONFIG_KEY.'.inc.php'; -require_once MODX_CONNECTORS_PATH.'index.php'; - -$corePath = $modx->getOption('mxcalendars.core_path',null,$modx->getOption('core_path').'components/mxcalendars/'); -require_once $corePath.'model/mxcalendars/mxcalendars.class.php'; -$modx->mxcalendars = new mxCalendars($modx); - -$modx->lexicon->load('mxcalendars:default'); - /* handle request */ -$path = $modx->getOption('processorsPath',$modx->mxcalendars->config,$corePath.'processors/'); -$modx->request->handleRequest(array( - 'processors_path' => $path, - 'location' => '', -)); +$modx->request->handleRequest( + array( + 'processors_path' => $modx->getOption('processorsPath', null, $corePath . 'processors/'), + 'location' => '', + ) +); -?> +$modx->lexicon->load('mxcalendars:default'); diff --git a/assets/components/mxcalendars/js/mgr/sections/index.js b/assets/components/mxcalendars/js/mgr/sections/home.js similarity index 50% rename from assets/components/mxcalendars/js/mgr/sections/index.js rename to assets/components/mxcalendars/js/mgr/sections/home.js index c930776..e1c8c3c 100644 --- a/assets/components/mxcalendars/js/mgr/sections/index.js +++ b/assets/components/mxcalendars/js/mgr/sections/home.js @@ -1,19 +1,16 @@ Ext.onReady(function() { MODx.load({ xtype: 'mxcalendars-page-home'}); - - // Load the datastore for the chunks - //mxcCore.stores.chunks.load(); }); - + mxcCore.page.Home = function(config) { config = config || {}; Ext.applyIf(config,{ components: [{ - xtype: 'mxcalendars-panel-home' - ,renderTo: 'mxcalendars-panel-home-div' + xtype: 'mxcalendars-panel-home', + renderTo: 'mxcalendars-panel-home-div' }] }); mxcCore.page.Home.superclass.constructor.call(this,config); }; -Ext.extend(mxcCore.page.Home,MODx.Component); -Ext.reg('mxcalendars-page-home',mxcCore.page.Home); +Ext.extend(mxcCore.page.Home, MODx.Component); +Ext.reg('mxcalendars-page-home', mxcCore.page.Home); diff --git a/assets/components/mxcalendars/js/mgr/widgets/home.panel.js b/assets/components/mxcalendars/js/mgr/widgets/home.panel.js index 741b01d..5f20f04 100644 --- a/assets/components/mxcalendars/js/mgr/widgets/home.panel.js +++ b/assets/components/mxcalendars/js/mgr/widgets/home.panel.js @@ -1,67 +1,84 @@ mxcCore.panel.Home = function(config) { config = config || {}; Ext.apply(config,{ - border: false - ,baseCls: 'modx-formpanel' - ,items: [{ - html: ''+_('mxcalendars.management')+'' - ,border: false - ,cls: 'modx-page-header' - },{ - xtype: 'modx-tabs' - ,bodyStyle: 'padding: 10px' - ,defaults: { border: false,autoHeight: true } - ,border: true - ,items: [{ - //-- Events Tab - title: _('mxcalendars.tab_events') - ,defaults: { autoHeight: true } - ,items: [ - // ADD DESCRIPTION INFORMATION - { - html: '

'+_('mxcalendars.management_desc')+'


' - ,border: false - }, - // ADD THE GRID CONTROLLER - { - xtype: 'mxcalendars-grid-events' - ,preventRender: true - } + border: false, + baseCls: 'modx-formpanel', + cls: 'container', + items: [ + { + html: '

' + _('mxcalendars.component_title') + '

', + border: false, + cls: 'modx-page-header' + }, + { + xtype: 'modx-tabs', + bodyStyle: 'padding: 10px', + defaults: { border: false,autoHeight: true }, + border: true, + items: [ + { + //-- Events Tab + title: _('mxcalendars.tab_events'), + defaults: { autoHeight: true }, + items: [ + // ADD DESCRIPTION INFORMATION + { + html: '

' + _('mxcalendars.management_desc') + '


', + border: false + }, + // ADD THE GRID CONTROLLER + { + xtype: 'mxcalendars-grid-events', + preventRender: true + } ] - },{ - //-- Categories Tab - title: _('mxcalendars.tab_categories') - ,defaults: { autoHeight: true } - ,items: [{ - html: '

'+_('mxcalendars.category_desc')+'


' - ,border: false - },{ - xtype: 'mxcalendars-grid-categories' - ,preventRender: true - }] - },{ - //-- Calendars Tab - title: _('mxcalendars.tab_calendars') - ,items: [{ - html: '

'+_('mxcalendars.calendar_desc')+'


' - ,border: false - },{ - xtype: 'mxcalendars-grid-calendars' - ,preventRender: true - }] - },{ - //-- Feeds Tab - title: _('mxcalendars.tab_feed') - ,items: [{ - html: '

'+_('mxcalendars.feed_desc')+'


' - ,border: false - },{ - xtype: 'mxcalendars-grid-feeds' - ,preventRender: true - }] - } - ] - }] + }, + { + //-- Categories Tab + title: _('mxcalendars.tab_categories'), + defaults: { autoHeight: true }, + items: [ + { + html: '

' + _('mxcalendars.category_desc') + '


', + border: false + }, + { + xtype: 'mxcalendars-grid-categories', + preventRender: true + } + ] + }, + { + //-- Calendars Tab + title: _('mxcalendars.tab_calendars'), + items: [ + { + html: '

' + _('mxcalendars.calendar_desc') + '


', + border: false + }, + { + xtype: 'mxcalendars-grid-calendars', + preventRender: true + } + ] + }, + { + //-- Feeds Tab + title: _('mxcalendars.tab_feed'), + items: [ + { + html: '

' + _('mxcalendars.feed_desc') + '


', + border: false + }, + { + xtype: 'mxcalendars-grid-feeds', + preventRender: true + } + ] + } + ] + } + ] }); mxcCore.panel.Home.superclass.constructor.call(this,config); }; diff --git a/assets/components/mxcalendars/js/mgr/widgets/mxcalendars.calendars.grid.js b/assets/components/mxcalendars/js/mgr/widgets/mxcalendars.calendars.grid.js index d7b8368..e7e55eb 100644 --- a/assets/components/mxcalendars/js/mgr/widgets/mxcalendars.calendars.grid.js +++ b/assets/components/mxcalendars/js/mgr/widgets/mxcalendars.calendars.grid.js @@ -1,8 +1,8 @@ Ext.USE_NATIVE_JSON = false; function openWin() { - pf = document.getElementById("printfriendly").innerHTML; - pfw=window.open('','','width=550,height=600'); + let pf = document.getElementById("printfriendly").innerHTML; + let pfw = window.open('','','width=550,height=600'); pfw.document.write(pf); pfw.focus(); } @@ -10,85 +10,104 @@ function openWin() mxcCore.grid.calendars = function(config) { config = config || {}; Ext.applyIf(config,{ - id: 'mxcalendars-grid-calendars' - ,url: mxcCore.config.connectorUrl - ,baseParams: { action: 'mgr/calendar/getList' } - ,fields: ['id','name','webusergroup','active'] - ,paging: true - ,remoteSort: true - ,anchor: '97%' - ,autoExpandColumn: 'name' - ,save_action: 'mgr/calendar/updatefromgrid' // Support the inline editing - ,autosave: true // Support the inline editing - ,columns: [{ - header: _('id') - ,dataIndex: 'id' - ,sortable: true - },{ - header: _('mxcalendars.calendar_name_col_label') - ,dataIndex: 'name' - ,sortable: true - ,editor: { xtype: 'textfield' } - }/*,{ - header: _('mxcalendars.calendar_name_col_wug') - ,dataIndex: 'webusergroup' - ,sortable: true - ,editor: { xtype: 'textfield' } - }*/,{ - header: _('mxcalendars.calendar_name_col_active') - ,dataIndex: 'active' - ,sortable: true - ,editor: { xtype: 'modx-combo-boolean', renderer: true} - }],tbar:[{ - xtype: 'textfield' - ,id: 'mxcalendars-search-calendars-filter' - ,emptyText:_('mxcalendars.default_calendar_search') - ,listeners: { - 'change': {fn:this.search,scope:this} - ,'render': {fn: function(cmp) { + id: 'mxcalendars-grid-calendars', + url: mxcCore.config.connectorUrl, + baseParams: { action: 'mgr/calendar/getList' }, + fields: ['id','name','webusergroup','active'], + paging: true, + remoteSort: true, + anchor: '97%', + autoExpandColumn: 'name', + save_action: 'mgr/calendar/updatefromgrid', // Support the inline editing + autosave: true, // Support the inline editing + columns: [ + { + header: _('id'), + dataIndex: 'id', + sortable: true + }, + { + header: _('mxcalendars.calendar_name_col_label'), + dataIndex: 'name', + sortable: true, + editor: { xtype: 'textfield' } + }, + /*{ + header: _('mxcalendars.calendar_name_col_wug') + ,dataIndex: 'webusergroup' + ,sortable: true + ,editor: { xtype: 'textfield' } + },*/ + { + header: _('mxcalendars.calendar_name_col_active'), + dataIndex: 'active', + sortable: true, + editor: { xtype: 'modx-combo-boolean', renderer: true} + } + ], + tbar:[ + { + xtype: 'textfield', + id: 'mxcalendars-search-calendars-filter', + emptyText:_('mxcalendars.calendar_default_calendar_search'), + listeners: + { + 'change': {fn:this.search,scope:this}, + 'render': + { + fn: function(cmp) { new Ext.KeyMap(cmp.getEl(), { - key: Ext.EventObject.ENTER - ,fn: function() { - this.fireEvent('change',this); - this.blur(); - return true; - } - ,scope: cmp + key: Ext.EventObject.ENTER, + fn: function() { + this.fireEvent('change',this); + this.blur(); + return true; + }, + scope: cmp }); - },scope:this} - } - },'->',{ - text:_('mxcalendars.calendar_btn_create') - ,handler: { xtype: 'mxcalendars-window-calendar-create' ,blankValues: true } - }] + }, + scope:this + } + } + },'->', + { + text:_('mxcalendars.calendar_btn_create'), + handler: { xtype: 'mxcalendars-window-calendar-create' ,blankValues: true } + } + ] }); - mxcCore.grid.calendars.superclass.constructor.call(this,config) + mxcCore.grid.calendars.superclass.constructor.call(this,config); }; + Ext.extend(mxcCore.grid.calendars,MODx.grid.Grid,{ - search: function(tf,nv,ov) {textfield - var s = this.getStore(); + search: function(tf,nv,ov) { + let s = this.getStore(); s.baseParams.query = tf.getValue(); this.getBottomToolbar().changePage(1); this.refresh(); - },getMenu: function() { - var m = [{ - text: _('mxcalendars.calendar_context_menu_update') - ,handler: this.updateCal - },'-',{ - text: _('mxcalendars.calendar_context_menu_remove') - ,handler: this.removeCal - },'-',{ - text: "View Calendar Item" - ,handler: this.viewCal - }]; + }, + getMenu: function() { + let m = [ + { + text: _('mxcalendars.calendar_context_menu_update'), + handler: this.updateCal + },'-',{ + text: _('mxcalendars.calendar_context_menu_remove'), + handler: this.removeCal + // },'-',{ + // text: 'View Calendar Item', + // handler: this.viewCal + } + ]; this.addContextMenuItem(m); return true; - },updateCal: function(btn,e) { + }, + updateCal: function(btn,e) { if (!this.updateCatWindow) { this.updateCatWindow = MODx.load({ - xtype: 'mxcalendars-window-calendar-update' - ,record: this.menu.record - ,listeners: { + xtype: 'mxcalendars-window-calendar-update', + record: this.menu.record, + listeners: { 'success': {fn:this.refresh,scope:this} } }); @@ -96,37 +115,39 @@ Ext.extend(mxcCore.grid.calendars,MODx.grid.Grid,{ this.updateCatWindow.setValues(this.menu.record); } this.updateCatWindow.show(e.target); - },removeCal: function() { + }, + removeCal: function() { MODx.msg.confirm({ - title: _('mxcalendars.cateogry_remove_title') - ,text: _('mxcalendars.cateogry_remove_confirm') - ,url: this.config.url - ,params: { - action: 'mgr/calendar/remove' - ,id: this.menu.record.id - } - ,listeners: { + title: _('mxcalendars.calendar_remove_title'), + text: _('mxcalendars.calendar_remove_confirm'), + url: this.config.url, + params: { + action: 'mgr/calendar/remove', + id: this.menu.record.id + }, + listeners: { 'success': {fn:this.refresh,scope:this} } }); - }, viewCal: function(){ - //-- this is your this.menu.record.json_post object - var json_src = '{"cust_FirstName":"Racovita","cust_LastName":"Victor","cust_PhoneDay":"","cust_Email1":"diavolss@yahoo.com","vInterest":"Pre-Owned","cust_Comments":"Dear Mr\/Ms\\r\\n\\r\\nI would like to ask how can i contact Hyundai engineering department?\\r\\nThank You","submit":"Submit","formConfigId":"contactUs","frm_chainTo":"\/request\/contact"}'; - var jsonData = Ext.util.JSON.decode(json_src); - var win = new Ext.Window({ - title :'My Title' - ,width : '80%' - ,height : '70%' - ,plain : true - ,html : '
'+ - '

My HTML content: '+this.menu.record.name+'

'+ - '

More fancy things can go here just remember your single quotes.

'+ - '

Sample JSON DATA: '+jsonData.cust_FirstName+' '+jsonData.cust_LastName+'

'+ - '
'+ - '

[ Print Me ]

' - }); - win.show(); - } + }, + viewCal: function() { + //-- this is your this.menu.record.json_post object + let json_src = '{"cust_FirstName":"Racovita","cust_LastName":"Victor","cust_PhoneDay":"","cust_Email1":"diavolss@yahoo.com","vInterest":"Pre-Owned","cust_Comments":"Dear Mr\/Ms\\r\\n\\r\\nI would like to ask how can i contact Hyundai engineering department?\\r\\nThank You","submit":"Submit","formConfigId":"contactUs","frm_chainTo":"\/request\/contact"}'; + let jsonData = Ext.util.JSON.decode(json_src); + let win = new Ext.Window({ + title:'My Title', + width: '80%', + height: '70%', + plain: true, + html: '
' + + '

My HTML content: '+this.menu.record.name+'

' + + '

More fancy things can go here just remember your single quotes.

' + + '

Sample JSON DATA: '+jsonData.cust_FirstName+' '+jsonData.cust_LastName+'

' + + '
' + + '

[ Print Me ]

' + }); + win.show(); + } }); Ext.reg('mxcalendars-grid-calendars',mxcCore.grid.calendars); @@ -137,23 +158,27 @@ Ext.reg('mxcalendars-grid-calendars',mxcCore.grid.calendars); mxcCore.window.UpdateCat = function(config) { config = config || {}; Ext.applyIf(config,{ - title: ''+_('mxcalendars.label_window_create') - ,url: mxcCore.config.connectorUrl - ,width: 650 - ,baseParams: { + title: ''+_('mxcalendars.label_window_create'), + url: mxcCore.config.connectorUrl, + width: 650, + baseParams: { action: 'mgr/calendar/update' - } - ,fields: [{xtype:'hidden',name:'id'},{ - xtype: 'textfield' - ,fieldLabel:_('mxcalendars.calendar_name_col_label') - ,name: 'name' - },{ - xtype: 'checkbox' - ,fieldLabel: _('mxcalendars.calendar_name_col_active') - ,name: 'active' - ,checked: true - ,value: 1 - }] + }, + fields: [ + { + xtype:'hidden',name:'id'},{ + xtype: 'textfield', + fieldLabel:_('mxcalendars.calendar_name_col_label'), + name: 'name' + }, + { + xtype: 'checkbox', + fieldLabel: _('mxcalendars.calendar_name_col_active'), + name: 'active', + checked: true, + value: 1 + } + ] }); mxcCore.window.UpdateCat.superclass.constructor.call(this,config); }; @@ -167,23 +192,26 @@ Ext.reg('mxcalendars-window-calendar-update',mxcCore.window.UpdateCat); mxcCore.window.CreateCal = function(config) { config = config || {}; Ext.applyIf(config,{ - title: ''+_('mxcalendars.label_window_create') - ,url: mxcCore.config.connectorUrl - ,width: 650 - ,baseParams: { + title: ''+_('mxcalendars.label_window_create'), + url: mxcCore.config.connectorUrl, + width: 650, + baseParams: { action: 'mgr/calendar/create' - } - ,fields: [{ - xtype: 'textfield' - ,fieldLabel:_('mxcalendars.calendar_name_col_label') - ,name: 'name' - },{ - xtype: 'checkbox' - ,fieldLabel: _('mxcalendars.calendar_name_col_active') - ,name: 'active' - ,checked: true - ,value: 1 - }] + }, + fields: [ + { + xtype: 'textfield', + fieldLabel:_('mxcalendars.calendar_name_col_label'), + name: 'name' + }, + { + xtype: 'checkbox', + fieldLabel: _('mxcalendars.calendar_name_col_active'), + name: 'active', + checked: true, + value: 1 + } + ] }); mxcCore.window.CreateCal.superclass.constructor.call(this,config); }; diff --git a/assets/components/mxcalendars/js/mgr/widgets/mxcalendars.categories.grid.js b/assets/components/mxcalendars/js/mgr/widgets/mxcalendars.categories.grid.js index 646267f..4e04c41 100644 --- a/assets/components/mxcalendars/js/mgr/widgets/mxcalendars.categories.grid.js +++ b/assets/components/mxcalendars/js/mgr/widgets/mxcalendars.categories.grid.js @@ -1,102 +1,123 @@ mxcCore.grid.categories = function(config) { config = config || {}; Ext.applyIf(config,{ - id: 'mxcalendars-grid-categories' - ,url: mxcCore.config.connectorUrl - ,baseParams: { action: 'mgr/category/getList' } - ,fields: ['id','isdefault','name','foregroundcss','backgroundcss','inlinecss','disable','active','menu'] - ,paging: true - ,remoteSort: true - ,anchor: '97%' - ,autoExpandColumn: 'name' - ,save_action: 'mgr/category/updatefromgrid' // Support the inline editing - ,autosave: true // Support the inline editing - ,columns: [{ - header: _('id') - ,dataIndex: 'id' - ,sortable: true - },{ - header: _('mxcalendars.category_isdefault_col_label') - ,dataIndex: 'isdefault' - ,sortable: true - ,editor: { xtype: 'modx-combo-boolean', renderer: true} - },{ - header: _('mxcalendars.category_name_col_label') - ,dataIndex: 'name' - ,sortable: true - ,editor: { xtype: 'textfield' } - },{ - header: _('mxcalendars.category_foregroundcss_col_label') - ,dataIndex: 'foregroundcss' - ,sortable: true - ,editor: { xtype: 'textfield' } - },{ - header: _('mxcalendars.category_backgroundcss_col_label') - ,dataIndex: 'backgroundcss' - ,sortable: true - ,editor: { xtype: 'textfield' } - },{ - header: _('mxcalendars.category_inlinecss_col_label') - ,dataIndex: 'inlinecss' - ,sortable: true - ,editor: { xtype: 'textfield' } - },{ - header: _('mxcalendars.category_disabled_col_label') - ,dataIndex: 'disable' - ,sortable: true - ,editor: { xtype: 'modx-combo-boolean', renderer: true} - },{ - header: _('mxcalendars.category_active_col_label') - ,dataIndex: 'active' - ,sortable: true - ,editor: { xtype: 'modx-combo-boolean', renderer: true} - }],tbar:[{ - xtype: 'textfield' - ,id: 'mxcalendars-search-categories-filter' - ,emptyText:_('mxcalendars.default_category_search') - ,listeners: { - 'change': {fn:this.search,scope:this} - ,'render': {fn: function(cmp) { - new Ext.KeyMap(cmp.getEl(), { - key: Ext.EventObject.ENTER - ,fn: function() { - this.fireEvent('change',this); - this.blur(); - return true; - } - ,scope: cmp - }); - },scope:this} - } - },'->',{ - text:_('mxcalendars.btn_create_cat') - ,handler: { xtype: 'mxcalendars-window-category-create' ,blankValues: true } - }] + id: 'mxcalendars-grid-categories', + url: mxcCore.config.connectorUrl, + baseParams: { action: 'mgr/category/getList' }, + fields: ['id','isdefault','name','foregroundcss','backgroundcss','inlinecss','disable','active','menu'], + paging: true, + remoteSort: true, + anchor: '97%', + autoExpandColumn: 'name', + save_action: 'mgr/category/updatefromgrid', // Support the inline editing + autosave: true, // Support the inline editing + columns: [ + { + header: _('id'), + dataIndex: 'id', + sortable: true + }, + { + header: _('mxcalendars.category_isdefault_col_label'), + dataIndex: 'isdefault', + sortable: true, + editor: { xtype: 'modx-combo-boolean', renderer: true} + }, + { + header: _('mxcalendars.category_name_col_label'), + dataIndex: 'name', + sortable: true, + editor: { xtype: 'textfield' } + }, + { + header: _('mxcalendars.category_foregroundcss_col_label'), + dataIndex: 'foregroundcss', + sortable: true, + editor: { xtype: 'textfield' } + }, + { + header: _('mxcalendars.category_backgroundcss_col_label'), + dataIndex: 'backgroundcss', + sortable: true, + editor: { xtype: 'textfield' } + }, + { + header: _('mxcalendars.category_inlinecss_col_label'), + dataIndex: 'inlinecss', + sortable: true, + editor: { xtype: 'textfield' } + }, + { + header: _('mxcalendars.category_disabled_col_label'), + dataIndex: 'disable', + sortable: true, + editor: { xtype: 'modx-combo-boolean', renderer: true} + }, + { + header: _('mxcalendars.category_active_col_label'), + dataIndex: 'active', + sortable: true, + editor: { xtype: 'modx-combo-boolean', renderer: true} + } + ], + tbar:[ + { + xtype: 'textfield', + id: 'mxcalendars-search-categories-filter', + emptyText:_('mxcalendars.default_category_search'), + listeners: { + 'change': {fn:this.search,scope:this}, + 'render': { + fn: function(cmp) { + new Ext.KeyMap(cmp.getEl(), { + key: Ext.EventObject.ENTER, + fn: function() { + this.fireEvent('change',this); + this.blur(); + return true; + }, + scope: cmp + }); + }, + scope:this + } + } + },'->', + { + text:_('mxcalendars.btn_create_cat'), + handler: { xtype: 'mxcalendars-window-category-create' ,blankValues: true } + } + ] }); - mxcCore.grid.categories.superclass.constructor.call(this,config) + mxcCore.grid.categories.superclass.constructor.call(this,config); }; Ext.extend(mxcCore.grid.categories,MODx.grid.Grid,{ - search: function(tf,nv,ov) {textfield - var s = this.getStore(); + search: function(tf,nv,ov) { + let s = this.getStore(); s.baseParams.query = tf.getValue(); this.getBottomToolbar().changePage(1); this.refresh(); - },getMenu: function() { - var m = [{ - text: _('mxcalendars.menu_update_category') - ,handler: this.updateCat - },'-',{ - text: _('mxcalendars.menu_remove_category') - ,handler: this.removeCat - }]; + }, + getMenu: function() { + let m = [ + { + text: _('mxcalendars.menu_update_category'), + handler: this.updateCat + },'-', + { + text: _('mxcalendars.menu_remove_category'), + handler: this.removeCat + } + ]; this.addContextMenuItem(m); return true; - },updateCat: function(btn,e) { + }, + updateCat: function(btn,e) { if (!this.updateCatWindow) { this.updateCatWindow = MODx.load({ - xtype: 'mxcalendars-window-category-update' - ,record: this.menu.record - ,listeners: { + xtype: 'mxcalendars-window-category-update', + record: this.menu.record, + listeners: { 'success': {fn:this.refresh,scope:this} } }); @@ -104,16 +125,17 @@ Ext.extend(mxcCore.grid.categories,MODx.grid.Grid,{ this.updateCatWindow.setValues(this.menu.record); } this.updateCatWindow.show(e.target); - },removeCat: function() { + }, + removeCat: function() { MODx.msg.confirm({ - title: _('mxcalendars.cateogry_remove_title') - ,text: _('mxcalendars.cateogry_remove_confirm') - ,url: this.config.url - ,params: { - action: 'mgr/category/remove' - ,id: this.menu.record.id - } - ,listeners: { + title: _('mxcalendars.cateogry_remove_title'), + text: _('mxcalendars.cateogry_remove_confirm'), + url: this.config.url, + params: { + action: 'mgr/category/remove', + id: this.menu.record.id + }, + listeners: { 'success': {fn:this.refresh,scope:this} } }); @@ -128,74 +150,88 @@ Ext.reg('mxcalendars-grid-categories',mxcCore.grid.categories); mxcCore.window.UpdateCat = function(config) { config = config || {}; Ext.applyIf(config,{ - title: ''+_('mxcalendars.label_window_create') - ,url: mxcCore.config.connectorUrl - ,width: 400 - ,baseParams: { + title: ''+_('mxcalendars.label_window_create'), + url: mxcCore.config.connectorUrl, + width: 400, + baseParams: { action: 'mgr/category/update' - } - ,fields: [{xtype:'hidden',name:'id'},{ - xtype: 'textfield' - ,fieldLabel:_('mxcalendars.category_name_col_label') - ,name: 'name' - }/*,{ - xtype: 'combo', - displayField: 'name', - valueField: 'id', - forceSelection: true, - store: new Ext.data.JsonStore({ - root: 'results', - idProperty: 'id', - url: mxcCore.config.connectorUrl, - baseParams: { - action: 'stores/getcalendars' - }, - fields: [ - 'id', 'name' - ] - }), - mode: 'remote', - triggerAction: 'all', - fieldLabel: _('mxcalendars.grid_col_calendar'), - name: 'calendarid', - hiddenName: 'calendarid', - id: 'ucalendarid', - allowBlank: false, - typeAhead:true, - minChars:1, - emptyText:_('mxcalendars.label_select_calendar'), - valueNotFoundText:_('mxcalendars.label_select_calendar_err'), - anchor:'100%', - value: config.record.calendarid - }*/,{ - xtype: 'checkbox' - ,fieldLabel: _('mxcalendars.category_isdefault_col_label') - ,name: 'isdefault' - },{ - xtype: 'textfield' - ,fieldLabel: _('mxcalendars.category_foregroundcss_col_label') - ,name: 'foregroundcss' - },{ - xtype: 'textfield' - ,fieldLabel: _('mxcalendars.category_backgroundcss_col_label') - ,name: 'backgroundcss' - },{ - xtype: 'textfield' - ,fieldLabel: _('mxcalendars.category_inlinecss_col_label') - ,name: 'inlinecss' - },{ - xtype: 'checkbox' - ,fieldLabel: _('mxcalendars.category_disabled_col_label') - ,name: 'disable' - ,checked: false - ,value: 1 - },{ - xtype: 'checkbox' - ,fieldLabel: _('mxcalendars.category_active_col_label') - ,name: 'active' - ,checked: true - ,value: 1 - }] + }, + fields: [ + { + xtype:'hidden', + name:'id' + }, + { + xtype: 'textfield', + fieldLabel:_('mxcalendars.category_name_col_label'), + name: 'name' + }, + /* + { + xtype: 'combo', + displayField: 'name', + valueField: 'id', + forceSelection: true, + store: new Ext.data.JsonStore({ + root: 'results', + idProperty: 'id', + url: mxcCore.config.connectorUrl, + baseParams: { + action: 'stores/getcalendars' + }, + fields: [ + 'id', 'name' + ] + }), + mode: 'remote', + triggerAction: 'all', + fieldLabel: _('mxcalendars.grid_col_calendar'), + name: 'calendarid', + hiddenName: 'calendarid', + id: 'ucalendarid', + allowBlank: false, + typeAhead:true, + minChars:1, + emptyText:_('mxcalendars.label_select_calendar'), + valueNotFoundText:_('mxcalendars.label_select_calendar_err'), + anchor:'100%', + value: config.record.calendarid + }*/ + { + xtype: 'checkbox', + fieldLabel: _('mxcalendars.category_isdefault_col_label'), + name: 'isdefault' + }, + { + xtype: 'textfield', + fieldLabel: _('mxcalendars.category_foregroundcss_col_label'), + name: 'foregroundcss' + }, + { + xtype: 'textfield', + fieldLabel: _('mxcalendars.category_backgroundcss_col_label'), + name: 'backgroundcss' + }, + { + xtype: 'textfield', + fieldLabel: _('mxcalendars.category_inlinecss_col_label'), + name: 'inlinecss' + }, + { + xtype: 'checkbox', + fieldLabel: _('mxcalendars.category_disabled_col_label'), + name: 'disable', + checked: false, + value: 1 + }, + { + xtype: 'checkbox', + fieldLabel: _('mxcalendars.category_active_col_label'), + name: 'active', + checked: true, + value: 1 + } + ] }); mxcCore.window.UpdateCat.superclass.constructor.call(this,config); }; @@ -208,74 +244,84 @@ Ext.reg('mxcalendars-window-category-update',mxcCore.window.UpdateCat); //-------------------------------------------// mxcCore.window.CreateCat = function(config) { config = config || {}; - Ext.applyIf(config,{ - title: ''+_('mxcalendars.label_window_create') - ,url: mxcCore.config.connectorUrl - ,width: 400 - ,baseParams: { + Ext.applyIf(config, + { + title: ''+_('mxcalendars.label_window_create'), + url: mxcCore.config.connectorUrl, + width: 400, + baseParams: { action: 'mgr/category/create' - } - ,fields: [{ - xtype: 'textfield' - ,fieldLabel:_('mxcalendars.category_name_col_label') - ,name: 'name' - }/*,{ - xtype: 'combo', - displayField: 'name', - valueField: 'id', - forceSelection: true, - store: new Ext.data.JsonStore({ - root: 'results', - idProperty: 'id', - url: mxcCore.config.connectorUrl, - baseParams: { - action: 'stores/getcalendars' - }, - fields: [ - 'id', 'name' - ] - }), - mode: 'remote', - triggerAction: 'all', - fieldLabel: _('mxcalendars.grid_col_calendar'), - name: 'calendarid', - hiddenName: 'calendarid', - id: 'calendarid', - allowBlank: false, - typeAhead:true, - minChars:1, - emptyText:_('mxcalendars.label_select_calendar'), - valueNotFoundText:_('mxcalendars.label_select_calendar_err'), - anchor:'100%' - }*/,{ - xtype: 'checkbox' - ,fieldLabel: _('mxcalendars.category_isdefault_col_label') - ,name: 'isdefault' - },{ - xtype: 'textfield' - ,fieldLabel: _('mxcalendars.category_foregroundcss_col_label') - ,name: 'foregroundcss' - },{ - xtype: 'textfield' - ,fieldLabel: _('mxcalendars.category_backgroundcss_col_label') - ,name: 'backgroundcss' - },{ - xtype: 'textfield' - ,fieldLabel: _('mxcalendars.category_inlinecss_col_label') - ,name: 'inlinecss' - },{ - xtype: 'checkbox' - ,fieldLabel: _('mxcalendars.category_disabled_col_label') - ,name: 'disable' - ,checked: false - ,value: 1 - },{ - xtype: 'checkbox' - ,fieldLabel: _('mxcalendars.category_active_col_label') - ,name: 'active' - ,checked: true - ,value: 1 - }] + }, + fields: [ + { + xtype: 'textfield', + fieldLabel:_('mxcalendars.category_name_col_label'), + name: 'name' + }, + /*{ + xtype: 'combo', + displayField: 'name', + valueField: 'id', + forceSelection: true, + store: new Ext.data.JsonStore({ + root: 'results', + idProperty: 'id', + url: mxcCore.config.connectorUrl, + baseParams: { + action: 'stores/getcalendars' + }, + fields: [ + 'id', 'name' + ] + }), + mode: 'remote', + triggerAction: 'all', + fieldLabel: _('mxcalendars.grid_col_calendar'), + name: 'calendarid', + hiddenName: 'calendarid', + id: 'calendarid', + allowBlank: false, + typeAhead:true, + minChars:1, + emptyText:_('mxcalendars.label_select_calendar'), + valueNotFoundText:_('mxcalendars.label_select_calendar_err'), + anchor:'100%' + }*/ + { + xtype: 'checkbox', + fieldLabel: _('mxcalendars.category_isdefault_col_label'), + name: 'isdefault' + }, + { + xtype: 'textfield', + fieldLabel: _('mxcalendars.category_foregroundcss_col_label'), + name: 'foregroundcss' + }, + { + xtype: 'textfield', + fieldLabel: _('mxcalendars.category_backgroundcss_col_label'), + name: 'backgroundcss' + }, + { + xtype: 'textfield', + fieldLabel: _('mxcalendars.category_inlinecss_col_label'), + name: 'inlinecss' + }, + { + xtype: 'checkbox', + fieldLabel: _('mxcalendars.category_disabled_col_label'), + name: 'disable', + checked: false, + value: 1 + }, + { + xtype: 'checkbox', + fieldLabel: _('mxcalendars.category_active_col_label'), + name: 'active', + checked: true, + value: 1 + } + ] }); mxcCore.window.CreateCat.superclass.constructor.call(this,config); }; diff --git a/assets/components/mxcalendars/js/mgr/widgets/mxcalendars.feed.grid.js b/assets/components/mxcalendars/js/mgr/widgets/mxcalendars.feed.grid.js index 62c5865..d49fa83 100644 --- a/assets/components/mxcalendars/js/mgr/widgets/mxcalendars.feed.grid.js +++ b/assets/components/mxcalendars/js/mgr/widgets/mxcalendars.feed.grid.js @@ -3,109 +3,118 @@ Ext.USE_NATIVE_JSON = false; mxcCore.grid.feeds = function(config) { config = config || {}; Ext.applyIf(config,{ - id: 'mxcalendars-grid-feeds' - ,url: mxcCore.config.connectorUrl - ,baseParams: { action: 'mgr/feed/getList' } - ,fields: ['id','feed','type','defaultcategoryid','timerint','timermeasurement',{name:'lastrunon', type: 'date', dateFormat:'timestamp'},{name:'nextrunon', type: 'date', dateFormat:'timestamp'},'active'] - ,paging: true - ,remoteSort: true - ,anchor: '97%' - ,autoExpandColumn: 'name' - ,save_action: 'mgr/feed/updatefromgrid' // Support the inline editing - ,autosave: true // Support the inline editing - ,columns: [{ - header: _('id') - ,dataIndex: 'id' - ,sortable: true - ,width: 5 + id: 'mxcalendars-grid-feeds', + url: mxcCore.config.connectorUrl, + baseParams: { action: 'mgr/feed/getList' }, + fields: ['id','feed','type','defaultcategoryid','timerint','timermeasurement',{name:'lastrunon', type: 'date', dateFormat:'timestamp'},{name:'nextrunon', type: 'date', dateFormat:'timestamp'},'active'], + paging: true, + remoteSort: true, + anchor: '97%', + autoExpandColumn: 'name', + save_action: 'mgr/feed/updatefromgrid', // Support the inline editing + autosave: true, // Support the inline editing + columns: [{ + header: _('id'), + dataIndex: 'id', + sortable: true, + width: 5 },{ - header: _('mxcalendars.feed_col_feed') - ,dataIndex: 'feed' - ,sortable: true - ,editor: { xtype: 'textfield' } + header: _('mxcalendars.feed_col_feed'), + dataIndex: 'feed', + sortable: true, + editor: { xtype: 'textfield' } },{ - header: _('mxcalendars.lastrunon_col_label') - ,dataIndex: 'lastrunon' - ,sortable: true - ,width:40 - , xtype : 'datecolumn' - ,format:mxcCore.config.mgr_dateformat+' '+mxcCore.config.mgr_timeformat - , editable:false - , editor:{xtype:'datefield', format:mxcCore.config.mgr_dateformat+' '+mxcCore.config.mgr_timeformat} + header: _('mxcalendars.lastrunon_col_label'), + dataIndex: 'lastrunon', + sortable: true, + width:40, + xtype : 'datecolumn', + format:mxcCore.config.mgr_dateformat + ' ' + mxcCore.config.mgr_timeformat, + editable:false, + editor:{xtype:'datefield', format:mxcCore.config.mgr_dateformat + ' ' + mxcCore.config.mgr_timeformat} },{ - header: _('mxcalendars.nextrunon_col_label') - ,dataIndex: 'nextrunon' - ,sortable: true - ,width:40 - , xtype : 'datecolumn' - ,format:mxcCore.config.mgr_dateformat+' '+mxcCore.config.mgr_timeformat - , editable:false - , editor:{xtype:'datefield', format:mxcCore.config.mgr_dateformat+' '+mxcCore.config.mgr_timeformat} + header: _('mxcalendars.nextrunon_col_label'), + dataIndex: 'nextrunon', + sortable: true, + width:40, + xtype : 'datecolumn', + format:mxcCore.config.mgr_dateformat + ' ' + mxcCore.config.mgr_timeformat, + editable:false, + editor:{xtype:'datefield', format:mxcCore.config.mgr_dateformat + ' ' + mxcCore.config.mgr_timeformat} },{ header: _('mxcalendars.feed_col_type'), dataIndex: 'type', sortable: true, width:15, - editor: { xtype: 'mxc-combo-feedtype', renderer: true, width:120 }} - ,{ - header: _('mxcalendars.label_default')+' '+_('mxcalendars.categoryid_col_label') - ,dataIndex: 'defaultcategoryid' - ,sortable: true - ,width:20 - ,editor: { xtype: 'mxc-combo-categories', renderer: true }} - ,{ - header: _('mxcalendars.feed_col_active') - ,dataIndex: 'active' - ,sortable: true - ,editor: { xtype: 'modx-combo-boolean', renderer: true } - ,width: 15 - }],tbar:[{ - xtype: 'textfield' - ,id: 'mxcalendars-search-feeds-filter' - ,emptyText:_('mxcalendars.default_feed_search') - ,listeners: { - 'change': {fn:this.search,scope:this} - ,'render': {fn: function(cmp) { - new Ext.KeyMap(cmp.getEl(), { - key: Ext.EventObject.ENTER - ,fn: function() { - this.fireEvent('change',this); - this.blur(); - return true; - } - ,scope: cmp - }); - },scope:this} + editor: { xtype: 'mxc-combo-feedtype', renderer: true, width:120 } + },{ + header: _('mxcalendars.label_default') + ' ' + _('mxcalendars.categoryid_col_label'), + dataIndex: 'defaultcategoryid', + sortable: true, + width:20, + editor: { xtype: 'mxc-combo-categories', renderer: true } + },{ + header: _('mxcalendars.feed_col_active'), + dataIndex: 'active', + sortable: true, + editor: { xtype: 'modx-combo-boolean', renderer: true }, + width: 15 + }], + tbar:[{ + xtype: 'textfield', + id: 'mxcalendars-search-feeds-filter', + emptyText:_('mxcalendars.default_feed_search'), + listeners: { + 'change': {fn:this.search,scope:this}, + 'render': { + fn: function(cmp) { + new Ext.KeyMap(cmp.getEl(), { + key: Ext.EventObject.ENTER, + fn: function() { + this.fireEvent('change', this); + this.blur(); + return true; + }, + scope: cmp + }); + }, + scope:this } + } },'->',{ - text:_('mxcalendars.feed_btn_create') - ,handler: { xtype: 'mxcalendars-window-feed-create' ,blankValues: true } + text:_('mxcalendars.feed_btn_create'), + handler: { + xtype: 'mxcalendars-window-feed-create', + blankValues: true + } }] }); - mxcCore.grid.feeds.superclass.constructor.call(this,config) + mxcCore.grid.feeds.superclass.constructor.call(this,config); }; Ext.extend(mxcCore.grid.feeds,MODx.grid.Grid,{ - search: function(tf,nv,ov) {textfield - var s = this.getStore(); + search: function(tf,nv,ov) { + let s = this.getStore(); s.baseParams.query = tf.getValue(); this.getBottomToolbar().changePage(1); this.refresh(); - },getMenu: function() { - var m = [{ - text: _('mxcalendars.feed_menu_update') - ,handler: this.update + }, + getMenu: function() { + let m = [{ + text: _('mxcalendars.feed_menu_update'), + handler: this.update },'-',{ - text: _('mxcalendars.feed_menu_remove') - ,handler: this.remove + text: _('mxcalendars.feed_menu_remove'), + handler: this.remove }]; this.addContextMenuItem(m); return true; - },update: function(btn,e) { + }, + update: function(btn,e) { if (!this.updateWindow) { this.updateWindow = MODx.load({ - xtype: 'mxcalendars-window-feed-update' - ,record: this.menu.record - ,listeners: { + xtype: 'mxcalendars-window-feed-update', + record: this.menu.record, + listeners: { 'success': {fn:this.refresh,scope:this} } }); @@ -113,16 +122,17 @@ Ext.extend(mxcCore.grid.feeds,MODx.grid.Grid,{ this.updateWindow.setValues(this.menu.record); } this.updateWindow.show(e.target); - },remove: function() { + }, + remove: function() { MODx.msg.confirm({ - title: _('mxcalendars.feed_remove_title') - ,text: _('mxcalendars.feed_remove_confirm') - ,url: this.config.url - ,params: { - action: 'mgr/feed/remove' - ,id: this.menu.record.id - } - ,listeners: { + title: _('mxcalendars.feed_remove_title'), + text: _('mxcalendars.feed_remove_confirm'), + url: this.config.url, + params: { + action: 'mgr/feed/remove', + id: this.menu.record.id + }, + listeners: { 'success': {fn:this.refresh,scope:this} } }); @@ -137,71 +147,77 @@ Ext.reg('mxcalendars-grid-feeds',mxcCore.grid.feeds); mxcCore.window.UpdateFeed = function(config) { config = config || {}; Ext.applyIf(config,{ - title: _('mxcalendars.feed_menu_update') - ,url: mxcCore.config.connectorUrl - ,width: 400 - ,baseParams: { + title: _('mxcalendars.feed_menu_update'), + url: mxcCore.config.connectorUrl, + width: 400, + baseParams: { action: 'mgr/feed/update' - } - ,fields: [{xtype:'hidden',name:'id'},{ - xtype: 'textfield' - ,fieldLabel:_('mxcalendars.feed_col_feed') - ,name: 'feed' - }, - { - xtype: 'mxc-combo-categories', - fieldLabel: _('mxcalendars.label_default')+' '+_('mxcalendars.categoryid_col_label'), - name: 'defaultcategoryid', - allowBlank: false, - triggerAction: 'all', - typeAhead: true, - mode: 'remote', - width:120, - listWidth: 120, - hiddenName: 'defaultcategoryid' - }, - { - xtype : 'numberfield', - fieldLabel : _('mxcalendars.label_feedmeasurementtime'), - name : 'timerint', - allowBlank : true, - emptyText : '0', - allowDecimals : false, - minValue : 0, - maxValue : 3600, - hiddenName: 'timerint' }, - { - xtype: 'mxc-combo-measurementtype', - fieldLabel: _('mxcalendars.label_feedmeasurementtype'), - name: 'timermeasurement', - allowBlank: true, - triggerAction: 'all', - typeAhead: true, - mode: 'remote', - width:120, - listWidth: 120, - hiddenName: 'timermeasurement' - }, - { - xtype: 'mxc-combo-feedtype', - fieldLabel: _('mxcalendars.feed_col_type'), - name: 'type', - allowBlank: false, - triggerAction: 'all', - typeAhead: true, - mode: 'local', - width:120, - listWidth: 120, - hiddenName: 'type' - } - ,{ - xtype: 'checkbox' - ,fieldLabel: _('mxcalendars.feed_col_active') - ,name: 'active' - ,checked: true - ,value: 1 - }] + fields: [ + { + xtype:'hidden', + name:'id' + }, + { + xtype: 'textfield', + fieldLabel:_('mxcalendars.feed_col_feed'), + name: 'feed' + }, + { + xtype: 'mxc-combo-categories', + fieldLabel: _('mxcalendars.label_default') + ' ' + _('mxcalendars.categoryid_col_label'), + name: 'defaultcategoryid', + allowBlank: true, + triggerAction: 'all', + typeAhead: true, + mode: 'remote', + width:120, + listWidth: 120, + hiddenName: 'defaultcategoryid' + }, + { + xtype: 'numberfield', + fieldLabel: _('mxcalendars.label_feedmeasurementtime'), + name: 'timerint', + allowBlank: true, + emptyText: '0', + allowDecimals: false, + minValue: 0, + maxValue: 3600, + hiddenName: 'timerint' + }, + { + xtype: 'mxc-combo-measurementtype', + fieldLabel: _('mxcalendars.label_feedmeasurementtype'), + name: 'timermeasurement', + allowBlank: true, + triggerAction: 'all', + typeAhead: true, + mode: 'remote', + width:120, + listWidth: 120, + hiddenName: 'timermeasurement' + }, + { + xtype: 'mxc-combo-feedtype', + fieldLabel: _('mxcalendars.feed_col_type'), + name: 'type', + allowBlank: true, + triggerAction: 'all', + typeAhead: true, + mode: 'local', + width:120, + listWidth: 120, + hiddenName: 'type' + }, + { + xtype: 'checkbox', + fieldLabel: _('mxcalendars.feed_col_active'), + name: 'active', + checked: true, + value: 1 + } + ] }); mxcCore.window.UpdateFeed.superclass.constructor.call(this,config); }; @@ -215,22 +231,22 @@ Ext.reg('mxcalendars-window-feed-update',mxcCore.window.UpdateFeed); mxcCore.window.CreateFeed = function(config) { config = config || {}; Ext.applyIf(config,{ - title: _('mxcalendars.feed_btn_create') - ,url: mxcCore.config.connectorUrl - ,width: 400 - ,baseParams: { + title: _('mxcalendars.feed_btn_create'), + url: mxcCore.config.connectorUrl, + width: 400, + baseParams: { action: 'mgr/feed/create' - } - ,fields: [{ - xtype: 'textfield' - ,fieldLabel:_('mxcalendars.feed_col_feed') - ,name: 'feed' + }, + fields: [{ + xtype: 'textfield', + fieldLabel:_('mxcalendars.feed_col_feed'), + name: 'feed' }, { xtype: 'mxc-combo-categories', fieldLabel: _('mxcalendars.label_default')+' '+_('mxcalendars.categoryid_col_label'), name: 'defaultcategoryid', - allowBlank: false, + allowBlank: true, triggerAction: 'all', typeAhead: true, mode: 'remote', @@ -265,7 +281,7 @@ mxcCore.window.CreateFeed = function(config) { xtype: 'mxc-combo-feedtype', fieldLabel: _('mxcalendars.feed_col_type'), name: 'type', - allowBlank: false, + allowBlank: true, editable: false, triggerAction: 'all', typeAhead: true, @@ -274,13 +290,13 @@ mxcCore.window.CreateFeed = function(config) { listWidth: 120, hiddenName: 'type', - } - ,{ - xtype: 'checkbox' - ,fieldLabel: _('mxcalendars.feed_col_active') - ,name: 'active' - ,checked: true - ,value: 1 + }, + { + xtype: 'checkbox', + fieldLabel: _('mxcalendars.feed_col_active'), + name: 'active', + checked: true, + value: 1 }] }); mxcCore.window.CreateFeed.superclass.constructor.call(this,config); diff --git a/assets/components/mxcalendars/js/mgr/widgets/mxcalendars.grid.js b/assets/components/mxcalendars/js/mgr/widgets/mxcalendars.grid.js index 6f7ae8c..d3cb125 100644 --- a/assets/components/mxcalendars/js/mgr/widgets/mxcalendars.grid.js +++ b/assets/components/mxcalendars/js/mgr/widgets/mxcalendars.grid.js @@ -1,1523 +1,2006 @@ -mxcCore.grid.events = function(config) { +mxcCore.grid.events = function (config) { config = config || {}; - Ext.applyIf(config,{ - id: 'mxcalendars-grid-events' - ,url: mxcCore.config.connectorUrl - ,baseParams: {action: 'mgr/events/getList'} - ,fields: ['id','description','content','title','context','calendar_id','form_chunk','categoryid','source','feeds_id','feeds_uid',{name:'startdate', type: 'date', dateFormat:'timestamp'},'startdate_date','startdate_time',{name:'enddate', type: 'date', dateFormat:'timestamp'},'enddate_date','enddate_time','repeating','repeattype','repeaton','repeatfrequency',{name:'repeatenddate', type: 'date', dateFormat:'timestamp'},'repeatdates','menu','name','map','link','linkrel','linktarget','location_name','location_address','address','active','catfriendly','allday'] - ,paging: true - ,remoteSort: true - ,anchor: '97%' - ,autoExpandColumn: 'name' - ,save_action: 'mgr/events/updatefromgrid' // Support the inline editing - ,autosave: true // Support the inline editing - ,columns: [ - // add the grid columns to the display - {header: _('id'),dataIndex: 'id',sortable: true,width:40} - ,{header: _('mxcalendars.source'),dataIndex: 'source',sortable: true,width:50} - ,{header: _('mxcalendars.name'),dataIndex: 'title',sortable: true,width:110,editor: {xtype: 'textfield'}} - ,{header: _('mxcalendars.grid_col_context'), dataIndex:'context',editor: { xtype: 'mxc-combo-context', renderer: true }} - ,{header: _('mxcalendars.grid_col_calendar'), dataIndex:'calendar_id',editor: { xtype: 'mxc-combo-calendar', renderer: true }} - ,{header: _('mxcalendars.categoryid_col_label'),dataIndex: 'catfriendly',sortable: true,width:80} - //,{header: _('mxcalendars.startdate_col_label'),dataIndex: 'startdate',sortable: true} - ,{header: _('mxcalendars.startdate_col_label'),dataIndex: 'startdate',sortable: true,width:60, xtype : 'datecolumn',format:mxcCore.config.mgr_dateformat, editable:false, editor:{xtype:'datefield', format:mxcCore.config.mgr_dateformat}} - ,{header: _('mxcalendars.starttime_col_label'), dataIndex: 'startdate_time', sortable:false,width:60, editor:{ xtype:'timefield', format: mxcCore.config.mgr_timeformat}} - ,{header: _('mxcalendars.enddate_col_label'),dataIndex: 'enddate',sortable: true,width:60, xtype : 'datecolumn',format:mxcCore.config.mgr_dateformat, editable:false, editor:{xtype:'datefield',format:mxcCore.config.mgr_dateformat}} - ,{header: _('mxcalendars.endtime_col_label'),dataIndex: 'enddate_time',sortable: false,width:60, editor:{ xtype:'timefield', format: mxcCore.config.mgr_timeformat}} - ,{header: _('mxcalendars.repeating_col_label'),dataIndex: 'repeating',sortable: true,width:30} - ,{header: _('mxcalendars.repeating_last_occ_col_label'),dataIndex: 'repeatenddate', sortable: true,width:60, xtype : 'datecolumn',format:mxcCore.config.mgr_dateformat} - ,{header: _('mxcalendars.category_active_col_label'),dataIndex: 'active', sortable: true,width:30,editor: { xtype: 'modx-combo-boolean', renderer: true}} - ,{hidden:true, header: _('mxcalendars.label_content'), dataIndex:'content'} - ,{hidden:true, header: _('mxcalendars.label_forms'), dataIndex:'form_chunk'} - ,{hidden:true, header: _('mxcalendars.label_repeating_event'), dataIndex:'repeating'} - ,{hidden:true, header: _('mxcalendars.label_repeat_type'), dataIndex:'repeattype'} - ,{hidden:true, header: _('mxcalendars.label_repeaton'), dataIndex:'repeaton'} - ,{hidden:true, header: _('mxcalendars.label_repeat_frequency'), dataIndex:'repeatfrequency'} - ,{hidden:true, header: _('mxcalendars.label_display_map'), dataIndex:'map'} - ,{hidden:true, header: _('mxcalendars.label_link'), dataIndex:'link'} - ,{hidden:true, header: _('mxcalendars.label_link_rel'), dataIndex:'linkrel'} - ,{hidden:true, header: _('mxcalendars.label_link_target'), dataIndex:'linktarget'} - ,{hidden:true, header: _('mxcalendars.label_location')+' '+_('mxcalendars.label_name'), dataIndex:'location_name'} - ,{hidden:true, header: _('mxcalendars.label_address'), dataIndex:'location_address'} - ,{hidden:true, header: _('mxcalendars.label_location')+' '+_('mxcalendars.label_address'), dataIndex:'address'} - ,{hidden:true, header: _('mxcalendars.label_allday'), dataIndex:'allday',editable:false,editor: { xtype: 'modx-combo-boolean', renderer: true}} - ],tbar:[{ - xtype: 'textfield' - ,id: 'mxcalendars-search-filter' - ,emptyText:_('mxcalendars.search_default_text') - ,listeners: { - 'change': {fn:this.search,scope:this} - ,'render': {fn: function(cmp) { - new Ext.KeyMap(cmp.getEl(), { - key: Ext.EventObject.ENTER - ,fn: function() { - this.fireEvent('change',this); - this.blur(); - return true; - } - ,scope: cmp - }); - },scope:this} - } - },'->',{ - text:_('mxcalendars.btn_show_past_events') - ,id:'pastbnt' - ,visible:true - ,handler: function(){ - var s = this.getStore(); - s.baseParams.historical = 1; - this.getBottomToolbar().changePage(1); - this.refresh(); - Ext.getCmp('pastbnt').hide(); - Ext.getCmp('futurebnt').show(); + Ext.applyIf(config, { + id: 'mxcalendars-grid-events', + url: mxcCore.config.connectorUrl, + baseParams: {action: 'mgr/events/getList'}, + fields: [ + 'id', + 'description', + 'content', + 'title', + 'context', + 'calendar_id', + 'form_chunk', + 'categoryid', + 'source', + 'feeds_id', + 'feeds_uid', + { + name: 'startdate', + type: 'date', + dateFormat: 'timestamp' + }, + 'startdate_date', + 'startdate_time', + { + name: 'enddate', + type: 'date', + dateFormat: 'timestamp' + }, + 'enddate_date', + 'enddate_time', + 'repeating', + 'repeattype', + 'repeaton', + 'repeatfrequency', + { + name: 'repeatenddate', + type: 'date', + dateFormat: 'timestamp' + }, + 'repeatdates', + 'menu', 'name', + 'map', + 'link', + //'linkrel', + 'linktarget', + 'location_name', + 'location_address', + 'address', + 'price', + 'food', + 'age', + 'capacity', + 'active', + 'catfriendly', + 'allday' + ], + paging: true, + remoteSort: true, + anchor: '97%', + autoExpandColumn: 'name', + save_action: 'mgr/events/updatefromgrid', // Support the inline editing + autosave: true, // Support the inline editing + columns: [ + // add the grid columns to the display + { + header: _('id'), + dataIndex: 'id', + sortable: true, + width: 40 + }, + { + header: _('mxcalendars.source'), + dataIndex: 'source', + sortable: true, + width: 50 + }, + { + header: _('mxcalendars.name'), + dataIndex: 'title', + sortable: true, + width: 110, + msgTarget:'under', + editor: {xtype: 'textfield'} + }, + { + header: _('mxcalendars.grid_col_context'), + dataIndex: 'context', + editor: {xtype: 'mxc-combo-context', renderer: true} + }, + { + header: _('mxcalendars.grid_col_calendar'), + dataIndex: 'calendar_id', + editor: {xtype: 'mxc-combo-calendar', renderer: true} + }, + { + header: _('mxcalendars.categoryid_col_label'), + dataIndex: 'catfriendly', + sortable: true, + width: 80 + }, + // { + // header: _('mxcalendars.startdate_col_label'), + // dataIndex: 'startdate', + // sortable: true + // }, + { + header: _('mxcalendars.startdate_col_label'), + dataIndex: 'startdate', + sortable: true, + width: 60, + xtype: 'datecolumn', + format: mxcCore.config.mgr_dateformat, + editable: true, + editor: {xtype: 'datefield', format: mxcCore.config.mgr_dateformat} + }, + { + header: _('mxcalendars.starttime_col_label'), + dataIndex: 'startdate_time', + sortable: false, + width: 60, + editable: true, + editor: {xtype: 'timefield', format: mxcCore.config.mgr_timeformat} + }, + { + header: _('mxcalendars.enddate_col_label'), + dataIndex: 'enddate', + sortable: true, + width: 60, + xtype: 'datecolumn', + format: mxcCore.config.mgr_dateformat, + editable: true, + editor: {xtype: 'datefield', format: mxcCore.config.mgr_dateformat} + }, + { + header: _('mxcalendars.endtime_col_label'), + dataIndex: 'enddate_time', + sortable: false, + width: 60, + editable: true, + editor: {xtype: 'timefield', format: mxcCore.config.mgr_timeformat} + }, + { + header: _('mxcalendars.repeating_col_label'), dataIndex: 'repeating', sortable: true, width: 30 + }, + { + header: _('mxcalendars.repeating_last_occ_col_label'), + dataIndex: 'repeatenddate', + sortable: true, + width: 60, + xtype: 'datecolumn', + format: mxcCore.config.mgr_dateformat, + editable: true, + editor: {xtype: 'datefield', format: mxcCore.config.mgr_dateformat} + }, + { + header: _('mxcalendars.category_active_col_label'), + dataIndex: 'active', + sortable: true, + width: 30, + editor: {xtype: 'modx-combo-boolean', renderer: true} + }, + { + hidden: true, + header: _('mxcalendars.label_content'), + dataIndex: 'content' + }, + { + hidden: true, + header: _('mxcalendars.label_forms'), + dataIndex: 'form_chunk' + }, + { + hidden: true, + header: _('mxcalendars.label_repeating_event'), + dataIndex: 'repeating' + }, + { + hidden: true, + header: _('mxcalendars.label_repeat_type'), + dataIndex: 'repeattype' + }, + { + hidden: true, + header: _('mxcalendars.label_repeaton'), + dataIndex: 'repeaton' + }, + { + hidden: true, + header: _('mxcalendars.label_repeat_frequency'), + dataIndex: 'repeatfrequency' + }, + { + hidden: true, + header: _('mxcalendars.label_display_map'), + dataIndex: 'map' + }, + { + hidden: true, + header: _('mxcalendars.label_link'), + dataIndex: 'link' + }, + // { + // hidden: true, + // header: _('mxcalendars.label_link_rel'), + // dataIndex: 'linkrel' + // }, + { + hidden: true, + header: _('mxcalendars.label_link_target'), + dataIndex: 'linktarget' + }, + { + hidden: true, + header: _('mxcalendars.label_location') + ' ' + _('mxcalendars.label_name'), + dataIndex: 'location_name' + }, + { + hidden: true, + header: _('mxcalendars.label_address'), + dataIndex: 'location_address' + }, + { + hidden: true, + header: _('mxcalendars.label_location') + ' ' + _('mxcalendars.label_address'), + dataIndex: 'address' + }, + { + hidden: true, + header: _('mxcalendars.label_price') + ' ' + _('mxcalendars.label_price'), + dataIndex: 'price' + }, + { + hidden: true, + header: _('mxcalendars.label_food') + ' ' + _('mxcalendars.label_food'), + dataIndex: 'food' + }, + { + hidden: true, + header: _('mxcalendars.label_age') + ' ' + _('mxcalendars.label_age'), + dataIndex: 'age' + }, + { + hidden: true, + header: _('mxcalendars.label_capacity') + ' ' + _('mxcalendars.label_capacity'), + dataIndex: 'capacity' + }, + { + hidden: true, + header: _('mxcalendars.label_allday'), + dataIndex: 'allday', + editable: false, + editor: {xtype: 'modx-combo-boolean', renderer: true} + } + ], + tbar: [ + { + xtype: 'textfield', + id: 'mxcalendars-search-filter', + emptyText: _('mxcalendars.search_default_text'), + listeners: { + 'change': {fn: this.search, scope: this}, + 'render': { + fn: function (cmp) { + new Ext.KeyMap(cmp.getEl(), { + key: Ext.EventObject.ENTER, + fn: function () { + this.fireEvent('change', this); + this.blur(); + return true; + }, scope: cmp + }); + }, scope: this } - },{ - text:_('mxcalendars.btn_show_upcoming_events') - ,id:'futurebnt' - ,hidden:true - ,handler: function(){ - var s = this.getStore(); - s.baseParams.historical = 0; - this.getBottomToolbar().changePage(1); - this.refresh(); - Ext.getCmp('futurebnt').hide(); - Ext.getCmp('pastbnt').show(); - } - },'-',{ - text:_('mxcalendars.btn_create') - ,handler:this.createCal - }] + } + }, '->', { + text: _('mxcalendars.btn_show_past_events'), + id: 'pastbnt', + visible: true, + handler: function () { + let s = this.getStore(); + s.baseParams.historical = 1; + this.getBottomToolbar().changePage(1); + this.refresh(); + Ext.getCmp('pastbnt').hide(); + Ext.getCmp('futurebnt').show(); + } + }, + { + text: _('mxcalendars.btn_show_upcoming_events'), + id: 'futurebnt', + hidden: true, + handler: function () { + let s = this.getStore(); + s.baseParams.historical = 0; + this.getBottomToolbar().changePage(1); + this.refresh(); + Ext.getCmp('futurebnt').hide(); + Ext.getCmp('pastbnt').show(); + } + }, '-', { + text: _('mxcalendars.btn_create'), + handler: this.createCal + } + ] }); - mxcCore.grid.events.superclass.constructor.call(this,config) + mxcCore.grid.events.superclass.constructor.call(this, config); }; -Ext.extend(mxcCore.grid.events,MODx.grid.Grid,{ - search: function(tf,nv,ov) { - var s = this.getStore(); +Ext.extend(mxcCore.grid.events, MODx.grid.Grid, { + search: function (tf, nv, ov) { + let s = this.getStore(); s.baseParams.query = tf.getValue(); this.getBottomToolbar().changePage(1); this.refresh(); - },getMenu: function() { - var m = [{ - text: _('mxcalendars.event_title_update') - ,handler: this.updateCal - },'-',{ - text: _('mxcalendars.event_title_duplicate') - ,handler: this.duplicateEvent - },'-',{ - text: _('mxcalendars.event_title_remove') - ,handler: this.removeCal - }]; - this.addContextMenuItem(m); - return true; - },createCal: function(btn,e) { - mxcCore.eventId = 0; - if (this.createCalWindow) { - this.createCalWindow.close(); - } - this.createCalWindow = MODx.load({ - xtype: 'mxcalendars-window-mxcalendar-create' - ,record: {'repeaton':''} - }); - - this.createCalWindow.show(e.target); - //this.createCalWindow.center(); - },updateCal: function(btn,e) { - mxcCore.eventId = this.menu.record.id; - if (this.updateCalWindow) { - this.updateCalWindow.close(); - } - this.updateCalWindow = MODx.load({ - xtype: 'mxcalendars-window-mxcalendar-update' - ,record: this.menu.record - ,listeners: { - 'success': {fn:this.refresh,scope:this} - } - }); - - this.updateCalWindow.show(e.target); - //this.updateCalWindow.center(); - },removeCal: function() { - MODx.msg.confirm({ - title: _('mxcalendars.mxcalendars_remove') - ,text: _('mxcalendars.mxcalendars_remove_confirm') - ,url: this.config.url - ,params: { - action: 'mgr/events/remove' - ,id: this.menu.record.id - } - ,listeners: { - 'success': {fn:this.refresh,scope:this} - } - }); - },duplicateEvent:function(btn,e){ - if (this.createCalWindow) { - this.createCalWindow.close(); - } - cloneRec = this.menu.record; - cloneRec.title = '('+_('mxcalendars.label_duplicate')+') '+cloneRec.title; - this.createCalWindow = MODx.load({ - xtype: 'mxcalendars-window-mxcalendar-create' - ,record: cloneRec - }); - this.createCalWindow.show(e.target); + }, + getMenu: function () { + let m = [ + { + text: _('mxcalendars.event_title_update'), + handler: this.updateCal + }, '-', { + text: _('mxcalendars.event_title_duplicate'), + handler: this.duplicateEvent + }, '-', { + text: _('mxcalendars.event_title_remove'), + handler: this.removeCal + } + ]; + this.addContextMenuItem(m); + return true; + }, + createCal: function (btn, e) { + mxcCore.eventId = 0; + if (this.createCalWindow) { + this.createCalWindow.close(); + } + this.createCalWindow = MODx.load({ + xtype: 'mxcalendars-window-mxcalendar-create', + record: {'repeaton': ''} + }); + + this.createCalWindow.show(e.target); + //this.createCalWindow.center(); + }, + updateCal: function (btn, e) { + mxcCore.eventId = this.menu.record.id; + if (this.updateCalWindow) { + this.updateCalWindow.close(); } + this.updateCalWindow = MODx.load({ + xtype: 'mxcalendars-window-mxcalendar-update', + record: this.menu.record, + listeners: { + 'success': {fn: this.refresh, scope: this} + } + }); + this.updateCalWindow.show(e.target); + //this.updateCalWindow.center(); + }, + removeCal: function () { + MODx.msg.confirm({ + title: _('mxcalendars.mxcalendars_remove'), + text: _('mxcalendars.mxcalendars_remove_confirm'), + url: this.config.url, + params: { + action: 'mgr/events/remove', + id: this.menu.record.id + }, + listeners: { + 'success': {fn: this.refresh, scope: this} + } + }); + }, + duplicateEvent: function (btn, e) { + if (this.createCalWindow) { + this.createCalWindow.close(); + } + let cloneRec = this.menu.record; + cloneRec.title = '(' + _('mxcalendars.label_duplicate') + ') ' + cloneRec.title; + this.createCalWindow = MODx.load({ + xtype: 'mxcalendars-window-mxcalendar-create', + record: cloneRec + }); + this.createCalWindow.show(e.target); + } }); -Ext.reg('mxcalendars-grid-events',mxcCore.grid.events); +Ext.reg('mxcalendars-grid-events', mxcCore.grid.events); -mxcCore.window.CreateCal = function(config) { +mxcCore.window.CreateCal = function (config) { config = config || {}; - Ext.applyIf(config,{ - title: _('mxcalendars.event_title_create') - ,autoHeight: false - ,height: Ext.getBody().getViewSize().height*.85 - ,autoScroll: true - ,id: 'CreateCal' - ,url: mxcCore.config.connectorUrl - ,width: 870 - ,baseParams: { + Ext.applyIf(config, { + title: _('mxcalendars.event_title_create'), + autoHeight: false, + height: Ext.getBody().getViewSize().height * 0.85, + autoScroll: true, + id: 'CreateCal', + url: mxcCore.config.connectorUrl, + width: 870, + baseParams: { action: 'mgr/events/create' - } - ,closeAction: 'hide' - ,border: false - ,bodyStyle: 'padding:15px' - ,plain:true - ,fieldDefaults: { + }, + closeAction: 'hide', + border: false, + bodyStyle: 'padding:15px', + plain: true, + fieldDefaults: { //msgTarget: 'side' - } - ,defaults: { - // applied to each contained item - // nothing this time - anchor:'100%' - ,layout: 'Form' - ,labelWidth: '100' - ,cellCls: 'valign-center' - } - ,items: - [{ - xtype: 'container', - anchor: '0', - layout: 'column', - defaultType: 'container', - defaults: { - layout:'form', - defaultType: 'textfield', - labelAlign: 'left', - anchor: '0' - //,msgTarget: 'side' - }, - items: [ - { - // Left Column - columnWidth: .5, - items: [{ - xtype: 'combo', - displayField: 'key', - valueField: 'key', - forceSelection: true, - store: new Ext.data.JsonStore({ - root: 'results', - idProperty: 'key', - url: mxcCore.config.connectorUrl, - baseParams: { - action: 'stores/getcontexts' - }, - fields: [ - 'key', - ] - }), - mode: 'remote', - triggerAction: 'all', - fieldLabel: _('mxcalendars.grid_col_context'), - name: 'context', - hiddenName: 'context', - id: 'ccontext', - allowBlank: mxcCore.config.isAdministrator ? true : false, - typeAhead:true, - minChars:1, - emptyText:_('mxcalendars.label_select_context'), - valueNotFoundText:_('mxcalendars.label_select_context_err'), - anchor:'100%', - value: config.record.context - },{ - fieldLabel: _('mxcalendars.label_title'), - name: 'title', - hiddenname: 'title', - id: 'ctitle', - allowBlank: false, - anchor:'100%', - value: config.record.title - },{ - xtype: 'superboxselect', - displayField: 'name', - valueField: 'id', - forceSelection: true, - store: new Ext.data.JsonStore({ - root: 'results', - idProperty: 'id', - url: mxcCore.config.connectorUrl, - baseParams: { - action: 'stores/getcategories' - }, - fields: [ - 'id', 'name' - ] - }), - mode: 'remote', - triggerAction: 'all', - fieldLabel: _('mxcalendars.grid_col_category'), - name: 'categoryid', - hiddenName: 'categoryid', - id: 'ccategoryid', - allowBlank: mxcCore.config.category_required ? true : false, - typeAhead:true, - minChars:1, - emptyText:_('mxcalendars.label_select_category'), - valueNotFoundText:_('mxcalendars.label_select_category_err'), - anchor:'100%', - value: config.record.categoryid - }] - },{ - // Right Column - columnWidth: .5, - items: [{ - xtype: 'combo', - displayField: 'name', - valueField: 'id', - forceSelection: true, - store: new Ext.data.JsonStore({ - root: 'results', - idProperty: 'id', - url: mxcCore.config.connectorUrl, - baseParams: { - action: 'stores/getcalendars' - }, - fields: [ - 'id', 'name' - ] - }), - mode: 'remote', - triggerAction: 'all', - fieldLabel: _('mxcalendars.grid_col_calendar'), - name: 'calendar_id', - hiddenName: 'calendar_id', - id: 'ccalendar_id', - allowBlank: true, - typeAhead:true, - minChars:1, - emptyText:_('mxcalendars.label_select_calendar'), - valueNotFoundText:_('mxcalendars.label_select_category_err'), - anchor:'100%', - value: config.record.calendar_id - },{ - xtype: 'container', - labelWidth: '250', - //boxLabel: _('mxcalendars.label_allday'), - combineErrors: true, - msgTarget : 'side', - layout: 'hbox', - defaults: { - flex: 1, - hideLabel: true + }, + defaults: { + // applied to each contained item + // nothing this time + anchor: '100%', + layout: 'Form', + labelWidth: '100', + cellCls: 'valign-center' + }, + items: [ + { + xtype: 'container', + anchor: '0', + layout: 'column', + defaultType: 'container', + defaults: { + layout: 'form', + defaultType: 'textfield', + labelAlign: 'left', + anchor: '0' + //,msgTarget: 'side' + }, + items: [ + { + // Left Column + columnWidth: 0.5, + items: [ + { + xtype: 'combo', + displayField: 'key', + valueField: 'key', + forceSelection: true, + store: new Ext.data.JsonStore({ + root: 'results', + idProperty: 'key', + url: mxcCore.config.connectorUrl, + baseParams: { + action: 'stores/getcontexts' + }, + fields: [ + 'key', + ] + }), + mode: 'remote', + triggerAction: 'all', + fieldLabel: _('mxcalendars.grid_col_context'), + name: 'context', + hiddenName: 'context', + id: 'ccontext', + allowBlank: mxcCore.config.isAdministrator ? true : false, + typeAhead: true, + minChars: 1, + emptyText: _('mxcalendars.label_select_context'), + valueNotFoundText: _('mxcalendars.label_select_context_err'), + anchor: '100%', + value: config.record.context + }, { + fieldLabel: _('mxcalendars.label_title'), + name: 'title', + hiddenname: 'title', + id: 'ctitle', + allowBlank: false, + anchor: '100%', + value: config.record.title + }, { + xtype: 'superboxselect', + displayField: 'name', + valueField: 'id', + forceSelection: true, + store: new Ext.data.JsonStore({ + root: 'results', + idProperty: 'id', + url: mxcCore.config.connectorUrl, + baseParams: { + action: 'stores/getcategories' + }, + fields: [ + 'id', 'name' + ] + }), + mode: 'remote', + triggerAction: 'all', + fieldLabel: _('mxcalendars.grid_col_category'), + name: 'categoryid', + hiddenName: 'categoryid', + id: 'ccategoryid', + allowBlank: mxcCore.config.category_required ? true : false, + typeAhead: true, + minChars: 1, + emptyText: _('mxcalendars.label_select_category'), + valueNotFoundText: _('mxcalendars.label_select_category_err'), + anchor: '100%', + value: config.record.categoryid + } + ] + }, { + // Right Column + columnWidth: 0.5, + items: [{ + xtype: 'combo', + displayField: 'name', + valueField: 'id', + forceSelection: true, + store: new Ext.data.JsonStore({ + root: 'results', + idProperty: 'id', + url: mxcCore.config.connectorUrl, + baseParams: { + action: 'stores/getcalendars' }, - items: [ - {boxLabel: _('mxcalendars.label_allday') - ,name:'allday' - ,id:'callday' - ,xtype:'checkbox' - ,checked: config.record.allday ? true : false - ,listeners:{check:{fn:function(tht, value) { + fields: [ + 'id', 'name' + ] + }), + mode: 'remote', + triggerAction: 'all', + fieldLabel: _('mxcalendars.grid_col_calendar'), + name: 'calendar_id', + hiddenName: 'calendar_id', + id: 'ccalendar_id', + allowBlank: true, + typeAhead: true, + minChars: 1, + emptyText: _('mxcalendars.label_select_calendar'), + valueNotFoundText: _('mxcalendars.label_select_category_err'), + anchor: '100%', + value: config.record.calendar_id + }, { + xtype: 'container', + labelWidth: '250', + //boxLabel: _('mxcalendars.label_allday'), + combineErrors: true, + msgTarget: 'side', + layout: 'hbox', + defaults: { + flex: 1, + hideLabel: true + }, + items: [ + { + boxLabel: _('mxcalendars.label_allday'), + name: 'allday', + id: 'callday', + xtype: 'checkbox', + checked: config.record.allday ? true : false, + listeners: { + check: { + fn: function (tht, value) { - var calldayFlag = Ext.getCmp('callday'); - - var edt = Ext.getCmp('cenddate_time'); - var sdt = Ext.getCmp('cstartdate_time'); - var ed = Ext.getCmp('cenddate_date'); - var sd = Ext.getCmp('cstartdate_date'); - - //Ext.getCmp('cstartdate_fields').label.update(_('mxcalendars.startdate_col_label')); - - if(calldayFlag.getValue() === true){ + let calldayFlag = Ext.getCmp('callday'); + let edt = Ext.getCmp('cenddate_time'); + let sdt = Ext.getCmp('cstartdate_time'); + let ed = Ext.getCmp('cenddate_date'); + let sd = Ext.getCmp('cstartdate_date'); - sdt.hide().setValue(mxcCore.config.mgr_allday_start); - //Ext.getCmp('cenddate_fields').hide(); - Ext.getCmp('cenddate_time').hide(); - edt.setValue(mxcCore.config.mgr_allday_end); + //Ext.getCmp('cstartdate_fields').label.update(_('mxcalendars.startdate_col_label')); + + if (calldayFlag.getValue() === true) { + + sdt.hide().setValue(mxcCore.config.mgr_allday_start); + //Ext.getCmp('cenddate_fields').hide(); + Ext.getCmp('cenddate_time').hide(); + edt.setValue(mxcCore.config.mgr_allday_end); + + if (ed.getValue() !== sd.getValue()) { + ed.setValue(sd.getValue()); + } + + } else { + sdt.show(); + //Ext.getCmp('cenddate_fields').show(); + Ext.getCmp('cenddate_time').show(); + //Ext.getCmp('cstartdate_fields').label.update(_('mxcalendars.label_startdate')); + } - if(ed.getValue() !== sd.getValue()){ - ed.setValue(sd.getValue()); } - - } else { - sdt.show(); - //Ext.getCmp('cenddate_fields').show(); - Ext.getCmp('cenddate_time').show(); - //Ext.getCmp('cstartdate_fields').label.update(_('mxcalendars.label_startdate')); } - - }}} } - - ] - },{ - xtype: 'container', + } + + ] + }, { + xtype: 'container', labelWidth: '250', id: 'cstartdate_fields', - fieldLabel: _('mxcalendars.label_startdate'), - combineErrors: true, - msgTarget : 'side', - layout: 'hbox', - defaults: { - flex: 1, - hideLabel: true - }, - items: [ - { - xtype : 'datefield', - name : 'startdate_date', - id : 'cstartdate_date', - format : mxcCore.config.mgr_dateformat, - fieldLabel: 'Start', - padding: '0 5 0 0', - allowBlank: false, - width: 150, + fieldLabel: _('mxcalendars.label_startdate'), + combineErrors: true, + msgTarget: 'side', + layout: 'hbox', + defaults: { + flex: 1, + hideLabel: true + }, + items: [ + { + xtype: 'datefield', + name: 'startdate_date', + id: 'cstartdate_date', + format: mxcCore.config.mgr_dateformat, + fieldLabel: 'Start', + padding: '0 5 0 0', + allowBlank: true, + width: 150, value: config.record.startdate_date, - listeners:{change:{fn:function(item, value) { - var ed = Ext.getCmp('cenddate_date'); - if(ed.getValue() === ''){ - ed.setValue(value); - } - - var alldayFlag = Ext.getCmp('callday'); - if(alldayFlag.getValue() === true){ - Ext.getCmp('cenddate_date').setValue(value); + listeners: { + change: { + fn: function (item, value) { + let ed = Ext.getCmp('cenddate_date'); + if (ed.getValue() === '') { + ed.setValue(value); + } + + let alldayFlag = Ext.getCmp('callday'); + if (alldayFlag.getValue() === true) { + Ext.getCmp('cenddate_date').setValue(value); + } + + } } - - }} } - - }, - { - xtype : 'timefield', - name : 'startdate_time', - id : 'cstartdate_time', - format : mxcCore.config.mgr_timeformat, - fieldLabel: 'Time', - margin: '0 5 0 0', - allowBlank: false, - width: 120, - value: config.record.startdate_time, + + }, + { + xtype: 'timefield', + name: 'startdate_time', + id: 'cstartdate_time', + format: mxcCore.config.mgr_timeformat, + fieldLabel: 'Time', + margin: '0 5 0 0', + allowBlank: true, + width: 120, + value: config.record.startdate_time, hidden: config.record.allday ? true : false - } - ] - },{ - xtype: 'container', - fieldLabel: _('mxcalendars.label_enddate'), - combineErrors: true, - id: 'cenddate_fields', - msgTarget : 'side', - layout: 'hbox', - defaults: { - flex: 1, - hideLabel: true - }, - items: [ - { - xtype : 'datefield', - name : 'enddate_date', - id: 'cenddate_date', - format : mxcCore.config.mgr_dateformat, - fieldLabel: 'End', - padding: '0 5 0 0', - allowBlank: false, - width: 150, - value: config.record.enddate_date, - hidden: config.record.allday ? true : false - }, - { - xtype : 'timefield', - name : 'enddate_time', - id : 'cenddate_time', - format : mxcCore.config.mgr_timeformat, - fieldLabel: 'End Time', - margin: '0 5 0 0', - allowBlank: false, - width: 120, - value: config.record.enddate_time, - hidden: config.record.allday ? true : false - } - ] - }] - }] - },{name: 'repeating',id: 'crepeating',xtype:'hidden',value:config.record.repeating?1:0} - ,{ - xtype:'fieldset', - checkboxToggle:true, - title: _('mxcalendars.label_repeating_event'), - collapsed: config.record.repeating ? false : true, - autoHeight: true, - layout: 'column', - border: 'false', - listeners: { -         'beforecollapse' :  function(panel,ani) { -         // Hide all the form fields you need to hide - Ext.getCmp('crepeating').setValue(0); -         return true; // this will avoid collapse of the field set -     }, -     'beforeexpand' : function(panel,ani) { -         // Display all the fields -         Ext.getCmp('crepeating').setValue(1); - return true; // this will avoid the default expand behaviour -     } + } + ] + }, { + xtype: 'container', + fieldLabel: _('mxcalendars.label_enddate'), + combineErrors: true, + id: 'cenddate_fields', + msgTarget: 'side', + layout: 'hbox', + defaults: { + flex: 1, + hideLabel: true + }, + items: [ + { + xtype: 'datefield', + name: 'enddate_date', + id: 'cenddate_date', + format: mxcCore.config.mgr_dateformat, + fieldLabel: 'End', + padding: '0 5 0 0', + allowBlank: true, + width: 150, + value: config.record.enddate_date, + hidden: config.record.allday ? true : false + }, + { + xtype: 'timefield', + name: 'enddate_time', + id: 'cenddate_time', + format: mxcCore.config.mgr_timeformat, + fieldLabel: 'End Time', + margin: '0 5 0 0', + allowBlank: true, + width: 120, + value: config.record.enddate_time, + hidden: config.record.allday ? true : false + } + ] + }] + }] + }, + {name: 'repeating', id: 'crepeating', xtype: 'hidden', value: config.record.repeating ? 1 : 0}, + { + xtype: 'fieldset', + checkboxToggle: true, + title: _('mxcalendars.label_repeating_event'), + collapsed: config.record.repeating === 'ano' ? false : true, + autoHeight: true, + layout: 'column', + border: 'false', + listeners: { + 'beforecollapse': function (panel, ani) { + // Hide all the form fields you need to hide + Ext.getCmp('crepeating').setValue(0); + return true; // this will avoid collapse of the field set }, - items :[ - { - columnWidth: .9, - border: false, - layout: 'form', - hideMode: 'offsets', - items: [ - { - fieldLabel: 'Occurs' - ,name: 'repeattype' - ,id: 'crepeattype' - ,xtype:'combo' - ,mode: 'local' - ,anchor: '100%' - ,hideLabel: false - ,labelWidth: 100 - ,store: new Ext.data.ArrayStore({ - id: 0, - fields: ['v', 'measure'], - data: [[0, _('mxcalendars.label_daily')],[1, _('mxcalendars.label_weekly')],[2, _('mxcalendars.label_monthly')],[3, _('mxcalendars.label_yearly')]] - }) - ,triggerAction: 'all' - ,displayField: 'measure' - ,valueField: 'v' - ,editable: true - ,cls: 'mxcFloat' - ,value: config.record.repeattype - ,listeners:{select:{fn:function(combo, value) { - var rt = Ext.getCmp('crepeattype'); - if(rt.getValue() === 1){ - Ext.getCmp('crepeaton').show(); - Ext.getCmp('crepeaton').doLayout(); - } else { Ext.getCmp('crepeaton').hide(); } - }} + 'beforeexpand': function (panel, ani) { + // Display all the fields + Ext.getCmp('crepeating').setValue(1); + return true; // this will avoid the default expand behaviour + } + }, + items: [ + { + columnWidth: 0.9, + border: false, + layout: 'form', + hideMode: 'offsets', + items: [ + { + fieldLabel: 'Occurs', + name: 'repeattype', + id: 'crepeattype', + xtype: 'combo', + mode: 'local', + anchor: '100%', + hideLabel: false, + labelWidth: 100, + store: new Ext.data.ArrayStore({ + id: 0, + fields: ['v', 'measure'], + data: [[0, _('mxcalendars.label_daily')], [1, _('mxcalendars.label_weekly')], [2, _('mxcalendars.label_monthly')], [3, _('mxcalendars.label_yearly')]] + }), + triggerAction: 'all', + displayField: 'measure', + valueField: 'v', + editable: true, + cls: 'mxcFloat', + value: config.record.repeattype, + listeners: { + select: { + fn: function (combo, value) { + let rt = Ext.getCmp('crepeattype'); + if (rt.getValue() === 1) { + Ext.getCmp('crepeaton').show(); + Ext.getCmp('crepeaton').doLayout(); + } else { + Ext.getCmp('crepeaton').hide(); + } + } } - ,value: config.record.repeattype - },{ - fieldLabel: _('mxcalendars.label_repeaton') - ,name: 'repeaton' - ,id: 'crepeaton' - ,xtype: 'checkboxgroup' - ,anchor: '100%' - ,hideLabel: false - ,labelWidth: 100 - ,hidden: config.record.repeattype == 1 ? false : true // hide on load - ,items: [ - {boxLabel: _('mxcalendars.label_sunday'), name: 'cb-auto-1', value: -1, checked: config.record.repeaton.indexOf(',-1,')!=-1 ? true : false }, - {boxLabel: _('mxcalendars.label_monday'), name: 'cb-auto-2', value: 0, checked: config.record.repeaton.indexOf(',0,')!=-1 ? true : false }, - {boxLabel: _('mxcalendars.label_tuesday'), name: 'cb-auto-3', value: 1, checked: config.record.repeaton.indexOf(',1,')!=-1 ? true : false }, - {boxLabel: _('mxcalendars.label_wednesday'), name: 'cb-auto-4', value: 2, checked: config.record.repeaton.indexOf(',2,')!=-1 ? true : false }, - {boxLabel: _('mxcalendars.label_thursday'), name: 'cb-auto-5', value: 3, checked: config.record.repeaton.indexOf(',3,')!=-1 ? true : false }, - {boxLabel: _('mxcalendars.label_friday'), name: 'cb-auto-6', value: 4, checked: config.record.repeaton.indexOf(',4,')!=-1 ? true : false }, - {boxLabel: _('mxcalendars.label_saturday'), name: 'cb-auto-7', value: 5, checked: config.record.repeaton.indexOf(',5,')!=-1 ? true : false } - ] - ,value: config.record.repeaton - }, - { - fieldLabel: _('mxcalendars.label_repeat_frequency') - ,name: 'repeatfrequency' - ,id: 'crepeatfrequency' - ,xtype: 'combo' - ,mode: 'local' - ,hideLabel: false - ,labelWidth: 100 - ,anchor: '100%' - ,store: new Ext.data.ArrayStore({ - id: 0, - fields: ['counter'], - data: [[],[1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12],[13],[14],[15],[16],[17],[18],[19],[20],[21],[22],[23],[24],[25],[26],[27],[28],[29],[30]] - }) - ,triggerAction: 'all' - ,displayField: 'counter' - ,valueField: 'counter' - ,editable: true - ,value: config.record.repeatfrequency - ,listeners: { - render: function(c) { + } + //, value: config.record.repeattype + }, + { + fieldLabel: _('mxcalendars.label_repeaton'), + name: 'repeaton', + id: 'crepeaton', + xtype: 'checkboxgroup', + anchor: '100%', + hideLabel: false, + labelWidth: 100, + hidden: config.record.repeattype == 1 ? false : true, // hide on load + items: [ + { + boxLabel: _('mxcalendars.label_sunday'), + name: 'cb-auto-1', + value: -1, + checked: config.record.repeaton.indexOf(',-1,') != -1 ? true : false + }, + { + boxLabel: _('mxcalendars.label_monday'), + name: 'cb-auto-2', + value: 0, + checked: config.record.repeaton.indexOf(',0,') != -1 ? true : false + }, + { + boxLabel: _('mxcalendars.label_tuesday'), + name: 'cb-auto-3', + value: 1, + checked: config.record.repeaton.indexOf(',1,') != -1 ? true : false + }, + { + boxLabel: _('mxcalendars.label_wednesday'), + name: 'cb-auto-4', + value: 2, + checked: config.record.repeaton.indexOf(',2,') != -1 ? true : false + }, + { + boxLabel: _('mxcalendars.label_thursday'), + name: 'cb-auto-5', + value: 3, + checked: config.record.repeaton.indexOf(',3,') != -1 ? true : false + }, + { + boxLabel: _('mxcalendars.label_friday'), + name: 'cb-auto-6', + value: 4, + checked: config.record.repeaton.indexOf(',4,') != -1 ? true : false + }, + { + boxLabel: _('mxcalendars.label_saturday'), + name: 'cb-auto-7', + value: 5, + checked: config.record.repeaton.indexOf(',5,') != -1 ? true : false + } + ], + value: config.record.repeaton + }, + { + fieldLabel: _('mxcalendars.label_repeat_frequency'), + name: 'repeatfrequency', + id: 'crepeatfrequency', + xtype: 'combo', + mode: 'local', + hideLabel: false, + labelWidth: 100, + anchor: '100%', + store: new Ext.data.ArrayStore({ + id: 0, + fields: ['counter'], + data: [[], [1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12], [13], [14], [15], [16], [17], [18], [19], [20], [21], [22], [23], [24], [25], [26], [27], [28], [29], [30]] + }), + triggerAction: 'all', + displayField: 'counter', + valueField: 'counter', + editable: true, + value: config.record.repeatfrequency, + listeners: { + render: function (c) { Ext.QuickTips.register({ target: c.getEl(), text: _('mxcalendars.tip_repeaton') }); - } } - },{ - fieldLabel: _('mxcalendars.label_repeat_last_occurance') - ,name: 'repeatenddate' - ,id: 'crepeatenddate' - ,hideLabel: false - ,labelWidth: 100 - ,anchor: '100% 100%' - ,format : mxcCore.config.mgr_dateformat - ,allowBlank:false - ,xtype: 'datefield' - ,value: config.record.repeatenddate - ,submitValue: false } - ] - } - ] - },{ - xtype: 'container' - ,anchor: '100%' - ,layout: 'form' - ,items: [ - { - xtype:'tabpanel' - ,plain:true - ,activeTab: 0 - ,height:385 - //,autoHeight: true - ,width:840 - ,defaults:{bodyStyle:'padding:10px',layout:'form'} - ,items:[ - { - cls: 'x-plain', - title: _('mxcalendars.label_description'), - layout: 'fit', - items: { - xtype: mxcCore.config.event_desc_type == 'htmleditor' ? 'textarea' : mxcCore.config.event_desc_type - ,name: 'description' - ,hiddenName: 'description' - ,id: 'cdescription' - ,value: config.record.description - } - ,listeners:{ - activate : function(tabpanel){ - //if(MODx.config.use_editor && MODx.loadRTE && mxcCore.config.event_desc_type == 'htmleditor'){ - // MODx.loadRTE('description-'+config.record.id); - //} - - if (MODx.loadRTE) { - MODx.loadRTE('cdescription'); // Will transform the textarea with ID "description" to a RTE - // MODx.loadRTE(['description1','description2']); - } + }, { + fieldLabel: _('mxcalendars.label_repeat_last_occurance'), + name: 'repeatenddate', + id: 'crepeatenddate', + hideLabel: false, + labelWidth: 100, + anchor: '100% 100%', + format: mxcCore.config.mgr_dateformat, + allowBlank: true, + xtype: 'datefield', + value: config.record.repeatenddate, + submitValue: false + } + ] + } + ] + }, + { + xtype: 'container', + anchor: '100%', + layout: 'form', + items: [{ + xtype: 'tabpanel', + plain: true, + activeTab: 0, + height: 385, + //,autoHeight: true + width: 840, + defaults: {bodyStyle: 'padding:10px', layout: 'form'}, + items: [ + { + cls: 'x-plain', + title: _('mxcalendars.label_description'), + layout: 'fit', + items: { + xtype: mxcCore.config.event_desc_type == 'htmleditor' ? 'textarea' : mxcCore.config.event_desc_type, + name: 'description', + hiddenName: 'description', + id: 'cdescription', + value: config.record.description + }, + listeners: { + activate: function (tabpanel) { + //if(MODx.config.use_editor && MODx.loadRTE && mxcCore.config.event_desc_type == 'htmleditor'){ + // MODx.loadRTE('description-'+config.record.id); + //} - } + if (MODx.loadRTE) { + MODx.loadRTE('cdescription'); // Will transform the textarea with ID "description" to a RTE + // MODx.loadRTE(['description1','description2']); } - },{ - cls: 'x-plain', - title: _('mxcalendars.label_content'), - layout: 'fit', - items: { - xtype: mxcCore.config.event_desc_type == 'htmleditor' ? 'textarea' : mxcCore.config.event_desc_type - ,name: 'content' - ,hiddenName: 'content' - ,id: 'ccontent' - ,value: config.record.content - } - ,listeners:{ - activate : function(tabpanel){ - if (MODx.config.use_editor && MODx.loadRTE){ - MODx.loadRTE('ccontent'); - } - } + + } + } + }, + { + cls: 'x-plain', + title: _('mxcalendars.label_content'), + layout: 'fit', + items:{ + xtype: mxcCore.config.event_desc_type == 'htmleditor' ? 'textarea' : mxcCore.config.event_desc_type, + name: 'content', + hiddenName: 'content', + id: 'ccontent', + value: config.record.content + }, + listeners: { + activate: function (tabpanel) { + if (MODx.config.use_editor && MODx.loadRTE) { + MODx.loadRTE('ccontent'); } - },{ - cls: 'x-plain', - title: _('mxcalendars.label_images'), - layout: 'fit', - items: { - xtype: 'mxc-images-grid' - ,id: 'gridimages' - } - },{ - cls: 'x-plain', - title: _('mxcalendars.label_videos'), - layout: 'fit', - items: { - xtype: 'mxc-videos-grid' - ,id: 'gridvideos' - } - },{ - title: _('mxcalendars.label_location') - ,defaults: {width:230} - ,defaultType:'textfield' - ,items:[{ - fieldLabel: _('mxcalendars.label_name') - ,name:'location_name' - ,id: 'clocation_name' - ,value: config.record.location_name - },{ - fieldLabel: _('mxcalendars.label_address') - ,name:'location_address' - ,id:'clocation_address' - ,value: config.record.location_address - },{ - boxLabel: _('mxcalendars.label_display_map') - ,name:'map' - ,id:'cmap' - ,xtype:'checkbox' - ,checked: config.record.map ? true : false - }] - },{ - title:_('mxcalendars.label_link'), - defaults: {width: 230}, - defaultType: 'textfield', - items: [{ - fieldLabel: 'Link' - ,name: 'link' - ,id: 'clink' - ,allowBlank:false - ,value: config.record.link - },{ - fieldLabel: _('mxcalendars.label_link_rel') - ,name: 'linkrel' - ,id: 'clinkrel' - ,value: config.record.linkrel - },{ - fieldLabel: _('mxcalendars.label_link_target') - ,name: 'linktarget' - ,id: 'clinktarget' - ,xtype: 'combo' - ,mode: 'local' - ,store: new Ext.data.ArrayStore({ - id: 0, - fields: ['tt'], - data: [['_self'],['_new'],['_blank']] - }) - ,triggerAction: 'all' - ,displayField: 'tt' - ,valueField: 'tt' - ,editable: true - ,width: 'auto' - ,anchor: '30%' - ,value: config.record.linktarget - }] - },{ - title:"Form" - ,defaults: {width:230} - ,items: [{ - xtype: 'combo', - displayField: 'name', - valueField: 'name', - forceSelection: true, - store: new Ext.data.JsonStore({ - root: 'results', - idProperty: 'id', - url: mxcCore.config.connectorUrl, - baseParams: { - action: 'stores/getformchunks' - }, - fields: [ - 'id','name','description', - ] - }), - mode: 'remote', - triggerAction: 'all', - fieldLabel: _('mxcalendars.grid_col_formchunk'), - name: 'form_chunk', - hiddenName: 'form_chunk', - id: 'cform_chunk', - allowBlank: true, - typeAhead:true, - minChars:1, - emptyText:_('mxcalendars.label_select_form'), - value: config.record.form_chunk, - valueNotFoundText:_('mxcalendars.label_select_form_err'), - anchor:'100%' - }] } - ] - } - ] - },{ - xtype: 'checkbox' - ,boxLabel: _('mxcalendars.category_active_col_label') - ,id: 'cactive' - ,name: 'active' - ,hiddenName: 'active' - ,checked: true - ,value: 1 + } + }, + { + cls: 'x-plain', + title: _('mxcalendars.label_images'), + layout: 'fit', + items: { + xtype: 'mxc-images-grid', + id: 'gridimages' + } + }, + { + cls: 'x-plain', + title: _('mxcalendars.label_videos'), + layout: 'fit', + items: { + xtype: 'mxc-videos-grid', + id: 'gridvideos' + } + }, + { + title: _('mxcalendars.label_location'), + defaults: {width: 230}, + defaultType: 'textfield', + items: [ + { + fieldLabel: _('mxcalendars.label_name'), + name: 'location_name', + id: 'clocation_name', + value: config.record.location_name + }, + { + fieldLabel: _('mxcalendars.label_address'), + name: 'location_address', + id: 'clocation_address', + value: config.record.location_address + }, + { + boxLabel: _('mxcalendars.label_display_map'), + name: 'map', + id: 'cmap', + xtype: 'checkbox', + checked: config.record.map ? true : false + } + ] + }, + { + title: _('mxcalendars.label_price'), + defaults: {width: 230}, + defaultType: 'textfield', + items: [{ + fieldLabel: _('mxcalendars.label_price'), + name: 'label_price', + id: 'cprice', + value: config.record.price + }] + }, + { + title: _('mxcalendars.label_food'), + defaults: {width: 230}, + defaultType: 'textfield', + items: [{ + fieldLabel: _('mxcalendars.label_food'), + name: 'label_food', + id: 'cfood', + value: config.record.food + }] + }, + { + title: _('mxcalendars.label_age'), + defaults: {width: 230}, + defaultType: 'textfield', + items: [{ + fieldLabel: _('mxcalendars.label_age'), + name: 'label_age', + id: 'cage', + value: config.record.age + }] + }, + { + title: _('mxcalendars.label_capacity'), + defaults: {width: 230}, + defaultType: 'textfield', + items: [{ + fieldLabel: _('mxcalendars.label_capacity'), + name: 'label_capacity', + id: 'ccapacity', + value: config.record.capacity + }] + }, + { + title: _('mxcalendars.label_link'), + defaults: {width: 230}, + defaultType: 'textfield', + items: [ + { + fieldLabel: 'Link', + name: 'link', + id: 'clink', + allowBlank: true, + value: config.record.link + }, + // fieldLabel: _('mxcalendars.label_link_rel') + // , name: 'linkrel' + // , id: 'clinkrel' + // , value: config.record.linkrel + // }, { + { + fieldLabel: _('mxcalendars.label_link_target'), + name: 'linktarget', + id: 'clinktarget', + xtype: 'combo', + mode: 'local', + store: new Ext.data.ArrayStore({ + id: 0, + fields: ['tt'], + data: [['_self'], ['_new'], ['_blank']] + }), + triggerAction: 'all', + displayField: 'tt', + valueField: 'tt', + editable: true, + width: 'auto', + anchor: '30%', + value: config.record.linktarget + } + ] + }, + { + title: 'Form', + defaults: {width: 230}, + items: [{ + xtype: 'combo', + displayField: 'name', + valueField: 'name', + forceSelection: true, + store: new Ext.data.JsonStore({ + root: 'results', + idProperty: 'id', + url: mxcCore.config.connectorUrl, + baseParams: { + action: 'stores/getformchunks' + }, + fields: [ + 'id', 'name', 'description', + ] + }), + mode: 'remote', + triggerAction: 'all', + fieldLabel: _('mxcalendars.grid_col_formchunk'), + name: 'form_chunk', + hiddenName: 'form_chunk', + id: 'cform_chunk', + allowBlank: true, + typeAhead: true, + minChars: 1, + emptyText: _('mxcalendars.label_select_form'), + value: config.record.form_chunk, + valueNotFoundText: _('mxcalendars.label_select_form_err'), + anchor: '100%' + }] + } + ] } - ] - - ,buttons: [{ - text: _('mxcalendars.label_cancel') - ,type: 'close' - ,handler: function() - { - Ext.getCmp('CreateCal').hide(); - } - },{ - text: _('mxcalendars.label_save') - ,handler: function(){ - - var repeatDOW = ''; - var rawRepeatOn = Ext.getCmp('crepeaton').getValue(); - ////console.log("RepeatOn: "+rawRepeatOn.join(",")); - for (i = 0; i < rawRepeatOn.length; i++) { - repeatDOW += ','+rawRepeatOn[i].value; - ////console.log(rawRepeatOn[i]); + ] + }, + { + xtype: 'checkbox', + boxLabel: _('mxcalendars.category_active_col_label'), + id: 'cactive', + name: 'active', + hiddenName: 'active', + checked: true, + value: 1 + } + ], + buttons: [ + { + text: _('mxcalendars.label_cancel'), + type: 'close', + handler: function () { + Ext.getCmp('CreateCal').hide(); } - if(repeatDOW.length){repeatDOW+=',';} - ////console.log("New RepeatON: "+repeatDOW); - var frmData = { - title: Ext.getCmp('ctitle').getValue() //req - ,active: Ext.getCmp('cactive').getValue() === true ? 1 :0 - ,description: Ext.getCmp('cdescription').getValue() - ,categoryid: Ext.getCmp('ccategoryid').getValue() //req - ,allday: Ext.getCmp('callday').getValue() === true ? 1 :0 - ,startdate_date: Ext.getCmp('cstartdate_date').getValue() //req - ,startdate_time: Ext.getCmp('cstartdate_time').getValue() //req - ,enddate_date: Ext.getCmp('cenddate_date').getValue() //req - ,enddate_time: Ext.getCmp('cenddate_time').getValue() //req - ,link: Ext.getCmp('clink').getValue() - ,linkrel: Ext.getCmp('clinkrel').getValue() - ,linktarget: Ext.getCmp('clinktarget').getValue() - ,location_name: Ext.getCmp('clocation_name').getValue() - ,location_address: Ext.getCmp('clocation_address').getValue() - ,map: Ext.getCmp('cmap').checked ? 1 : 0 - ,repeating: Ext.getCmp('crepeating').getValue() - ,repeattype: Ext.getCmp('crepeattype').getValue() - ,repeaton: repeatDOW //Ext.getCmp('repeaton').getValue() - ,repeatfrequency: Ext.getCmp('crepeatfrequency').getValue() - ,repeatenddate: Ext.getCmp('crepeatenddate').getValue() - ,context: Ext.getCmp('ccontext').getValue() - ,calendar_id: Ext.getCmp('ccalendar_id').getValue() - ,form_chunk: Ext.getCmp('cform_chunk').getValue() + }, + { + text: _('mxcalendars.label_save'), + handler: function () { + let repeatDOW = ''; + let rawRepeatOn = Ext.getCmp('crepeaton').getValue(); + ////console.log("RepeatOn: "+rawRepeatOn.join(",")); + for (let i = 0; i < rawRepeatOn.length; i++) { + repeatDOW += ',' + rawRepeatOn[i].value; + ////console.log(rawRepeatOn[i]); + } + if (repeatDOW.length) { + repeatDOW += ','; + } + ////console.log("New RepeatON: "+repeatDOW); + let frmData = { + title: Ext.getCmp('ctitle').getValue(), //req + active: Ext.getCmp('cactive').getValue() === true ? 1 : 0, + description: Ext.getCmp('cdescription').getValue(), + categoryid: Ext.getCmp('ccategoryid').getValue(), //req + allday: Ext.getCmp('callday').getValue() === true ? 1 : 0, + startdate_date: Ext.getCmp('cstartdate_date').getValue(), //req + startdate_time: Ext.getCmp('cstartdate_time').getValue(), //req + enddate_date: Ext.getCmp('cenddate_date').getValue(), //req + enddate_time: Ext.getCmp('cenddate_time').getValue(), //req + link: Ext.getCmp('clink').getValue(), + //, linkrel: Ext.getCmp('clinkrel').getValue(), + linktarget: Ext.getCmp('clinktarget').getValue(), + location_name: Ext.getCmp('clocation_name').getValue(), + location_address: Ext.getCmp('clocation_address').getValue(), + map: Ext.getCmp('cmap').checked ? 1 : 0, + price: Ext.getCmp('cprice').getValue(), + food: Ext.getCmp('cfood').getValue(), + age: Ext.getCmp('cage').getValue(), + capacity: Ext.getCmp('ccapacity').getValue(), + repeating: Ext.getCmp('crepeating').getValue(), + repeattype: Ext.getCmp('crepeattype').getValue(), + repeaton: repeatDOW, //Ext.getCmp('repeaton').getValue(), + repeatfrequency: Ext.getCmp('crepeatfrequency').getValue(), + repeatenddate: Ext.getCmp('crepeatenddate').getValue(), + context: Ext.getCmp('ccontext').getValue(), + calendar_id: Ext.getCmp('ccalendar_id').getValue(), + form_chunk: Ext.getCmp('cform_chunk').getValue(), // @TODO move to proper config section - ,HTTP_MODAUTH: MODx.siteId - ,action: 'mgr/events/create' - }; - - mxcCore.ajax.request({ - url: mxcCore.config.connectorUrl, + HTTP_MODAUTH: MODx.siteId, + action: 'mgr/events/create' + }; + + mxcCore.ajax.request({ + url: mxcCore.config.connectorUrl, extraParams: { - //action: 'mgr/events/update' - }, - params: frmData, - scope: this, - success: function(resp, opts) { - // resp is the XmlHttpRequest object - var status = Ext.decode(resp.responseText).success; - if(!status){ - errmsg = ''; - cnt=0; - Ext.each(Ext.decode(resp.responseText).data, function(op) { - cnt++; - errmsg += cnt+') '+op.msg+'
'; - var el = Ext.get('c'+op.id); - el.addClass('x-form-invalid'); - }); - if(cnt > 0) Ext.Msg.alert("Error",errmsg); - } else { - //Ext.Msg.alert('Update Event', 'Your event data is: '); - Ext.getCmp('CreateCal').hide(); - Ext.getCmp('mxcalendars-grid-events').refresh(); - } - }, - failure: function(resp, opts) { - ////console.log('server-side failure with status code ' + resp.status); - } - }); - - } - }] + //action: 'mgr/events/update' + }, + params: frmData, + scope: this, + success: function (resp, opts) { + // resp is the XmlHttpRequest object + let status = Ext.decode(resp.responseText).success; + if (!status) { + let errmsg = ''; + let cnt = 0; + Ext.each(Ext.decode(resp.responseText).data, function (op) { + cnt++; + errmsg += cnt + ') ' + op.msg + '
'; + let el = Ext.get('c' + op.id); + el.addClass('x-form-invalid'); + }); + if (cnt > 0) Ext.Msg.alert('Error', errmsg); + } else { + //Ext.Msg.alert('Update Event', 'Your event data is: '); + Ext.getCmp('CreateCal').hide(); + Ext.getCmp('mxcalendars-grid-events').refresh(); + } + }, + failure: function (resp, opts) { + ////console.log('server-side failure with status code ' + resp.status); + } + }); + + } + } + ] }); - mxcCore.window.CreateCal.superclass.constructor.call(this,config); - this.on('deactivate',function(w,e) { - if(MODx.config.use_editor && MODx.loadRTE && typeof tinyMCE !== 'undefined'){ - tinyMCE.execCommand('mceRemoveControl',false, 'cdescription-'+config.record.id); - tinyMCE.execCommand('mceRemoveControl',false, 'ccontent-'+config.record.id); + mxcCore.window.CreateCal.superclass.constructor.call(this, config); + this.on('deactivate', function (w, e) { + if (MODx.config.use_editor && MODx.loadRTE && typeof tinyMCE !== 'undefined') { + tinyMCE.execCommand('mceRemoveControl', false, 'cdescription-' + config.record.id); + tinyMCE.execCommand('mceRemoveControl', false, 'ccontent-' + config.record.id); } - },this); + }, this); }; -Ext.extend(mxcCore.window.CreateCal,MODx.Window); -Ext.reg('mxcalendars-window-mxcalendar-create',mxcCore.window.CreateCal); +Ext.extend(mxcCore.window.CreateCal, MODx.Window); +Ext.reg('mxcalendars-window-mxcalendar-create', mxcCore.window.CreateCal); Ext.ns('mxcCore.window'); -mxcCore.window.UpdateCal = function(config) { +mxcCore.window.UpdateCal = function (config) { config = config || {}; - this.mxcEvent = Ext.applyIf(config,{ - title: _('mxcalendars.event_title_update') - ,autoHeight: false - ,height: Ext.getBody().getViewSize().height*.85 - ,autoScroll: true - ,xtype: 'form' - ,layout: 'form' - ,id: 'UpdateCal' - ,url: mxcCore.config.connectorUrl - ,width: 870 - ,baseParams: { + this.mxcEvent = Ext.applyIf(config, { + title: _('mxcalendars.event_title_update'), + autoHeight: false, + height: Ext.getBody().getViewSize().height * 0.85, + autoScroll: true, + xtype: 'form', + layout: 'form', + id: 'UpdateCal', + url: mxcCore.config.connectorUrl, + width: 870, + baseParams: { action: 'mgr/events/update' - } - ,border: false - ,bodyStyle: 'padding:15px' - ,plain:true - ,fieldDefaults: { + }, + border: false, + bodyStyle: 'padding:15px', + plain: true, + fieldDefaults: { //msgTarget: 'side' - } - ,defaults: { - // applied to each contained item - // nothing this time - anchor:'100%' - ,layout: 'Form' - ,labelWidth: '100' - ,cellCls: 'valign-center' - } - ,items: - [{ - xtype: 'container', - anchor: '0', - layout: 'column', - defaultType: 'container', - defaults: { - layout:'form', - defaultType: 'textfield', - labelAlign: 'left', - anchor: '0' - //,msgTarget: 'side' - }, - items: [ - { - // Left Column - columnWidth: .5, - items: [{ - xtype: 'combo', - displayField: 'key', - valueField: 'key', - forceSelection: true, - store: new Ext.data.JsonStore({ - root: 'results', - idProperty: 'key', - url: mxcCore.config.connectorUrl, - baseParams: { - action: 'stores/getcontexts' - }, - fields: [ + }, + defaults: { + // applied to each contained item + // nothing this time + anchor: '100%', + layout: 'Form', + labelWidth: '100', + cellCls: 'valign-center' + }, + items: + [ + { + xtype: 'container', + anchor: '0', + layout: 'column', + defaultType: 'container', + defaults: { + layout: 'form', + defaultType: 'textfield', + labelAlign: 'left', + anchor: '0' + //,msgTarget: 'side' + }, + items: [ + { + // Left Column + columnWidth: 0.5, + items: [ + { + xtype: 'combo', + displayField: 'key', + valueField: 'key', + forceSelection: true, + store: new Ext.data.JsonStore({ + root: 'results', + idProperty: 'key', + url: mxcCore.config.connectorUrl, + baseParams: { + action: 'stores/getcontexts' + }, + fields: [ 'key', - ] - }), - mode: 'remote', - triggerAction: 'all', - fieldLabel: _('mxcalendars.grid_col_context'), - name: 'context', - hiddenName: 'context', - id: 'context', - allowBlank: mxcCore.config.isAdministrator ? true : false, - typeAhead:true, - minChars:1, - emptyText:_('mxcalendars.label_select_context'), - valueNotFoundText:_('mxcalendars.label_select_context_err'), - anchor:'100%', - value: config.record.context - },{ - xtype: 'hidden' - ,name:'id' - ,id: 'id' - ,value: config.record.id - },{ - xtype: 'hidden' - ,name:'source' - ,id: 'source' - ,value: config.record.source - },{ - fieldLabel: _('mxcalendars.label_title'), - name: 'title', - hiddenname: 'title', - id: 'title', - allowBlank: false, - anchor:'100%', - value: config.record.title - },{ - xtype: 'superboxselect', - displayField: 'name', - valueField: 'id', - forceSelection: true, - store: new Ext.data.JsonStore({ - root: 'results', - idProperty: 'id', - url: mxcCore.config.connectorUrl, - baseParams: { - action: 'stores/getcategories' - }, - fields: [ - 'id', 'name' - ] - }), - mode: 'remote', - triggerAction: 'all', - fieldLabel: _('mxcalendars.grid_col_category'), - name: 'categoryid', - hiddenName: 'categoryid', - id: 'categoryid', - allowBlank: mxcCore.config.category_required ? true : false, - typeAhead:true, - minChars:1, - emptyText:_('mxcalendars.label_select_category'), - valueNotFoundText:_('mxcalendars.label_select_category_err'), - anchor:'100%', - value: config.record.categoryid - }] - },{ - // Right Column - columnWidth: .5, - items: [{ - xtype: 'combo', - displayField: 'name', - valueField: 'id', - forceSelection: true, - store: new Ext.data.JsonStore({ - root: 'results', - idProperty: 'id', - url: mxcCore.config.connectorUrl, - baseParams: { - action: 'stores/getcalendars' - }, - fields: [ + ] + }), + mode: 'remote', + triggerAction: 'all', + fieldLabel: _('mxcalendars.grid_col_context'), + name: 'context', + hiddenName: 'context', + id: 'context', + allowBlank: mxcCore.config.isAdministrator ? true : false, + typeAhead: true, + minChars: 1, + emptyText: _('mxcalendars.label_select_context'), + valueNotFoundText: _('mxcalendars.label_select_context_err'), + anchor: '100%', + value: config.record.context + }, + { + xtype: 'hidden', + name: 'id', + id: 'id', + value: config.record.id + }, + { + xtype: 'hidden', + name: 'source', + id: 'source', + value: config.record.source + }, + { + fieldLabel: _('mxcalendars.label_title'), + name: 'title', + hiddenname: 'title', + id: 'title', + allowBlank: true, + anchor: '100%', + value: config.record.title + }, + { + xtype: 'superboxselect', + displayField: 'name', + valueField: 'id', + forceSelection: true, + lazyRender: true, + editable: true, + store: new Ext.data.JsonStore({ + root: 'results', + idProperty: 'id', + autoLoad: true, + url: mxcCore.config.connectorUrl, + baseParams: { + action: 'stores/getcategories' + }, + fields: [ + 'id', 'name' + ] + }), + mode: 'remote', + triggerAction: 'all', + fieldLabel: _('mxcalendars.grid_col_category'), + name: 'categoryid', + hiddenName: 'categoryid', + id: 'categoryid', + allowBlank: mxcCore.config.category_required ? true : false, + typeAhead: true, + minChars: 1, + emptyText: _('mxcalendars.label_select_category'), + valueNotFoundText: _('mxcalendars.label_select_category_err'), + anchor: '100%', + value: config.record.categoryid + } + ] + }, + { + // Right Column + columnWidth: 0.5, + items: [ + { + xtype: 'combo', + displayField: 'name', + valueField: 'id', + forceSelection: true, + store: new Ext.data.JsonStore({ + root: 'results', + idProperty: 'id', + url: mxcCore.config.connectorUrl, + baseParams: { + action: 'stores/getcalendars' + }, + fields: [ 'id', 'name' - ] - }), - mode: 'remote', - triggerAction: 'all', - fieldLabel: _('mxcalendars.grid_col_calendar'), - name: 'calendar_id', - hiddenName: 'calendar_id', - id: 'calendar_id', - allowBlank: true, - typeAhead:true, - minChars:1, - emptyText:_('mxcalendars.label_select_calendar'), - valueNotFoundText:_('mxcalendars.label_select_category_err'), - anchor:'100%', - value: config.record.calendar_id - },{ - xtype: 'container', - labelWidth: '250', - //boxLabel: _('mxcalendars.label_allday'), - combineErrors: true, - msgTarget : 'side', - layout: 'hbox', - defaults: { - flex: 1, - hideLabel: true + ] + }), + mode: 'remote', + triggerAction: 'all', + fieldLabel: _('mxcalendars.grid_col_calendar'), + name: 'calendar_id', + hiddenName: 'calendar_id', + id: 'calendar_id', + allowBlank: true, + typeAhead: true, + minChars: 1, + emptyText: _('mxcalendars.label_select_calendar'), + valueNotFoundText: _('mxcalendars.label_select_category_err'), + anchor: '100%', + value: config.record.calendar_id }, - items: [ - {boxLabel: _('mxcalendars.label_allday') - ,name:'allday' - ,id:'allday' - ,xtype:'checkbox' - ,checked: config.record.allday ? true : false - ,listeners:{check:{fn:function(tht, value) { + { + xtype: 'container', + labelWidth: '250', + //boxLabel: _('mxcalendars.label_allday'), + combineErrors: true, + msgTarget: 'side', + layout: 'hbox', + defaults: { + flex: 1, + hideLabel: true + }, + items: [ + { + boxLabel: _('mxcalendars.label_allday'), + name: 'allday', + id: 'allday', + xtype: 'checkbox', + checked: config.record.allday ? true : false, + listeners: { + check: { + fn: function (tht, value) { + let calldayFlag = Ext.getCmp('allday'); + let edt = Ext.getCmp('enddate_time'); + let sdt = Ext.getCmp('startdate_time'); + let ed = Ext.getCmp('enddate_date'); + let sd = Ext.getCmp('startdate_date'); + + //Ext.getCmp('startdate_fields').label.update(_('mxcalendars.startdate_col_label')); - var calldayFlag = Ext.getCmp('allday'); - - var edt = Ext.getCmp('enddate_time'); - var sdt = Ext.getCmp('startdate_time'); - var ed = Ext.getCmp('enddate_date'); - var sd = Ext.getCmp('startdate_date'); - - //Ext.getCmp('startdate_fields').label.update(_('mxcalendars.startdate_col_label')); - - if(calldayFlag.getValue() === true){ + if (calldayFlag.getValue() === true) { - sdt.hide().setValue(mxcCore.config.mgr_allday_start); - //Ext.getCmp('cenddate_fields').hide(); - Ext.getCmp('enddate_time').hide(); - edt.setValue(mxcCore.config.mgr_allday_end); + sdt.hide().setValue(mxcCore.config.mgr_allday_start); + //Ext.getCmp('cenddate_fields').hide(); + Ext.getCmp('enddate_time').hide(); + edt.setValue(mxcCore.config.mgr_allday_end); - if(ed.getValue() !== sd.getValue()){ - ed.setValue(sd.getValue()); + if (ed.getValue() !== sd.getValue()) { + ed.setValue(sd.getValue()); + } + + } else { + sdt.show(); + //Ext.getCmp('cenddate_fields').show(); + Ext.getCmp('enddate_time').show(); + //Ext.getCmp('cstartdate_fields').label.update(_('mxcalendars.label_startdate')); + } + + } + } } - - } else { - sdt.show(); - //Ext.getCmp('cenddate_fields').show(); - Ext.getCmp('enddate_time').show(); - //Ext.getCmp('cstartdate_fields').label.update(_('mxcalendars.label_startdate')); } - }}} - } - - ] - },{ - xtype: 'container', - labelWidth: '250', - id: 'startdate_fields', - fieldLabel: _('mxcalendars.label_startdate'), - combineErrors: true, - msgTarget : 'side', - layout: 'hbox', - defaults: { - flex: 1, - hideLabel: true - }, - items: [ - { - xtype : 'datefield', - name : 'startdate_date', - id : 'startdate_date', - format : mxcCore.config.mgr_dateformat, - fieldLabel: 'Start', - padding: '0 5 0 0', - allowBlank: false, - width: 150, - value: config.record.startdate_date - ,listeners:{select:{fn:function(ths, value) { - var edf = Ext.getCmp('enddate_date'); - if(edf.getValue() == ''){ - edf.setValue(value); - } - - var alldayFlag = Ext.getCmp('allday'); - if(alldayFlag.getValue() === true){ - Ext.getCmp('enddate_date').setValue(value); + ] + }, + { + xtype: 'container', + labelWidth: '250', + id: 'startdate_fields', + fieldLabel: _('mxcalendars.label_startdate'), + combineErrors: true, + msgTarget: 'side', + layout: 'hbox', + defaults: { + flex: 1, + hideLabel: true + }, + items: [ + { + xtype: 'datefield', + name: 'startdate_date', + id: 'startdate_date', + format: mxcCore.config.mgr_dateformat, + fieldLabel: 'Start', + padding: '0 5 0 0', + allowBlank: true, + width: 150, + value: config.record.startdate_date, + listeners: { + select: { + fn: function (ths, value) { + let edf = Ext.getCmp('enddate_date'); + if (edf.getValue() == '') { + edf.setValue(value); + } + + let alldayFlag = Ext.getCmp('allday'); + if (alldayFlag.getValue() === true) { + Ext.getCmp('enddate_date').setValue(value); + } + } + } + } + }, + { + xtype: 'timefield', + name: 'startdate_time', + id: 'startdate_time', + format: mxcCore.config.mgr_timeformat, + fieldLabel: 'Time', + margin: '0 5 0 0', + allowBlank: true, + width: 120, + //increment: mxcCore.config.mgr_time_increment, + value: config.record.startdate_time, + listeners: { + change: { + fn: function (tht, value) { + let edt = Ext.getCmp('enddate_time'); + if (edt.getValue() == '') { + edt.setValue(value); + } + } + } + } } - }} - } - }, - { - xtype : 'timefield', - name : 'startdate_time', - id : 'startdate_time', - format : mxcCore.config.mgr_timeformat, - fieldLabel: 'Time', - margin: '0 5 0 0', - allowBlank: false, - width: 120, - //increment: mxcCore.config.mgr_time_increment, - value: config.record.startdate_time - ,listeners:{change:{fn:function(tht, value) { - var edt = Ext.getCmp('enddate_time'); - if(edt.getValue() == ''){ - edt.setValue(value); + ] + }, + { + xtype: 'container', + fieldLabel: _('mxcalendars.label_enddate'), + combineErrors: true, + id: 'enddate_fields', + msgTarget: 'side', + layout: 'hbox', + defaults: { + flex: 1, + hideLabel: true + }, + items: [ + { + xtype: 'datefield', + name: 'enddate_date', + id: 'enddate_date', + format: mxcCore.config.mgr_dateformat, + fieldLabel: 'End', + padding: '0 5 0 0', + allowBlank: true, + width: 150, + value: config.record.enddate_date + }, + { + xtype: 'timefield', + name: 'enddate_time', + id: 'enddate_time', + format: mxcCore.config.mgr_timeformat, + fieldLabel: 'End Time', + margin: '0 5 0 0', + allowBlank: true, + width: 120, + //increment: mxcCore.config.mgr_time_increment, + value: config.record.enddate_time } - }} - } - } - ] - },{ - xtype: 'container', - fieldLabel: _('mxcalendars.label_enddate'), - combineErrors: true, - id: 'enddate_fields', - msgTarget : 'side', - layout: 'hbox', - defaults: { - flex: 1, - hideLabel: true - }, - items: [ - { - xtype : 'datefield', - name : 'enddate_date', - id: 'enddate_date', - format : mxcCore.config.mgr_dateformat, - fieldLabel: 'End', - padding: '0 5 0 0', - allowBlank: false, - width: 150, - value: config.record.enddate_date - }, - { - xtype : 'timefield', - name : 'enddate_time', - id : 'enddate_time', - format : mxcCore.config.mgr_timeformat, - fieldLabel: 'End Time', - margin: '0 5 0 0', - allowBlank: false, - width: 120, - //increment: mxcCore.config.mgr_time_increment, - value: config.record.enddate_time - } - ] - }] - }] - }, - { - xtype:'fieldset', - checkboxToggle:true, - title: _('mxcalendars.label_repeating_event'), - defaultType: 'textfield', - collapsed: config.record.repeating ? false : true, - autoHeight: true, - defaults: { - layout:'fill' + ] + } + ] + } + ] + }, + { + xtype: 'fieldset', + checkboxToggle: true, + title: _('mxcalendars.label_repeating_event'), + defaultType: 'textfield', + collapsed: config.record.repeating === 'ano' ? false : true, + autoHeight: true, + defaults: { + layout: 'fill' + }, + listeners: { + 'beforecollapse': function (panel, ani) { + // Hide all the form fields you need to hide + Ext.getCmp('repeating').setValue(0); + return true; // this will avoid collapse of the field set }, - listeners: { -         'beforecollapse' :  function(panel,ani) { -         // Hide all the form fields you need to hide - Ext.getCmp('repeating').setValue(0); -         return true; // this will avoid collapse of the field set -     }, -     'beforeexpand' : function(panel,ani) { -         // Display all the fields -         Ext.getCmp('repeating').setValue(1); - return true; // this will avoid the default expand behaviour -     } + 'beforeexpand': function (panel, ani) { + // Display all the fields + Ext.getCmp('repeating').setValue(1); + return true; // this will avoid the default expand behaviour + } + }, + layout: 'form', + labelWidth: 150, + items: [ + { + name: 'repeating', + id: 'repeating', + xtype: 'hidden', + value: config.record.repeating ? 1 : 0 }, - layout: 'form', - items :[{name: 'repeating',id: 'repeating',xtype:'hidden',value:config.record.repeating?1:0},{ - fieldLabel: _('mxcalendars.label_repeat_type') - ,name: 'repeattype' - ,id: 'repeattype' - ,xtype:'combo' - ,mode: 'local' - ,store: new Ext.data.ArrayStore({ - id: 0, - fields: ['v', 'measure'], - data: [[0, _('mxcalendars.label_daily')],[1, _('mxcalendars.label_weekly')],[2, _('mxcalendars.label_monthly')],[3, _('mxcalendars.label_yearly')]] - }) - ,triggerAction: 'all' - ,displayField: 'measure' - ,valueField: 'v' - ,editable: true - ,width: 150 - ,layout:'anchor' - ,anchor: '100% 100%' - ,value: config.record.repeattype - ,listeners:{select:{fn:function(combo, value) { - var rt = Ext.getCmp('repeattype'); - if(rt.getValue() === 1){ - Ext.getCmp('repeaton').show(); - } else { Ext.getCmp('repeaton').hide(); } - }} + { + fieldLabel: _('mxcalendars.label_repeat_type'), + name: 'repeattype', + id: 'repeattype', + xtype: 'combo', + mode: 'local', + margin: '0 10 0 0', + store: new Ext.data.ArrayStore({ + id: 0, + fields: ['v', 'measure'], + data: [[0, _('mxcalendars.label_daily')], [1, _('mxcalendars.label_weekly')], [2, _('mxcalendars.label_monthly')], [3, _('mxcalendars.label_yearly')]] + }), + triggerAction: 'all', + displayField: 'measure', + valueField: 'v', + editable: true, + width: 150, + layout: 'anchor', + anchor: '100% 100%', + value: config.record.repeattype, + listeners: { + select: { + fn: function (combo, value) { + let rt = Ext.getCmp('repeattype'); + if (rt.getValue() === 1) { + Ext.getCmp('repeaton').show(); + } else { + Ext.getCmp('repeaton').hide(); + } + } + } } - },{ - fieldLabel: _('mxcalendars.label_repeaton') - ,name: 'repeaton' - ,id: 'repeaton' - ,xtype: 'checkboxgroup' - ,hidden: config.record.repeattype == 1 ? false : true // hide on load - ,items: [ - {boxLabel: _('mxcalendars.label_sunday'), name: 'cb-auto-1', value: -1, checked: config.record.repeaton.indexOf(',-1,')!=-1 ? true : false }, - {boxLabel: _('mxcalendars.label_monday'), name: 'cb-auto-2', value: 0, checked: config.record.repeaton.indexOf(',0,')!=-1 ? true : false }, - {boxLabel: _('mxcalendars.label_tuesday'), name: 'cb-auto-3', value: 1, checked: config.record.repeaton.indexOf(',1,')!=-1 ? true : false }, - {boxLabel: _('mxcalendars.label_wednesday'), name: 'cb-auto-4', value: 2, checked: config.record.repeaton.indexOf(',2,')!=-1 ? true : false }, - {boxLabel: _('mxcalendars.label_thursday'), name: 'cb-auto-5', value: 3, checked: config.record.repeaton.indexOf(',3,')!=-1 ? true : false }, - {boxLabel: _('mxcalendars.label_friday'), name: 'cb-auto-6', value: 4, checked: config.record.repeaton.indexOf(',4,')!=-1 ? true : false }, - {boxLabel: _('mxcalendars.label_saturday'), name: 'cb-auto-7', value: 5, checked: config.record.repeaton.indexOf(',5,')!=-1 ? true : false } - ] + }, + { + fieldLabel: _('mxcalendars.label_repeaton'), + name: 'repeaton', + id: 'repeaton', + xtype: 'checkboxgroup', + hidden: config.record.repeattype == 1 ? false : true, // hide on load + items: [ + { + boxLabel: _('mxcalendars.label_sunday'), + name: 'cb-auto-1', + value: -1, + checked: config.record.repeaton.indexOf(',-1,') != -1 ? true : false + }, + { + boxLabel: _('mxcalendars.label_monday'), + name: 'cb-auto-2', + value: 0, + checked: config.record.repeaton.indexOf(',0,') != -1 ? true : false + }, + { + boxLabel: _('mxcalendars.label_tuesday'), + name: 'cb-auto-3', + value: 1, + checked: config.record.repeaton.indexOf(',1,') != -1 ? true : false + }, + { + boxLabel: _('mxcalendars.label_wednesday'), + name: 'cb-auto-4', + value: 2, + checked: config.record.repeaton.indexOf(',2,') != -1 ? true : false + }, + { + boxLabel: _('mxcalendars.label_thursday'), + name: 'cb-auto-5', + value: 3, + checked: config.record.repeaton.indexOf(',3,') != -1 ? true : false + }, + { + boxLabel: _('mxcalendars.label_friday'), + name: 'cb-auto-6', + value: 4, + checked: config.record.repeaton.indexOf(',4,') != -1 ? true : false + }, + { + boxLabel: _('mxcalendars.label_saturday'), + name: 'cb-auto-7', + value: 5, + checked: config.record.repeaton.indexOf(',5,') != -1 ? true : false + } + ] //,value: config.record.repeaton - },{ - fieldLabel: _('mxcalendars.label_repeat_frequency') - ,name: 'repeatfrequency' - ,id: 'repeatfrequency' - ,xtype: 'combo' - ,mode: 'local' - ,store: new Ext.data.ArrayStore({ - id: 0, - fields: ['counter'], - data: [[],[1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12],[13],[14],[15],[16],[17],[18],[19],[20],[21],[22],[23],[24],[25],[26],[27],[28],[29],[30]] - }) - ,displayField: 'counter' - ,valueField: 'counter' - ,editable: true - ,width: 50 - ,layout:'anchor' - ,anchor: '100% 100%' - ,value: config.record.repeatfrequency - ,msgTarget : 'crepeatfrequency' - ,msgDisplay: 'block' - ,listeners: { - render: function(c) { - Ext.QuickTips.register({ - target: c.getEl(), - text: _('mxcalendars.tip_repeaton') - }); + }, + { + fieldLabel: _('mxcalendars.label_repeat_frequency'), + name: 'repeatfrequency', + id: 'repeatfrequency', + xtype: 'combo', + mode: 'local', + store: new Ext.data.ArrayStore({ + id: 0, + fields: ['counter'], + data: [[], [1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12], [13], [14], [15], [16], [17], [18], [19], [20], [21], [22], [23], [24], [25], [26], [27], [28], [29], [30]] + }), + displayField: 'counter', + valueField: 'counter', + editable: true, + width: 50, + layout: 'anchor', + anchor: '100% 100%', + value: config.record.repeatfrequency, + msgTarget: 'crepeatfrequency', + msgDisplay: 'block', + listeners: { + render: function (c) { + Ext.QuickTips.register({ + target: c.getEl(), + text: _('mxcalendars.tip_repeaton') + }); } } - },{ - fieldLabel: _('mxcalendars.label_repeat_last_occurance') - ,name: 'repeatenddate' - ,id: 'repeatenddate' - ,format : mxcCore.config.mgr_dateformat - ,allowBlank:false - ,xtype: 'datefield' - ,value: config.record.repeatenddate - ,submitValue: false - ,width: 120 - ,layout:'anchor' - ,anchor: '100% 100%' - }] - },{ - xtype: 'container' - ,anchor: '100%' - ,layout: 'form' - ,items: [ - { - xtype:'tabpanel' - ,plain:true - ,activeTab: 0 - ,height:385 - ,width:840 - ,defaults:{bodyStyle:'padding:10px',layout:'form'} - ,items:[ - { - cls: 'x-plain', - title: _('mxcalendars.label_description'), - layout: 'fit', - items: { - xtype: mxcCore.config.event_desc_type == 'htmleditor' ? 'textarea' : mxcCore.config.event_desc_type - ,name: 'description' - ,hiddenName: 'description' - ,id: 'description-'+config.record.id - ,value: config.record.description - } - ,listeners:{ - activate : function(tabpanel){ - //if(MODx.config.use_editor && MODx.loadRTE && mxcCore.config.event_desc_type == 'htmleditor'){ - // MODx.loadRTE('description-'+config.record.id); - //} - - if (MODx.loadRTE) { - MODx.loadRTE('description-'+config.record.id); // Will transform the textarea with ID "description" to a RTE - // MODx.loadRTE(['description1','description2']); - } + }, + { + fieldLabel: _('mxcalendars.label_repeat_last_occurance'), + name: 'repeatenddate', + id: 'repeatenddate', + format: mxcCore.config.mgr_dateformat, + allowBlank: true, + xtype: 'datefield', + value: config.record.repeatenddate, + //submitValue: false, + width: 120, + //layout: 'anchor', + //anchor: '100% 100%', + } + ] + }, + { + xtype: 'container', + anchor: '100%', + layout: 'form', + items: [ + { + xtype: 'tabpanel', + plain: true, + activeTab: 0, + height: 385, + width: 840, + defaults: {bodyStyle: 'padding:10px', layout: 'form'}, + items: [ + { + cls: 'x-plain', + title: _('mxcalendars.label_description'), + layout: 'fit', + items: { + xtype: mxcCore.config.event_desc_type == 'htmleditor' ? 'textarea' : mxcCore.config.event_desc_type, + name: 'description', + hiddenName: 'description', + id: 'description-' + config.record.id, + value: config.record.description + }, + listeners: { + activate: function (tabpanel) { + //if(MODx.config.use_editor && MODx.loadRTE && mxcCore.config.event_desc_type == 'htmleditor'){ + // MODx.loadRTE('description-'+config.record.id); + //} + + if (MODx.loadRTE) { + MODx.loadRTE('description-' + config.record.id); // Will transform the textarea with ID "description" to a RTE + // MODx.loadRTE(['description1','description2']); + } - } } - },{ - cls: 'x-plain', - title: _('mxcalendars.label_content'), - layout: 'fit', - items: { - xtype: mxcCore.config.event_desc_type == 'htmleditor' ? 'textarea' : mxcCore.config.event_desc_type - ,name: 'content' - ,hiddenName: 'content' - ,id: 'content-'+config.record.id - ,value: config.record.content - } - ,listeners:{ - activate : function(tabpanel){ - if (MODx.config.use_editor && MODx.loadRTE){ - MODx.loadRTE('content-'+config.record.id); - } - } + } + }, + { + cls: 'x-plain', + title: _('mxcalendars.label_content'), + layout: 'fit', + items: { + xtype: mxcCore.config.event_desc_type == 'htmleditor' ? 'textarea' : mxcCore.config.event_desc_type, + name: 'content', + hiddenName: 'content', + id: 'content-' + config.record.id, + value: config.record.content + }, + listeners: { + activate: function (tabpanel) { + if (MODx.config.use_editor && MODx.loadRTE) { + MODx.loadRTE('content-' + config.record.id); + } } - },{ - cls: 'x-plain', - title: _('mxcalendars.label_images'), - layout: 'fit', - items: { - xtype: 'mxc-images-grid' - ,id: 'gridimages' - } - },{ - cls: 'x-plain', - title: _('mxcalendars.label_videos'), - layout: 'fit', - items: { - xtype: 'mxc-videos-grid' - ,id: 'gridvideos' - } - },{ - title: _('mxcalendars.label_location') - ,defaults: {width:230} - ,defaultType:'textfield' - ,items:[{ - fieldLabel:_('mxcalendars.label_name') - ,name:'location_name' - ,id: 'location_name' - ,value: config.record.location_name - },{ - fieldLabel:_('mxcalendars.label_address') - ,name:'location_address' - ,id:'location_address' - ,value: config.record.location_address - },{ - boxLabel: _('mxcalendars.label_display_map') - ,name:'map' - ,id:'map' - ,xtype:'checkbox' - ,checked: config.record.map ? true : false - }] - },{ - title:_('mxcalendars.label_link'), - defaults: {width: 230}, - defaultType: 'textfield', - items: [{ - fieldLabel: 'Link' - ,name: 'link' - ,id: 'link' - ,allowBlank:false - ,value: config.record.link - },{ - fieldLabel: _('mxcalendars.label_link_rel') - ,name: 'linkrel' - ,id: 'linkrel' - ,value: config.record.linkrel - },{ - fieldLabel: _('mxcalendars.label_link_target') - ,name: 'linktarget' - ,id: 'linktarget' - ,xtype: 'combo' - ,mode: 'local' - ,store: new Ext.data.ArrayStore({ - id: 0, - fields: ['tt'], - data: [['_self'],['_new'],['_blank']] - }) - ,triggerAction: 'all' - ,displayField: 'tt' - ,valueField: 'tt' - ,editable: true - ,width: 'auto' - ,anchor: '30%' - ,value: config.record.linktarget - }] - },{ - title:"Form" - ,defaults: {width:230} - ,items: [{ - xtype: 'combo', - displayField: 'name', - valueField: 'name', - forceSelection: true, - store: new Ext.data.JsonStore({ - root: 'results', - idProperty: 'name', - url: mxcCore.config.connectorUrl, - baseParams: { - action: 'stores/getformchunks' - }, - fields: [ - 'id','name','description', - ] - }), - mode: 'remote', - triggerAction: 'all', - fieldLabel: _('mxcalendars.grid_col_formchunk'), - name: 'form_chunk', - hiddenName: 'form_chunk', - id: 'form_chunk', - allowBlank: true, - typeAhead:true, - minChars:1, - emptyText:_('mxcalendars.label_select_form'), - valueNotFoundText:_('mxcalendars.label_select_form_err'), - anchor:'100%', - value: config.record.form_chunk - }] } - ] - } - ] - },{ - xtype: 'checkbox' - ,fieldLabel: _('mxcalendars.category_active_col_label') - ,id: 'active' - ,name: 'active' - ,hiddenName: 'active' - ,checked: config.record.active ? true : false - ,value: 1 + }, + { + cls: 'x-plain', + title: _('mxcalendars.label_images'), + layout: 'fit', + items: { + xtype: 'mxc-images-grid', + id: 'gridimages' + } + }, + { + cls: 'x-plain', + title: _('mxcalendars.label_videos'), + layout: 'fit', + items: { + xtype: 'mxc-videos-grid', + id: 'gridvideos' + } + }, + { + title: _('mxcalendars.label_location'), + defaults: {width: 230}, + defaultType: 'textfield', + items: [ + { + fieldLabel: _('mxcalendars.label_name'), + name: 'location_name', + id: 'location_name', + value: config.record.location_name + }, + { + fieldLabel: _('mxcalendars.label_address'), + name: 'location_address', + id: 'location_address', + value: config.record.location_address + }, + { + boxLabel: _('mxcalendars.label_display_map'), + name: 'map', + id: 'map', + xtype: 'checkbox', + checked: config.record.map ? true : false + } + ] + }, + { + title: _('mxcalendars.label_price'), + defaults: {width: 230}, + defaultType: 'textfield', + items: [{ + fieldLabel: _('mxcalendars.label_price'), + name: 'label_price', + id: 'price', + value: config.record.price + }] + }, + { + title: _('mxcalendars.label_food'), + defaults: {width: 230}, + defaultType: 'textfield', + items: [{ + fieldLabel: _('mxcalendars.label_food'), + name: 'label_food', + id: 'food', + value: config.record.food + }] + }, { + title: _('mxcalendars.label_age'), + defaults: {width: 230}, + defaultType: 'textfield', + items: [{ + fieldLabel: _('mxcalendars.label_age'), + name: 'label_age', + id: 'age', + value: config.record.age + }] + }, + { + title: _('mxcalendars.label_capacity'), + defaults: {width: 230}, + defaultType: 'textfield', + items: [{ + fieldLabel: _('mxcalendars.label_capacity'), + name: 'label_capacity', + id: 'capacity', + value: config.record.capacity + }] + }, + { + title: _('mxcalendars.label_link'), + defaults: {width: 230}, + defaultType: 'textfield', + items: [ + { + fieldLabel: 'Link', + name: 'link', + id: 'link', + allowBlank: true, + value: config.record.link + }, + //{ + // fieldLabel: _('mxcalendars.label_link_rel'), + // name: 'linkrel', + // id: 'linkrel', + // value: config.record.linkrel + // }, + { + fieldLabel: _('mxcalendars.label_link_target'), + name: 'linktarget', + id: 'linktarget', + xtype: 'combo', + mode: 'local', + store: new Ext.data.ArrayStore({ + id: 0, + fields: ['tt'], + data: [['_self'], ['_new'], ['_blank']] + }), + triggerAction: 'all', + displayField: 'tt', + valueField: 'tt', + editable: true, + width: 'auto', + anchor: '30%', + value: config.record.linktarget + } + ] + }, + { + title: "Form", + defaults: {width: 230}, + items: [{ + xtype: 'combo', + displayField: 'name', + valueField: 'name', + forceSelection: true, + store: new Ext.data.JsonStore({ + root: 'results', + idProperty: 'name', + url: mxcCore.config.connectorUrl, + baseParams: { + action: 'stores/getformchunks' + }, + fields: [ + 'id', 'name', 'description', + ] + }), + mode: 'remote', + triggerAction: 'all', + fieldLabel: _('mxcalendars.grid_col_formchunk'), + name: 'form_chunk', + hiddenName: 'form_chunk', + id: 'form_chunk', + allowBlank: true, + typeAhead: true, + minChars: 1, + emptyText: _('mxcalendars.label_select_form'), + valueNotFoundText: _('mxcalendars.label_select_form_err'), + anchor: '100%', + value: config.record.form_chunk + }] + } + ] } - ] - - ,buttons: [{ - text: _('mxcalendars.label_cancel') - ,type: 'close' - ,handler: function() - { - Ext.getCmp('UpdateCal').hide(); - } - },{ - text: _('mxcalendars.label_save') - ,handler: function(){ - var uidx = Ext.getCmp('id').getValue(); - var repeatDOW = ''; - var rawRepeatOn = Ext.getCmp('repeaton').getValue(); - //console.log("RepeatOn: "+rawRepeatOn.join(",")); - for (i = 0; i < rawRepeatOn.length; i++) { - repeatDOW += ','+rawRepeatOn[i].value; - //console.log(rawRepeatOn[i]); + ] + }, + { + xtype: 'checkbox', + fieldLabel: _('mxcalendars.category_active_col_label'), + id: 'active', + name: 'active', + hiddenName: 'active', + checked: config.record.active ? true : false, + value: 1 + } + ], + buttons: [ + { + text: _('mxcalendars.label_cancel'), + type: 'close', + handler: function () { + Ext.getCmp('UpdateCal').hide(); } - if(repeatDOW.length){repeatDOW+=',';} - //console.log("New RepeatON: "+repeatDOW); - var frmData = { - id: Ext.getCmp('id').getValue() - ,active: Ext.getCmp('active').getValue() === true ? 1 :0 - ,title: Ext.getCmp('title').getValue() - ,description: Ext.getCmp('description-'+uidx ).getValue() - ,content: Ext.getCmp('content-'+uidx ).getValue() - ,categoryid: Ext.getCmp('categoryid').getValue() - ,allday: Ext.getCmp('allday').getValue() === true ? 1 :0 - ,startdate_date: Ext.getCmp('startdate_date').getValue() - ,startdate_time: Ext.getCmp('startdate_time').getValue() - ,enddate_date: Ext.getCmp('enddate_date').getValue() - ,enddate_time: Ext.getCmp('enddate_time').getValue() - ,link: Ext.getCmp('link').getValue() - ,linkrel: Ext.getCmp('linkrel').getValue() - ,linktarget: Ext.getCmp('linktarget').getValue() - ,location_name: Ext.getCmp('location_name').getValue() - ,location_address: Ext.getCmp('location_address').getValue() - ,map: Ext.getCmp('map').checked ? 1 : 0 - ,repeating: Ext.getCmp('repeating').getValue() - ,repeattype: Ext.getCmp('repeattype').getValue() - ,repeaton: repeatDOW //Ext.getCmp('repeaton').getValue() - ,repeatfrequency: Ext.getCmp('repeatfrequency').getValue() - ,repeatenddate: Ext.getCmp('repeatenddate').getValue() - ,context: Ext.getCmp('context').getValue() - ,calendar_id: Ext.getCmp('calendar_id').getValue() - ,form_chunk: Ext.getCmp('form_chunk').getValue() - ,source: Ext.getCmp('source').getValue() + }, + { + text: _('mxcalendars.label_save'), + handler: function () { + let uidx = Ext.getCmp('id').getValue(); + let repeatDOW = ''; + let rawRepeatOn = Ext.getCmp('repeaton').getValue(); + //console.log("RepeatOn: "+rawRepeatOn.join(",")); + for (i = 0; i < rawRepeatOn.length; i++) { + repeatDOW += ',' + rawRepeatOn[i].value; + //console.log(rawRepeatOn[i]); + } + if (repeatDOW.length) { + repeatDOW += ','; + } + //console.log("New RepeatON: "+repeatDOW); + let frmData = { + id: Ext.getCmp('id').getValue(), + active: Ext.getCmp('active').getValue() === true ? 1 : 0, + title: Ext.getCmp('title').getValue(), + description: Ext.getCmp('description-' + uidx).getValue(), + content: Ext.getCmp('content-' + uidx).getValue(), + categoryid: Ext.getCmp('categoryid').getValue(), + allday: Ext.getCmp('allday').getValue() === true ? 1 : 0, + startdate_date: Ext.getCmp('startdate_date').getValue(), + startdate_time: Ext.getCmp('startdate_time').getValue(), + enddate_date: Ext.getCmp('enddate_date').getValue(), + enddate_time: Ext.getCmp('enddate_time').getValue(), + link: Ext.getCmp('link').getValue(), + //, linkrel: Ext.getCmp('linkrel').getValue(), + linktarget: Ext.getCmp('linktarget').getValue(), + location_name: Ext.getCmp('location_name').getValue(), + location_address: Ext.getCmp('location_address').getValue(), + map: Ext.getCmp('map').checked ? 1 : 0, + price: Ext.getCmp('price').getValue(), + food: Ext.getCmp('food').getValue(), + age: Ext.getCmp('age').getValue(), + capacity: Ext.getCmp('capacity').getValue(), + repeating: Ext.getCmp('repeating').getValue(), + repeattype: Ext.getCmp('repeattype').getValue(), + repeaton: repeatDOW, //Ext.getCmp('repeaton').getValue() + repeatfrequency: Ext.getCmp('repeatfrequency').getValue(), + repeatenddate: Ext.getCmp('repeatenddate').getValue(), + context: Ext.getCmp('context').getValue(), + calendar_id: Ext.getCmp('calendar_id').getValue(), + form_chunk: Ext.getCmp('form_chunk').getValue(), + source: Ext.getCmp('source').getValue(), // @TODO move to proper config section - ,HTTP_MODAUTH: MODx.siteId - ,action: 'mgr/events/update' - }; - - //console.log("frmData: "+frmData); - - mxcCore.ajax.request({ - url: mxcCore.config.connectorUrl, + HTTP_MODAUTH: MODx.siteId, + action: 'mgr/events/update' + }; + + //console.log("frmData: "+frmData); + + mxcCore.ajax.request({ + url: mxcCore.config.connectorUrl, extraParams: { - //action: 'mgr/events/update' - }, - params: frmData, - scope: this, - success: function(resp, opts) { - // remove the RTE instances - if (MODx.config.use_editor && MODx.loadRTE && typeof tinyMCE !== 'undefined'){ - if(typeof tinyMCE !== "undefined"){ - tinyMCE.execCommand('mceRemoveControl',false, 'description-'+frmData.id); - tinyMCE.execCommand('mceRemoveControl',false, 'content-'+frmData.id); - } + //action: 'mgr/events/update' + }, + params: frmData, + scope: this, + success: function (resp, opts) { + // remove the RTE instances + if (MODx.config.use_editor && MODx.loadRTE && typeof tinyMCE !== 'undefined') { + if (typeof tinyMCE !== "undefined") { + tinyMCE.execCommand('mceRemoveControl', false, 'description-' + frmData.id); + tinyMCE.execCommand('mceRemoveControl', false, 'content-' + frmData.id); } + } // resp is the XmlHttpRequest object - var status = Ext.decode(resp.responseText).success; - if(!status){ - Ext.Msg.alert("Error",Ext.decode(resp.responseText).message); - } else { - //Ext.Msg.alert('Update Event', 'Your event data is: '); - Ext.getCmp('UpdateCal').hide(); - Ext.getCmp('mxcalendars-grid-events').refresh(); - } - }, - }); - - } - }] + let status = Ext.decode(resp.responseText).success; + if (!status) { + Ext.Msg.alert("Error", Ext.decode(resp.responseText).message); + } else { + //Ext.Msg.alert('Update Event', 'Your event data is: '); + Ext.getCmp('UpdateCal').hide(); + Ext.getCmp('mxcalendars-grid-events').refresh(); + } + }, + }); + + } + } + ] }); - mxcCore.window.UpdateCal.superclass.constructor.call(this,config); - - this.on('deactivate',function(w,e) { - if(MODx.config.use_editor && MODx.loadRTE && typeof tinyMCE !== 'undefined'){ - tinyMCE.execCommand('mceRemoveControl',false, 'description-'+config.record.id); - tinyMCE.execCommand('mceRemoveControl',false, 'content-'+config.record.id); + mxcCore.window.UpdateCal.superclass.constructor.call(this, config); + + this.on('deactivate', function (w, e) { + if (MODx.config.use_editor && MODx.loadRTE && typeof tinyMCE !== 'undefined') { + tinyMCE.execCommand('mceRemoveControl', false, 'description-' + config.record.id); + tinyMCE.execCommand('mceRemoveControl', false, 'content-' + config.record.id); } - },this); - - + }, this); + + }; -Ext.extend(mxcCore.window.UpdateCal,Ext.Window); -Ext.reg('mxcalendars-window-mxcalendar-update',mxcCore.window.UpdateCal); +Ext.extend(mxcCore.window.UpdateCal, Ext.Window); +Ext.reg('mxcalendars-window-mxcalendar-update', mxcCore.window.UpdateCal); Ext.QuickTips.init(); \ No newline at end of file diff --git a/assets/components/mxcalendars/js/mgr/widgets/mxcalendars.images.grid.js b/assets/components/mxcalendars/js/mgr/widgets/mxcalendars.images.grid.js index b12aa86..0801b9b 100644 --- a/assets/components/mxcalendars/js/mgr/widgets/mxcalendars.images.grid.js +++ b/assets/components/mxcalendars/js/mgr/widgets/mxcalendars.images.grid.js @@ -1,105 +1,125 @@ mxcCore.grid.Images = function(config) { config = config || {}; - Ext.applyIf(config,{ - id: 'mxc-images-grid' - ,url: mxcCore.config.connectorUrl - ,baseParams: { action: 'mgr/images/getList', eventid: mxcCore.eventId } - ,fields: ['id','event_id','filepath','title','description','active'] - ,paging: true - ,remoteSort: true - ,anchor: '97%' - ,autoExpandColumn: 'title' - ,save_action: 'mgr/images/updatefromgrid' // Support the inline editing - ,autosave: true // Support the inline editing - ,columns: [{ - header: _('id') - ,dataIndex: 'id' - ,sortable: true - },{ - header: _('mxcalendars.tab_events')+' '+_('id') - ,dataIndex: 'event_id' - ,sortable: true - ,display: false - ,hidden: true - },{ - header: _('mxcalendars.image_filepath') - ,dataIndex: 'filepath' - ,sortable: true - ,editor: { xtype: 'textfield' } - },{ - header: _('mxcalendars.grid_col_title') - ,dataIndex: 'title' - ,sortable: true - ,editor: { xtype: 'textfield' } - },{ - header: _('mxcalendars.description') - ,dataIndex: 'description' - ,sortable: true - ,editor: { xtype: 'textfield' } - },{ - header: _('mxcalendars.category_active_col_label') - ,dataIndex: 'active' - ,sortable: true - ,editor: { xtype: 'modx-combo-boolean', renderer: true} - }],tbar:[{ - xtype: 'textfield' - ,id: 'mxcalendars-search-images-filter' - ,emptyText:_('mxcalendars.default_search') - ,listeners: { - 'change': {fn:this.search,scope:this} - ,'render': {fn: function(cmp) { - new Ext.KeyMap(cmp.getEl(), { - key: Ext.EventObject.ENTER - ,fn: function() { - this.fireEvent('change',this); - this.blur(); - return true; - } - ,scope: cmp - }); - },scope:this} - } - },'->',{ - text:_('mxcalendars.btn_create_image') - ,handler: function(btn,e) { - if (this.createImageWindow) { - this.createImageWindow.close(); - } - this.createImageWindow = MODx.load({ - xtype: 'mxcalendars-window-image-create' - ,blankValues: true - ,listeners: { - 'success': {fn:this.refresh,scope:this} - } - }); - this.createImageWindow.show(e.target); + Ext.applyIf(config, { + id: 'mxc-images-grid', + url: mxcCore.config.connectorUrl, + baseParams: { action: 'mgr/images/getList', eventid: mxcCore.eventId }, + fields: ['id','event_id','filepath','title','description','active'], + paging: true, + remoteSort: true, + anchor: '97%', + autoExpandColumn: 'title', + save_action: 'mgr/images/updatefromgrid', // Support the inline editing + autosave: true, // Support the inline editing + columns: [ + { + header: _('id'), + dataIndex: 'id', + sortable: true + }, + { + header: _('mxcalendars.tab_events')+' '+_('id'), + dataIndex: 'event_id', + sortable: true, + display: false, + hidden: true + }, + { + header: _('mxcalendars.image_filepath'), + dataIndex: 'filepath', + sortable: true, + editor: { xtype: 'textfield' } + }, + { + header: _('mxcalendars.grid_col_title'), + dataIndex: 'title', + sortable: true, + editor: { xtype: 'textfield' } + }, + { + header: _('mxcalendars.description'), + dataIndex: 'description', + sortable: true, + editor: { xtype: 'textfield' } + }, + { + header: _('mxcalendars.category_active_col_label'), + dataIndex: 'active', + sortable: true, + editor: { xtype: 'modx-combo-boolean', renderer: true} + } + ], + tbar:[ + { + xtype: 'textfield', + id: 'mxcalendars-search-images-filter', + emptyText:_('mxcalendars.default_search'), + listeners: { + 'change': {fn:this.search,scope:this}, + 'render': { + fn: function(cmp) { + new Ext.KeyMap(cmp.getEl(), { + key: Ext.EventObject.ENTER, + fn: function() { + this.fireEvent('change',this); + this.blur(); + return true; + }, + scope: cmp + }); + }, + scope:this + } + } + },'->', + { + text:_('mxcalendars.btn_create_image'), + handler: function(btn,e) { + if (this.createImageWindow) { + this.createImageWindow.close(); } - }] + this.createImageWindow = MODx.load({ + xtype: 'mxcalendars-window-image-create', + blankValues: true, + listeners: { + 'success': {fn:this.refresh,scope:this} + } + }); + this.createImageWindow.show(e.target); + } + } + ] }); - mxcCore.grid.Images.superclass.constructor.call(this,config) + mxcCore.grid.Images.superclass.constructor.call(this,config); }; + Ext.extend(mxcCore.grid.Images,MODx.grid.Grid,{ search: function(tf,nv,ov) { - var s = this.getStore(); + let s = this.getStore(); s.baseParams.query = tf.getValue(); this.getBottomToolbar().changePage(1); this.refresh(); - },getMenu: function() { - var m = [{ - text: _('mxcalendars.menu_update') - ,handler: this.updateImage - },'-',{ - text: _('mxcalendars.menu_remove') - ,handler: this.removeImage - }]; + }, + getMenu: function() { + let m = [ + { + text: _('mxcalendars.menu_update'), + handler: this.updateImage + },'-', + { + text: _('mxcalendars.menu_remove'), + handler: this.removeImage + } + ]; this.addContextMenuItem(m); return true; - },updateImage: function(btn,e) { + }, + updateImage: function(btn,e) { if (!this.updateImageWindow) { this.updateImageWindow = MODx.load({ - xtype: 'mxcalendars-window-image-update' - ,record: this.menu.record - ,listeners: { + xtype: 'mxcalendars-window-image-update', + record: this.menu.record, + listeners: { 'success': {fn:this.refresh,scope:this} } }); @@ -107,16 +127,17 @@ Ext.extend(mxcCore.grid.Images,MODx.grid.Grid,{ this.updateImageWindow.setValues(this.menu.record); } this.updateImageWindow.show(e.target); - },removeImage: function() { + }, + removeImage: function() { MODx.msg.confirm({ - title: _('mxcalendars.cateogry_remove_title') - ,text: _('mxcalendars.cateogry_remove_confirm') - ,url: this.config.url - ,params: { - action: 'mgr/images/remove' - ,id: this.menu.record.id - } - ,listeners: { + title: _('mxcalendars.image_remove_title'), + text: _('mxcalendars.image_remove_confirm'), + url: this.config.url, + params: { + action: 'mgr/images/remove', + id: this.menu.record.id + }, + listeners: { 'success': {fn:this.refresh,scope:this} } }); @@ -132,35 +153,49 @@ Ext.reg('mxc-images-grid',mxcCore.grid.Images); mxcCore.window.UpdateImage = function(config) { config = config || {}; Ext.applyIf(config,{ - title: _('mxcalendars.label_update')+' '+_('mxcalendars.label_select_image') - ,url: mxcCore.config.connectorUrl - ,width: 650 - ,baseParams: { + title: _('mxcalendars.label_update') + ' ' + _('mxcalendars.label_select_image'), + url: mxcCore.config.connectorUrl, + width: 650, + baseParams: { action: 'mgr/images/update' - } - ,fields: [{xtype:'hidden',name:'id'},{xtype:'hidden',name:'event_id', value: mxcCore.eventId},{ - xtype: 'textfield' - ,fieldLabel:_('mxcalendars.grid_col_title') - ,name: 'title' - ,anchor: '50%' - ,width: '50%' - },{ - xtype: 'textarea' - ,fieldLabel: _('mxcalendars.description') - ,name: 'description' - ,anchor: '100%' - ,width: '100%' - },{ - xtype: 'modx-combo-browser' - ,fieldLabel: _('mxcalendars.label_select_image') - ,name: 'filepath' - },{ - xtype: 'checkbox' - ,fieldLabel: _('mxcalendars.category_active_col_label') - ,name: 'active' - ,checked: true - ,value: 1 - }] + }, + fields: [ + { + xtype:'hidden', + name:'id' + }, + { + xtype:'hidden', + name:'event_id', + value: mxcCore.eventId + }, + { + xtype: 'textfield', + fieldLabel:_('mxcalendars.grid_col_title'), + name: 'title', + anchor: '50%', + width: '50%' + }, + { + xtype: 'textarea', + fieldLabel: _('mxcalendars.description'), + name: 'description', + anchor: '100%', + width: '100%' + }, + { + xtype: 'modx-combo-browser', + fieldLabel: _('mxcalendars.label_select_image'), + name: 'filepath' + }, + { + xtype: 'checkbox', + fieldLabel: _('mxcalendars.category_active_col_label'), + name: 'active', + checked: true, + value: 1 + } + ] }); mxcCore.window.UpdateImage.superclass.constructor.call(this,config); }; @@ -175,39 +210,49 @@ Ext.reg('mxcalendars-window-image-update',mxcCore.window.UpdateImage); mxcCore.window.CreateImage = function(config) { config = config || {}; Ext.applyIf(config,{ - title: _('mxcalendars.label_create')+' '+_('mxcalendars.label_select_image') - ,url: mxcCore.config.connectorUrl - ,fileUpload: true - ,autoHeight: false - ,height: Ext.getBody().getViewSize().height*.85 - ,width: 650 - ,autoScroll: true - ,baseParams: { + title: _('mxcalendars.label_create') + ' ' + _('mxcalendars.label_select_image'), + url: mxcCore.config.connectorUrl, + fileUpload: true, + autoHeight: false, + height: Ext.getBody().getViewSize().height * 0.85, + width: 650, + autoScroll: true, + baseParams: { action: 'mgr/images/create' - } - ,fields: [{xtype:'hidden',name:'event_id', value: mxcCore.eventId},{ - xtype: 'textfield' - ,fieldLabel:_('mxcalendars.grid_col_title') - ,name: 'title' - ,anchor: '50%' - ,width: '50%' - },{ - xtype: 'textarea' - ,fieldLabel: _('mxcalendars.description') - ,name: 'description' - ,anchor: '100%' - ,width: '100%' - },{ - xtype: 'modx-combo-browser' - ,fieldLabel: _('mxcalendars.label_select_image') - ,name: 'filepath' - },{ - xtype: 'checkbox' - ,fieldLabel: _('mxcalendars.category_active_col_label') - ,name: 'active' - ,checked: true - ,value: 1 - }] + }, + fields: [ + { + xtype:'hidden', + name:'event_id', + value: mxcCore.eventId + }, + { + xtype: 'textfield', + fieldLabel:_('mxcalendars.grid_col_title'), + name: 'title', + anchor: '50%', + width: '50%' + }, + { + xtype: 'textarea', + fieldLabel: _('mxcalendars.description'), + name: 'description', + anchor: '100%', + width: '100%' + }, + { + xtype: 'modx-combo-browser', + fieldLabel: _('mxcalendars.label_select_image'), + name: 'filepath' + }, + { + xtype: 'checkbox', + fieldLabel: _('mxcalendars.category_active_col_label'), + name: 'active', + checked: true, + value: 1 + } + ] }); mxcCore.window.CreateImage.superclass.constructor.call(this,config); }; diff --git a/assets/components/mxcalendars/js/mgr/widgets/mxcalendars.videos.grid.js b/assets/components/mxcalendars/js/mgr/widgets/mxcalendars.videos.grid.js index bbe43c4..0bde8ea 100644 --- a/assets/components/mxcalendars/js/mgr/widgets/mxcalendars.videos.grid.js +++ b/assets/components/mxcalendars/js/mgr/widgets/mxcalendars.videos.grid.js @@ -1,93 +1,113 @@ mxcCore.grid.Videos = function(config) { config = config || {}; Ext.applyIf(config,{ - id: 'mxc-videos-grid' - ,url: mxcCore.config.connectorUrl - ,baseParams: { action: 'mgr/videos/getList', eventid: mxcCore.eventId } - ,fields: ['id','event_id','video','title','description','active'] - ,paging: true - ,remoteSort: true - ,anchor: '97%' - ,autoExpandColumn: 'title' - ,save_action: 'mgr/videos/updatefromgrid' // Support the inline editing - ,autosave: true // Support the inline editing - ,columns: [{ - header: _('id') - ,dataIndex: 'id' - ,sortable: true - },{ - header: _('mxcalendars.tab_events')+' '+_('id') - ,dataIndex: 'event_id' - ,sortable: true - ,display: false - ,hidden: true - },{ - header: _('mxcalendars.video_filepath') - ,dataIndex: 'video' - ,sortable: true - ,editor: { xtype: 'textfield' } - },{ - header: _('mxcalendars.grid_col_title') - ,dataIndex: 'title' - ,sortable: true - ,editor: { xtype: 'textfield' } - },{ - header: _('mxcalendars.description') - ,dataIndex: 'description' - ,sortable: true - ,editor: { xtype: 'textfield' } - },{ - header: _('mxcalendars.category_active_col_label') - ,dataIndex: 'active' - ,sortable: true - ,editor: { xtype: 'modx-combo-boolean', renderer: true} - }],tbar:[{ - xtype: 'textfield' - ,id: 'mxcalendars-search-videos-filter' - ,emptyText:_('mxcalendars.default_search') - ,listeners: { - 'change': {fn:this.search,scope:this} - ,'render': {fn: function(cmp) { - new Ext.KeyMap(cmp.getEl(), { - key: Ext.EventObject.ENTER - ,fn: function() { - this.fireEvent('change',this); - this.blur(); - return true; - } - ,scope: cmp - }); - },scope:this} - } - },'->',{ - text:_('mxcalendars.btn_create_video') - ,handler: { xtype: 'mxcalendars-window-video-create' ,blankValues: true } - }] + id: 'mxc-videos-grid', + url: mxcCore.config.connectorUrl, + baseParams: { action: 'mgr/videos/getList', eventid: mxcCore.eventId }, + fields: ['id','event_id','video','title','description','active'], + paging: true, + remoteSort: true, + anchor: '97%', + autoExpandColumn: 'title', + save_action: 'mgr/videos/updatefromgrid', // Support the inline editing + autosave: true, // Support the inline editing + columns: [ + { + header: _('id'), + dataIndex: 'id', + sortable: true + }, + { + header: _('mxcalendars.tab_events')+' '+_('id'), + dataIndex: 'event_id', + sortable: true, + display: false, + hidden: true + }, + { + header: _('mxcalendars.video_filepath'), + dataIndex: 'video', + sortable: true, + editor: { xtype: 'textfield' } + }, + { + header: _('mxcalendars.grid_col_title'), + dataIndex: 'title', + sortable: true, + editor: { xtype: 'textfield' } + }, + { + header: _('mxcalendars.description'), + dataIndex: 'description', + sortable: true, + editor: { xtype: 'textfield' } + }, + { + header: _('mxcalendars.category_active_col_label'), + dataIndex: 'active', + sortable: true, + editor: { xtype: 'modx-combo-boolean', renderer: true} + } + ], + tbar:[ + { + xtype: 'textfield', + id: 'mxcalendars-search-videos-filter', + emptyText:_('mxcalendars.default_search'), + listeners: { + 'change': {fn:this.search,scope:this}, + 'render': { + fn: function(cmp) { + new Ext.KeyMap(cmp.getEl(), { + key: Ext.EventObject.ENTER, + fn: function() { + this.fireEvent('change',this); + this.blur(); + return true; + }, + scope: cmp + }); + }, + scope:this + } + } + },'->', + { + text:_('mxcalendars.btn_create_video'), + handler: { xtype: 'mxcalendars-window-video-create' ,blankValues: true } + } + ] }); - mxcCore.grid.Videos.superclass.constructor.call(this,config) + mxcCore.grid.Videos.superclass.constructor.call(this,config); }; + Ext.extend(mxcCore.grid.Videos,MODx.grid.Grid,{ search: function(tf,nv,ov) { - var s = this.getStore(); + let s = this.getStore(); s.baseParams.query = tf.getValue(); this.getBottomToolbar().changePage(1); this.refresh(); - },getMenu: function() { - var m = [{ - text: _('mxcalendars.menu_update') - ,handler: this.updateImage - },'-',{ - text: _('mxcalendars.menu_remove') - ,handler: this.removeImage - }]; + }, + getMenu: function() { + let m = [ + { + text: _('mxcalendars.menu_update'), + handler: this.updateImage + },'-', + { + text: _('mxcalendars.menu_remove'), + handler: this.removeImage + } + ]; this.addContextMenuItem(m); return true; - },updateImage: function(btn,e) { + }, + updateImage: function(btn,e) { if (!this.updateImageWindow) { this.updateImageWindow = MODx.load({ - xtype: 'mxcalendars-window-video-update' - ,record: this.menu.record - ,listeners: { + xtype: 'mxcalendars-window-video-update', + record: this.menu.record, + listeners: { 'success': {fn:this.refresh,scope:this} } }); @@ -95,16 +115,17 @@ Ext.extend(mxcCore.grid.Videos,MODx.grid.Grid,{ this.updateImageWindow.setValues(this.menu.record); } this.updateImageWindow.show(e.target); - },removeImage: function() { + }, + removeImage: function() { MODx.msg.confirm({ - title: _('mxcalendars.cateogry_remove_title') - ,text: _('mxcalendars.cateogry_remove_confirm') - ,url: this.config.url - ,params: { - action: 'mgr/category/remove' - ,id: this.menu.record.id - } - ,listeners: { + title: _('mxcalendars.video_remove_title'), + text: _('mxcalendars.video_remove_confirm'), + url: this.config.url, + params: { + action: 'mgr/videos/remove', + id: this.menu.record.id + }, + listeners: { 'success': {fn:this.refresh,scope:this} } }); @@ -116,86 +137,107 @@ Ext.reg('mxc-videos-grid',mxcCore.grid.Videos); //---------------------------------------// //-- Create the Update Videos Window --// //---------------------------------------// - mxcCore.window.UpdateVideo = function(config) { config = config || {}; Ext.applyIf(config,{ - title: _('mxcalendars.label_update')+' '+_('mxcalendars.label_select_video') - ,url: mxcCore.config.connectorUrl - ,width: 650 - ,baseParams: { + title: _('mxcalendars.label_update') + ' ' + _('mxcalendars.label_select_video'), + url: mxcCore.config.connectorUrl, + width: 650, + baseParams: { action: 'mgr/videos/update' - } - ,fields: [{xtype:'hidden',name:'id'},{xtype:'hidden',name:'event_id', value: mxcCore.eventId},{ - xtype: 'textfield' - ,fieldLabel:_('mxcalendars.grid_col_title') - ,name: 'title' - ,anchor: '50%' - ,width: '50%' - },{ - xtype: 'textarea' - ,fieldLabel: _('mxcalendars.description') - ,name: 'description' - ,anchor: '100%' - ,width: '100%' - },{ - xtype: 'textfield' //'modx-combo-browser' - ,fieldLabel: _('mxcalendars.label_select_video') - ,name: 'video' - },{ - xtype: 'checkbox' - ,fieldLabel: _('mxcalendars.category_active_col_label') - ,name: 'active' - ,checked: true - ,value: 1 - }] + }, + fields: [ + { + xtype:'hidden', + name:'id' + }, + { + xtype:'hidden', + name:'event_id', + value: mxcCore.eventId + }, + { + xtype: 'textfield', + fieldLabel:_('mxcalendars.grid_col_title'), + name: 'title', + anchor: '50%', + width: '50%' + }, + { + xtype: 'textarea', + fieldLabel: _('mxcalendars.description'), + name: 'description', + anchor: '100%', + width: '100%' + }, + { + xtype: 'textfield', //'modx-combo-browser' + fieldLabel: _('mxcalendars.label_select_video'), + name: 'video' + }, + { + xtype: 'checkbox', + fieldLabel: _('mxcalendars.category_active_col_label'), + name: 'active', + checked: true, + value: 1 + } + ] }); mxcCore.window.UpdateVideo.superclass.constructor.call(this,config); }; Ext.extend(mxcCore.window.UpdateVideo,MODx.Window); Ext.reg('mxcalendars-window-video-update',mxcCore.window.UpdateVideo); - - //-------------------------------------------// //-- Create the object for the new video --// //-------------------------------------------// mxcCore.window.CreateVideo = function(config) { config = config || {}; Ext.applyIf(config,{ - title: _('mxcalendars.label_create')+' '+_('mxcalendars.label_select_video') - ,url: mxcCore.config.connectorUrl - ,fileUpload: true - ,autoHeight: false - ,height: Ext.getBody().getViewSize().height*.85 - ,width: 650 - ,autoScroll: true - ,baseParams: { + title: _('mxcalendars.label_create') + ' ' + _('mxcalendars.label_select_video'), + url: mxcCore.config.connectorUrl, + fileUpload: true, + autoHeight: false, + height: Ext.getBody().getViewSize().height * 0.85, + width: 650, + autoScroll: true, + baseParams: { action: 'mgr/videos/create' - } - ,fields: [{xtype:'hidden',name:'event_id', value: mxcCore.eventId},{ - xtype: 'textfield' - ,fieldLabel:_('mxcalendars.grid_col_title') - ,name: 'title' - ,anchor: '50%' - ,width: '50%' - },{ - xtype: 'textarea' - ,fieldLabel: _('mxcalendars.description') - ,name: 'description' - ,anchor: '100%' - ,width: '100%' - },{ - xtype: 'textfield' //'modx-combo-browser' - ,fieldLabel: _('mxcalendars.label_select_video') - ,name: 'video' - },{ - xtype: 'checkbox' - ,fieldLabel: _('mxcalendars.category_active_col_label') - ,name: 'active' - ,checked: true - ,value: 1 - }] + }, + fields: [ + { + xtype:'hidden', + name:'event_id', + value: mxcCore.eventId + }, + { + xtype: 'textfield', + fieldLabel:_('mxcalendars.grid_col_title'), + name: 'title', + anchor: '50%', + width: '50%' + }, + { + xtype: 'textarea', + fieldLabel: _('mxcalendars.description'), + name: 'description', + anchor: '100%', + width: '100%' + }, + { + xtype: 'textfield', //'modx-combo-browser' + fieldLabel: _('mxcalendars.label_select_video'), + name: 'video' + }, + { + xtype: 'checkbox', + fieldLabel: _('mxcalendars.category_active_col_label'), + name: 'active', + checked: true, + value: 1 + } + ] }); mxcCore.window.CreateVideo.superclass.constructor.call(this,config); }; diff --git a/core/components/mxcalendars/controllers/home.class.php b/core/components/mxcalendars/controllers/home.class.php new file mode 100644 index 0000000..83c86ed --- /dev/null +++ b/core/components/mxcalendars/controllers/home.class.php @@ -0,0 +1,50 @@ + + */ + +require_once dirname(__DIR__) . '/index.class.php'; + +class mxcalendarsHomeManagerController extends mxcalendarsBaseManagerController +{ + public function process(array $scriptProperties = array()) { + + } + /** + * @access public. + */ + public function loadCustomCssJs() + { + $this->addJavascript($this->mxCalendars->config['jsUrl'] . 'mgr/widgets/home.panel.js'); + + $this->addJavascript($this->mxCalendars->config['jsUrl'] . 'mgr/widgets/mxcalendars.grid.js'); + $this->addJavascript($this->mxCalendars->config['jsUrl'] . 'mgr/widgets/mxcalendars.categories.grid.js'); + $this->addJavascript($this->mxCalendars->config['jsUrl'] . 'mgr/widgets/mxcalendars.calendars.grid.js'); + $this->addJavascript($this->mxCalendars->config['jsUrl'] . 'mgr/widgets/mxcalendars.images.grid.js'); + $this->addJavascript($this->mxCalendars->config['jsUrl'] . 'mgr/widgets/mxcalendars.videos.grid.js'); + $this->addJavascript($this->mxCalendars->config['jsUrl'] . 'mgr/widgets/mxcalendars.feed.grid.js'); + + $this->addLastJavascript($this->mxCalendars->config['jsUrl'] . 'mgr/sections/home.js'); + } + + /** + * @access public. + * @return String. + */ + public function getPageTitle() + { + return $this->modx->lexicon('mxcalendars'); + } + + /** + * @access public. + * @return String. + */ + public function getTemplateFile() + { + return $this->mxCalendars->config['templates_path'] . 'home.tpl'; + } +} \ No newline at end of file diff --git a/core/components/mxcalendars/controllers/index.php b/core/components/mxcalendars/controllers/index.php deleted file mode 100644 index 29992a2..0000000 --- a/core/components/mxcalendars/controllers/index.php +++ /dev/null @@ -1,7 +0,0 @@ -initialize('mgr'); - -?> diff --git a/core/components/mxcalendars/controllers/mgr/header.php b/core/components/mxcalendars/controllers/mgr/header.php deleted file mode 100644 index 704b617..0000000 --- a/core/components/mxcalendars/controllers/mgr/header.php +++ /dev/null @@ -1,11 +0,0 @@ -regClientStartupScript($mxcalendars->config['jsUrl'].'mgr/mxcalendars.js'); -$modx->regClientStartupHTMLBlock(''); -return ''; - -?> diff --git a/core/components/mxcalendars/controllers/mgr/index.php b/core/components/mxcalendars/controllers/mgr/index.php deleted file mode 100644 index 3632927..0000000 --- a/core/components/mxcalendars/controllers/mgr/index.php +++ /dev/null @@ -1,77 +0,0 @@ -regClientStartupScript($mxcalendars->config['jsUrl'].'mgr/widgets/mxcalendars.videos.grid.js'); -$modx->regClientStartupScript($mxcalendars->config['jsUrl'].'mgr/widgets/mxcalendars.images.grid.js'); -$modx->regClientStartupScript($mxcalendars->config['jsUrl'].'mgr/widgets/mxcalendars.grid.js'); -$modx->regClientStartupScript($mxcalendars->config['jsUrl'].'mgr/widgets/mxcalendars.categories.grid.js'); -$modx->regClientStartupScript($mxcalendars->config['jsUrl'].'mgr/widgets/mxcalendars.calendars.grid.js'); -$modx->regClientStartupScript($mxcalendars->config['jsUrl'].'mgr/widgets/mxcalendars.feed.grid.js'); -$modx->regClientStartupScript($mxcalendars->config['jsUrl'].'mgr/widgets/home.panel.js'); -$modx->regClientStartupScript($mxcalendars->config['jsUrl'].'mgr/sections/index.js'); - -/* If we want to use Tiny, we'll need some extra files. */ -$useRTE = $modx->getOption('mxcalendars.use_richtext',$mxcalendars->config,false); -$whichEditor = $this->modx->getOption('which_editor'); -$onRichTextEditorInit = ''; - -if ($useRTE) { - - if($whichEditor === 'TinyMCE'){ - $tinyCorePath = $modx->getOption('tiny.core_path',null,$modx->getOption('core_path').'components/tinymce/'); - if (file_exists($tinyCorePath.'tinymce.class.php')) { - - /* First fetch the mxcalendarstiny specific settings */ - $cb1 = $modx->getOption('mxcalendars.tiny.buttons1'); - $cb2 = $modx->getOption('mxcalendars.tiny.buttons2'); - $cb3 = $modx->getOption('mxcalendars.tiny.buttons3'); - $cb4 = $modx->getOption('mxcalendars.tiny.buttons4'); - $cb5 = $modx->getOption('mxcalendars.tiny.buttons5'); - $plugins = $modx->getOption('mxcalendars.tiny.custom_plugins'); - $theme = $modx->getOption('mxcalendars.tiny.theme'); - $bfs = $modx->getOption('mxcalendars.tiny.theme_advanced_blockformats'); - $css = $modx->getOption('mxcalendars.tiny.theme_advanced_css_selectors'); - - /* If the settings are empty, override them with the generic tinymce settings. */ - $tinyProperties = array( - 'height' => $modx->getOption('mxcalendars.tiny.height',null,200), - 'width' => $modx->getOption('mxcalendars.tiny.width',null,400), - 'tiny.custom_buttons1' => (!empty($cb1)) ? $cb1 : $modx->getOption('tiny.custom_buttons1'), - 'tiny.custom_buttons2' => (!empty($cb2)) ? $cb2 : $modx->getOption('tiny.custom_buttons2'), - 'tiny.custom_buttons3' => (!empty($cb3)) ? $cb3 : $modx->getOption('tiny.custom_buttons3'), - 'tiny.custom_buttons4' => (!empty($cb4)) ? $cb4 : $modx->getOption('tiny.custom_buttons4'), - 'tiny.custom_buttons5' => (!empty($cb5)) ? $cb5 : $modx->getOption('tiny.custom_buttons5'), - 'tiny.custom_plugins' => (!empty($plugins)) ? $plugins : $modx->getOption('tiny.custom_plugins'), - 'tiny.editor_theme' => (!empty($theme)) ? $theme : $modx->getOption('tiny.editor_theme'), - 'tiny.theme_advanced_blockformats' => (!empty($bfs)) ? $bfs : $modx->getOption('tiny.theme_advanced_blockformats'), - 'tiny.css_selectors' => (!empty($css)) ? $css : $modx->getOption('tiny.css_selectors'), - ); - - require_once $tinyCorePath.'tinymce.class.php'; - $tiny = new TinyMCE($modx,$tinyProperties); - $tiny->setProperties($tinyProperties); - $tiny->initialize(); - - $modx->regClientStartupHTMLBlock(''); - } - } elseif ($whichEditor == 'Redactor') { - /* invoke OnRichTextEditorInit event */ - $onRichTextEditorInit = $this->modx->invokeEvent('OnRichTextEditorInit',array( - 'editor' => $whichEditor, // Not necessary for Redactor - 'elements' => array('cdescription'), // Not necessary for Redactor - )); - if (is_array($onRichTextEditorInit)) - { - $onRichTextEditorInit = implode('', $onRichTextEditorInit); - } - $modx->setPlaceholder('onRichTextEditorInit', $onRichTextEditorInit); - } -} - - -return '
'.$onRichTextEditorInit.''; - -?> diff --git a/core/components/mxcalendars/elements/snippets/snippet.mxcalendars.php b/core/components/mxcalendars/elements/snippets/snippet.mxcalendars.php index e0b02d8..571cb9f 100644 --- a/core/components/mxcalendars/elements/snippets/snippet.mxcalendars.php +++ b/core/components/mxcalendars/elements/snippets/snippet.mxcalendars.php @@ -1,15 +1,17 @@ getService('mxcalendars','mxCalendars',$modx->getOption('mxcalendars.core_path',null,$modx->getOption('core_path').'components/mxcalendars/').'model/mxcalendars/',$scriptProperties); -if (!($mxcal instanceof mxCalendars)) return 'Error loading instance of mxCalendars.'; +if (!($mxcal instanceof mxCalendars)) { + return 'Error loading instance of mxCalendars.'; +} -include_once($modx->getOption('mxcalendars.core_path',null,$modx->getOption('core_path').'components/mxcalendars/').'processors/mgr/mxcHelper.php'); +include_once($modx->getOption('mxcalendars.core_path',null,$modx->getOption('core_path') . 'components/mxcalendars/') . 'processors/mgr/mxcHelper.php'); /* setup default properties */ $theme = $modx->getOption('theme',$scriptProperties,'default');// default, traditional @@ -33,7 +35,7 @@ $sort = $modx->getOption('mxc.sort',$scriptProperties,'startdate'); $dir = $modx->getOption('mxc.dir',$scriptProperties,'ASC'); $limit = $modx->getOption('limit',$scriptProperties,'99'); -$limitstart = $modx->getOption('limitstart', $scriptProperties, 0); +$offset = $modx->getOption('offset',$scriptProperties,0); //++ Text|Date Formatting properties $dateFormat = $modx->getOption('dateformat', $scriptProperties, '%Y-%m-%d'); $timeFormat = $modx->getOption('timeformat', $scriptProperties, '%H:%M %p'); @@ -90,20 +92,21 @@ //++ Calendar Options (ver >= 1.1.6d-pr) // Defaults to blank (ie show all categories). -if ($categoryFilter = urldecode(isset($_REQUEST['cid']) ? $_REQUEST['cid'] : $modx->getOption('categoryFilter', $scriptProperties, null))) { +if ($categoryFilter = urldecode(isset($_REQUEST['cid']) ?? $modx->getOption('categoryFilter', $scriptProperties, null))) { // Adding comma for retrieving events that are category-agnostic (ie have blank category). $categoryFilter = ",{$categoryFilter}"; } //++ Calendar Options (ver >= 1.1.0-pl) // Defaults to blank (ie show all calendars). -if ($calendarFilter = (isset($_REQUEST['calf']) ? $_REQUEST['calf'] : $modx->getOption('calendarFilter', $scriptProperties, null))) { +if ($calendarFilter = (isset($_REQUEST['calf']) ?? $modx->getOption('calendarFilter', $scriptProperties, null))) { // Adding comma for retrieving events that are calendar-agnostic (ie have blank calendar). $calendarFilter = ",{$calendarFilter}"; -}; +} //++ Context Options (ver >= 1.1.0-pl) // Defaults to current context. // Could be blank (ie show all contexts). -if ($contextFilter = ','.(isset($_REQUEST['conf']) ? $_REQUEST['conf'] : $modx->getOption('contextFilter',$scriptProperties, $modx->context->key))) { +if (isset($_REQUEST['conf']) ?? $modx->getOption('contextFilter', $scriptProperties, $modx->context->key)) { + $contextFilter = ',' . (isset($_REQUEST['conf']) ?? $modx->getOption('contextFilter', $scriptProperties, $modx->context->key)); // Adding comma for retrieving events that are context-agnostic (ie have blank context). $contextFilter = ",{$contextFilter}"; } @@ -113,79 +116,98 @@ //++ Caching Options $cacheEnable = $modx->getOption('cacheEnable',$scriptProperties,0); $cacheLifetime = $modx->getOption('cacheLifetime',$scriptProperties,null); //3600 would be one hour - and overrides the resource lifetime; leaving null inherits the resource cache lifetime settings -if (empty($cacheKey)) $cacheKey = $modx->getOption('cache_resource_key', null, 'resource'); -if (empty($cacheHandler)) $cacheHandler = $modx->getOption('cache_resource_handler', null, $modx->getOption(xPDO::OPT_CACHE_HANDLER, null, 'xPDOFileCache')); -if (!isset($cacheExpires)) $cacheExpires = $cacheLifetime!==null ? (integer)$cacheLifetime : (integer) $modx->getOption('cache_resource_expires', null, $modx->getOption(xPDO::OPT_CACHE_EXPIRES, null, 0)); -if (empty($cacheElementKey)) $cacheElementKey = $modx->resource->getCacheKey() . '/' . md5($modx->toJSON($properties) . implode('', $modx->request->getParameters())); +if (empty($cacheKey)) { + $cacheKey = $modx->getOption('cache_resource_key', null, 'resource'); +} +if (empty($cacheHandler)) { + $cacheHandler = $modx->getOption('cache_resource_handler', null, $modx->getOption(xPDO::OPT_CACHE_HANDLER, null, 'xPDOFileCache')); +} +if (!isset($cacheExpires)) { + $cacheExpires = $cacheLifetime!==null ? (integer)$cacheLifetime : (integer) $modx->getOption('cache_resource_expires', null, $modx->getOption(xPDO::OPT_CACHE_EXPIRES, null, 0)); +} +if (empty($cacheElementKey)) { + $cacheElementKey = $modx->resource->getCacheKey() . '/' . md5($modx->toJSON($properties) . implode('', $modx->request->getParameters())); +} $cacheOptions = array(xPDO::OPT_CACHE_KEY => $cacheKey,xPDO::OPT_CACHE_HANDLER => $cacheHandler,xPDO::OPT_CACHE_EXPIRES => $cacheExpires,); $results = $modx->cacheManager->get($cacheElementKey, $cacheOptions); - + //-- Update to the Timezone - if(!empty($setTimezone)) $mxcal->setTimeZone($setTimezone,$debugTimezone); + if(!empty($setTimezone)) { + $mxcal->setTimeZone($setTimezone, $debugTimezone); + } //-- Update to the Timezone: Manual fix to adjust timezone to match server settings examples. //date_default_timezone_set("Europe/Amsterdam"); //date_default_timezone_set('America/New_York'); // Process any needed Feeds as setup in mxCalendar Manager - + $feed = $modx->getObject('mxCalendarFeed', 10); if($feed){ $feed->set('nextrunon', 0); - $feed-save(); + $feed->save(); } $mxcal->processFeeds($setFeedTZ); -if($modx->resource->get('id') != $ajaxResourceId && $modx->resource->get('id') != $ajaxMonthResourceId) { +if((int)$modx->resource->get('id') !== (int)$ajaxResourceId && (int)$modx->resource->get('id') !== (int)$ajaxMonthResourceId) { //-- Add mxCalendar Theme CSS to html header (set in snippit properties) if($excludeCSS !== 1 && $excludeCSS !== '1'){ $modx->regClientCSS($modx->getOption('mxcalendars.assets_url',null,$modx->getOption('assets_url').'components/mxcalendars/').'themes/'.$theme.'/css/mxcalendar.css'); } //-- Add the Shadowbox library info if we are using modal - if(($modalView == 'true' || $modalView == 1) && ($usemxcLib == 'true' || $usemxcLib == 1)) { + if(($modalView === 'true' || (int)$modalView === 1) && ($usemxcLib === 'true' || (int)$usemxcLib === 1)) { $mxcal->addShadowBox($modalSetWidth,$modalSetHeight); } else { $mxcal->disableModal(); } //-- Add mxCalendar jQuery Library if enabled - if($addJQ && $addJQ !== 'false'){ + if($addJQ && $addJQ !== 'false') { $modx->regClientStartupScript($jqLibSrc); - //-- Only add the required JS files we need - if(!empty($ajaxResourceId) && $modx->resource->get('id') != $ajaxResourceId && $modx->resource->get('id') != $ajaxMonthResourceId)//-- Also requires a valid jQuery library be loaded - $modx->regClientStartupScript($mxcal->config['assetsUrl'].'js/web/mxc-calendar.js'); + //-- Only add the required JS files we need + if(!empty($ajaxResourceId)) { //-- Also requires a valid jQuery library be loaded + $modx->regClientStartupScript($mxcal->config['assetsUrl'] . 'js/web/mxc-calendar.js'); + } } } -if(((int)$cacheEnable === 1 || $cacheEnable === '1') && !empty($results) && $debug !== 1) +if(((int)$cacheEnable === 1 || $cacheEnable === '1') && !empty($results) && (int)$debug !== 1) { return $results; - -if($debug) -var_dump($scriptProperties); +} + +if($debug) { + var_dump($scriptProperties); +} $elStartDate = strtotime($eventListStartDate); -if($elStartDate ===false){ - if($debug) echo 'Could not convert elStartDate value of "'.$elStartDate.'" to proper time stamp.
'; +if($elStartDate === false) { + if($debug) { + echo 'Could not convert elStartDate value of "'.$elStartDate.'" to proper time stamp.
'; + } $elStartDate = time(); - } + $elEndDate = strtotime($eventListEndDate); -if($elEndDate ===false){ - if($debug) echo 'Could not convert elEndDate value of "'.$elEndDate.'" to proper time stamp.
'; +if($elEndDate === false){ + if($debug) { + echo 'Could not convert elEndDate value of "'.$elEndDate.'" to proper time stamp.
'; + } $elEndDate = time(); } - + //-- Setup varibles to hold the output $debugOutput = array(); $arrEventsDetail = array(); -$arrEventDates=array(); +$arrEventDates = array(); $output = ''; $time_start = microtime(true); $mxcalendars = $modx->getCollection('mxCalendarEvents'); -if($debug) $output .= "
Total Events: ".count($mxcalendars); +if($debug) { + $output .= '
Total Events: '.count($mxcalendars); +} $whereArr = array(); $eventsArr = array(); @@ -200,7 +222,7 @@ case 'ical': case 'rss': $sort = 'startdate'; - if(is_integer($eventid) && $eventid !== null){ + if($eventid !== null && is_integer($eventid)){ $whereArr = array(array('mxCalendarEvents.id:='=>$eventid)); } elseif (!$elDirectional) { $whereArr = array(array('repeating:=' => 0,'AND:enddate:>=' => $elStartDate,'AND:enddate:<=' => $elEndDate,array('OR:repeating:='=>1,'AND:repeatenddate:>=' => $elStartDate)) ); @@ -256,7 +278,7 @@ // For blank just show all. break; } - if($displayType == 'calendar' || $displayType == 'mini' || $displayType == 'list') { + if($displayType === 'calendar' || $displayType === 'mini' || $displayType === 'list') { $whereArr[] = array( array('categoryid' => $category), array('OR:categoryid:LIKE' => '%,'.$category.',%'), @@ -269,31 +291,44 @@ $whereArr['mxCalendarEvents.active'] = 1; $c->where($whereArr); -if($displayType != 'detail') - $c->sortby($sort,$dir); -$c->limit($limit,$limitstart); +if($displayType !== 'detail') { + $c->sortby($sort, $dir); +} + +$total = $modx->getCount('mxCalendarEvents',$c); +$totalVar = $modx->getOption('totalVar', $scriptProperties, 'total'); +$modx->setPlaceholder($totalVar,$total); +$offset = $modx->getOption('offset',$scriptProperties,0); + +$c->limit($limit, $offset); $c->prepare(); -if($debug) echo '

Filtering calendar date SQL range with: '.strftime('%m/%d/%Y', $elStartDate).' through '.strftime('%m/%d/%Y', $elEndDate).'

'; -if($debug) echo 'SQL: '.$c->toSql().'

'; +if($debug) { + echo '

Filtering calendar date SQL range with: '.strftime('%m/%d/%Y', $elStartDate).' through '.strftime('%m/%d/%Y', $elEndDate).'

'; +} +if($debug) { + echo 'SQL: ' . $c->toSQL() . '

'; +} -$queryTimer = new makeProcessTime($time_start,$debug); +$queryTimer = new makeProcessTime($debug,$time_start); $mxcalendars = $modx->getCollection('mxCalendarEvents',$c); $queryTimer->end('mxCalendars Query'); -if($debug) echo "
Returned Events: ".count($mxcalendars).'
'; +if($debug) { + echo '
Returned Events: ' . count($mxcalendars).'
'; +} -$resultLoopTimer = new makeProcessTime($time_start,$debug); +$resultLoopTimer = new makeProcessTime($debug,$time_start); foreach ($mxcalendars as $mxc) { //-- Convert the object to an array $mxcArray = $mxc->toArray(); - - $eStart = new DateTime(date('Y-m-d H:i:s',$mxc->get('startdate'))); + + $eStart = new DateTime(date('Y-m-d H:i:s',$mxc->get('startdate'))); $eEnd = new DateTime(date('Y-m-d H:i:s',$mxc->get('enddate'))); - + $durYear; $durMonth; $durDay; $durHour; $durMin; $durSec; - + if(version_compare(PHP_VERSION, '5.3.0') >= 0){ $diff = $eStart->diff($eEnd); $durYear = $diff->format('%y'); @@ -311,35 +346,43 @@ $durMin = $diff->minutes; $durSec = $diff->seconds; } - + //-- return event duration values - $mxcArray['durYear'] = !empty($durYear) ? $durYear : null; - $mxcArray['durMonth'] = !empty($durMonth) ? $durMonth : null; - $mxcArray['durDay'] = !empty($durDay) ? $durDay : null; - $mxcArray['durHour'] = !empty($durHour) ? $durHour : null; - $mxcArray['durMin'] = !empty($durMin) ? $durMin : null; + $mxcArray['durYear'] = !empty($durYear) ? $durYear : null; + $mxcArray['durMonth'] = !empty($durMonth) ? $durMonth : null; + $mxcArray['durDay'] = !empty($durDay) ? $durDay : null; + $mxcArray['durHour'] = !empty($durHour) ? $durHour : null; + $mxcArray['durMin'] = !empty($durMin) ? $durMin : null; $mxcArray['durSec'] = !empty($durSec) ? $durSec : null; - $mxcArray['mxcmodalClass'] = ($modalView && $ajaxResourceId || isset($_REQUEST['imajax']) ? 'mxcmodal' : ''); - + $mxcArray['mxcmodalClass'] = (($modalView && $ajaxResourceId) || isset($_REQUEST['imajax']) ? 'mxcmodal' : ''); + $arrEventsDetail[$mxcArray['id']] = $mxcArray; $arrEventDates[$mxcArray['id']] = array('date'=>$mxcArray['startdate'], 'eventId'=>$mxcArray['id'],'repeatId'=>0); - + //-- If we have repeating dates and repeating is enabled lets add those to the array - if($mxcArray['repeating'] && count(explode(',', $mxcArray['repeatdates']))){ - if($debug) echo 'Repeating Event: '.$mxcArray['title'].'
'; - if($debug) echo '   ++(0)  '.strftime($dateFormat.' '.$timeFormat, $mxcArray['startdate']).'
'; + if($mxcArray['repeating'] && count(explode(',', $mxcArray['repeatdates']))) { + if($debug) { + echo 'Repeating Event: ' . $mxcArray['title'] . '
'; + } + if($debug) { + echo '   ++(0)  ' . strftime($dateFormat . ' ' . $timeFormat, $mxcArray['startdate']) . '
'; + } $rid = 1; - foreach(explode(',',$mxcArray['repeatdates']) AS $rDate){ - $arrEventDates[$mxcArray['id'].'-'.$rid] = array('date'=>$rDate, 'eventId'=>$mxcArray['id'],'repeatId'=>$rid); - if($debug) echo '   ++('.$rid.')  '.strftime($dateFormat.' '.$timeFormat, $rDate).'
'; + foreach(explode(',',$mxcArray['repeatdates']) AS $rDate) { + $arrEventDates[$mxcArray['id'] . '-' . $rid] = array('date' => $rDate, 'eventId' => $mxcArray['id'], 'repeatId' => $rid); + if($debug) { + echo '   ++(' . $rid . ')  ' . strftime($dateFormat . ' ' . $timeFormat, $rDate) .'
'; + } $rid++; } } - + // Add date for each day in a multiple day event ( #127 ) if($mxcArray['durDay'] !== null && $mxcArray['durDay'] >= 1){ - if($debug) echo 'Multiple Day Event: '.$mxcArray['title'].'
'; - + if($debug) { + echo 'Multiple Day Event: ' . $mxcArray['title'] . '
'; + } + /* $i = 1; $endDate = $mxc->get('enddate'); @@ -351,22 +394,24 @@ } * */ - + for($i = 1; $i<=$mxcArray['durDay']; $i++){ $theSpanDate = strtotime('+'.$i.' day', $mxcArray['startdate']); $arrEventDates[$mxcArray['id'].'_'.$i] = array('date'=>$theSpanDate, 'eventId'=>$mxcArray['id'],'repeatId'=>null); - if($debug) echo '   ++('.$i.')  '.strftime($dateFormat.' '.$timeFormat, $theSpanDate).'
'; + if($debug) { + echo '   ++(' . $i . ')  ' . strftime($dateFormat . ' ' . $timeFormat, $theSpanDate) . '
'; + } } - + } - + //$output .= $mxcal->getChunk($tpl,$mxcArray); } $resultLoopTimer->end('mxc result set loop'); // Obtain a list of columns -$timer_5 = new makeProcessTime($time_start,$debug); +$timer_5 = new makeProcessTime($debug,$time_start); foreach ($arrEventDates as $key => $row) { $date[$key] = $row['date']; $event[$key] = $row['eventId']; @@ -375,60 +420,62 @@ // Sort the data with volume descending, edition ascending // Add $data as the last parameter, to sort by the common key -if(count($arrEventDates) && $displayType == 'list'){ - $multiSortTimer = new makeProcessTime($time_start,$debug); - if($dir == 'ASC') +if($displayType === 'list' && count($arrEventDates)){ + $multiSortTimer = new makeProcessTime($debug,$time_start); + if($dir === 'ASC') { array_multisort($date, SORT_ASC, $event, SORT_ASC, $arrEventDates); - else + } else { array_multisort($date, SORT_DESC, $event, SORT_DESC, $arrEventDates); + } $multiSortTimer->end('array_multisort'); -} else { - //array_multisort($date, SORT_ASC, $event, SORT_ASC, $arrEventDates); } if(count($arrEventDates)){ - if($debug) echo 'Looping through events list of '.count($arrEventDates).' total.
'; + if($debug) { + echo 'Looping through events list of ' . count($arrEventDates) . ' total.
'; + } $ulimit=0; - - $arraEventTimer = new makeProcessTime($time_start,$debug); - - $cnt = 1; + + $arraEventTimer = new makeProcessTime($debug,$time_start); + + $cnt = 1; foreach($arrEventDates AS $k=>$e){ - + $oDetails = $arrEventsDetail[$e['eventId']]; //Get original event (parent) details $oDetails['startdate'] = $e['date']; $oDetails['enddate'] = strtotime('+'.($arrEventsDetail[$e['eventId']]['durDay'] ? $arrEventsDetail[$e['eventId']]['durDay'].' days ' :'').($arrEventsDetail[$e['eventId']]['durHour'] ? $arrEventsDetail[$e['eventId']]['durHour'].' hour ' :'').($arrEventsDetail[$e['eventId']]['durMin'] ? $arrEventsDetail[$e['eventId']]['durMin'].' minute' :''), $e['date']);//$e['date'];//repeatenddate - if(( - ( - ($oDetails['startdate']>=$elStartDate || $oDetails['enddate'] >= $elStartDate) && + if(( + ( + ($oDetails['startdate']>=$elStartDate || $oDetails['enddate'] >= $elStartDate) && $oDetails['enddate']<=$elEndDate - ) - || - $displayType=='detail' || $displayType=='calendar' || $displayType == 'mini' - || - $elDirectional + ) || + $displayType === 'detail' || $displayType === 'calendar' || $displayType === 'mini' || $elDirectional )){ - - $oDetails['startdate_fstamp'] = $e['date']; + + $oDetails['startdate_fstamp'] = $e['date']; $oDetails['enddate_fstamp'] = $arrEventsDetail[$e['eventId']]['enddate']; - + $oDetails['detailURL'] = $modx->makeUrl((!empty($ajaxResourceId) && (bool)$modalView === true ? $ajaxResourceId : $resourceId),'',array('detail' => $e['eventId'], 'r'=>$e['repeatId'])); $eventsArr[strftime('%Y-%m-%d', $e['date'])][] = $oDetails; $ulimit++; - if($debug) echo $cnt.')    '.$ulimit.'['.$limit.']) '.strftime($dateFormat,$e['date']).' '.$e['eventId'].'
'; - if($ulimit >= $limit && $displayType=='list' ) break; + if($debug) { + echo $cnt . ')    ' . $ulimit . '[' . $limit . ']) ' . strftime($dateFormat,$e['date']) . ' ' . $e['eventId'] . '
'; + } + if($ulimit >= $limit && $displayType === 'list' ) { + break; + } $cnt++; } } $arraEventTimer->end('arrEventDates'); - -} else { - if($debug) echo 'No valid dates returned.'; + +} elseif($debug) { + echo 'No valid dates returned.'; } -$modx->setPlaceholders(array('dateseperator'=>$dateSeperator)); +$modx->setPlaceholders(array('dateseperator' => $dateSeperator)); //----- NOW GET THE DISPLAY TYPE ------// switch ($displayType){ @@ -436,34 +483,81 @@ case 'daily': case 'ical': case 'rss': - $output = $mxcal->makeEventList($eventListLimit, $eventsArr, array('tplElItem'=>$tplElItem, 'tplElMonthHeading'=>$tplElMonthHeading, 'tplElWrap'=>$tplElWrap, 'tplImage'=>$tplImageItem, 'tplVideo'=>$tplVIdeoItem, 'tplNoEvents'=>$tplNoEvents),$elStartDate,$elEndDate); + $output = $mxcal->makeEventList( + $eventListLimit, + $eventsArr, + array( + 'tplElItem' => $tplElItem, + 'tplElMonthHeading' => $tplElMonthHeading, + 'tplElWrap' => $tplElWrap, + 'tplImage' => $tplImageItem, + 'tplVideo' => $tplVideoItem, + 'tplNoEvents' => $tplNoEvents + ), + $elStartDate, + $elEndDate + ); break; case 'calendar': case 'mini': default: - $timer_10 = new makeProcessTime($time_start,$debug); - $output = $mxcal->makeEventCalendar($eventsArr,(!empty($ajaxResourceId) && $modalView? $ajaxResourceId : $resourceId),(!empty( $ajaxMonthResourceId) ? $ajaxMonthResourceId : (!empty($ajaxResourceId) ? $ajaxResourceId : $resourceId) ),array('event'=>$tplEvent,'day'=>$tplDay,'week'=>$tplWeek,'month'=>$tplMonth,'heading'=>$tplHeading, 'tplImage'=>$tplImageItem, 'tplVideo'=>$tplVIdeoItem), $contextFilter, $calendarFilter, $highlightToday); + $timer_10 = new makeProcessTime($debug, $time_start); + $ajaxMonthResourceIdHelper = !empty($ajaxResourceId) ? $ajaxResourceId : $resourceId; + $output = $mxcal->makeEventCalendar( + $eventsArr, + ((!empty($ajaxResourceId) && $modalView) ? $ajaxResourceId : $resourceId), + (!empty($ajaxMonthResourceId) ? $ajaxMonthResourceId : $ajaxMonthResourceIdHelper), + array( + 'event' => $tplEvent, + 'day' => $tplDay, + 'week' => $tplWeek, + 'month' => $tplMonth, + 'heading' => $tplHeading, + 'tplImage'=>$tplImageItem, + 'tplVideo'=>$tplVideoItem + ), + $contextFilter, + $calendarFilter, + $highlightToday + ); $timer_10->end('UI Rendering'); break; case 'year': break; case 'detail': - if($debug) $output .= 'Total Occurances: '.count($eventsArr).' for Event ID: '.$_REQUEST['detail'].'
'; - if(isset($resourceId) && $modx->resource->get('id') != $resourceId) - $tplDetail = $tplDetailModal; - $output .= $mxcal->makeEventDetail($eventsArr,($occurance=$_REQUEST['r']?$_REQUEST['r']:0) , array('tplDetail'=>$tplDetail, 'tplImage'=>$tplImageItem, 'tplVideo'=>$tplVIdeoItem),$mapWidth,$mapHeight,$gmapRegion); + if($debug) { + $output .= 'Total Occurances: ' . count($eventsArr) . ' for Event ID: ' . $_REQUEST['detail'] . '
'; + } + if(isset($resourceId) && (int)$modx->resource->get('id') !== (int)$resourceId) { + $tplDetail = $tplDetailModal; + } + $output .= $mxcal->makeEventDetail( + $eventsArr, + ($occurance = $_REQUEST['r'] ? $_REQUEST['r'] : 0), + array( + 'tplDetail'=> $tplDetail, + 'tplImage' => $tplImageItem, + 'tplVideo' => $tplVideoItem + ), + $mapWidth, + $mapHeight, + $gmapRegion + ); //$whereArr[0]['AND:id:='] = (int)$_REQUEST['detail']; //@TODO Make filter for single events repeating dates break; } //-- Always allow the category list placeholder to be set -if($showCategories == true) - $modx->setPlaceholder('categories', $mxcal->makeCategoryList($labelCategoryHeading, ($_REQUEST['cid'] ? $_REQUEST['cid'] : null),$resourceId, array('tplCategoryWrap'=>$tplCategoryWrap, 'tplCategoryItem'=>$tplCategoryItem))); +if($showCategories === true) { + $modx->setPlaceholder('categories', $mxcal->makeCategoryList($labelCategoryHeading, ($_REQUEST['cid'] ? $_REQUEST['cid'] : null), $resourceId, array('tplCategoryWrap'=>$tplCategoryWrap, 'tplCategoryItem'=>$tplCategoryItem))); +} $mxcal->restoreTimeZone($debugTimezone); $time_end = microtime(true); $time = $time_end - $time_start; -if($debug) echo "
mxCalendar processed in $time seconds

\n"; +if($debug) { + echo '
mxCalendar processed in $time seconds

\n'; +} $modx->cacheManager->set($cacheElementKey, $output, $cacheExpires, $cacheOptions); diff --git a/core/components/mxcalendars/index.class.php b/core/components/mxcalendars/index.class.php new file mode 100644 index 0000000..d7bcf95 --- /dev/null +++ b/core/components/mxcalendars/index.class.php @@ -0,0 +1,125 @@ + + */ +require_once dirname(__DIR__) . '/mxcalendars/model/mxcalendars/mxcalendars.class.php'; +abstract class mxcalendarsBaseManagerController extends modExtraManagerController +{ + /** + * @access public. + * @return Mixed. + */ + public $mxCalendars; + + public function initialize() + { + //$this->mxCalendars = new mxCalendars($this->modx); + $this->mxCalendars = $this->modx->getService('mxCalendars', 'mxCalendars', $this->modx->getOption('mxcalendars.core_path', null, $this->modx->getOption('core_path') . 'components/mxcalendars/') . 'model/mxcalendars/'); + //return $this->mxCalendars->initialize('mgr'); + $this->addJavascript($this->mxCalendars->config['jsUrl'] . 'mgr/mxcalendars.js'); + + $this->addHtml(''); + + //var_dump($this->mxCalendars->config); + /* If we want to use Tiny, we'll need some extra files. */ + $useRTE = $this->modx->getOption('mxcalendars.use_richtext', $this->mxCalendars->config, false); + $whichEditor = $this->modx->getOption('which_editor'); + $onRichTextEditorInit = ''; + + if ($useRTE) { + + if ($whichEditor === 'TinyMCE') { + $tinyCorePath = $this->modx->getOption('tiny.core_path', null, + $this->modx->getOption('core_path') . 'components/tinymce/'); + if (file_exists($tinyCorePath . 'tinymce.class.php')) { + + /* First fetch the mxcalendarstiny specific settings */ + $cb1 = $this->modx->getOption('mxcalendars.tiny.buttons1'); + $cb2 = $this->modx->getOption('mxcalendars.tiny.buttons2'); + $cb3 = $this->modx->getOption('mxcalendars.tiny.buttons3'); + $cb4 = $this->modx->getOption('mxcalendars.tiny.buttons4'); + $cb5 = $this->modx->getOption('mxcalendars.tiny.buttons5'); + $plugins = $this->modx->getOption('mxcalendars.tiny.custom_plugins'); + $theme = $this->modx->getOption('mxcalendars.tiny.theme'); + $bfs = $this->modx->getOption('mxcalendars.tiny.theme_advanced_blockformats'); + $css = $this->modx->getOption('mxcalendars.tiny.theme_advanced_css_selectors'); + + /* If the settings are empty, override them with the generic tinymce settings. */ + $tinyProperties = [ + 'height' => $this->modx->getOption('mxcalendars.tiny.height', null, 200), + 'width' => $this->modx->getOption('mxcalendars.tiny.width', null, 400), + 'tiny.custom_buttons1' => (!empty($cb1)) ? $cb1 : $this->modx->getOption('tiny.custom_buttons1'), + 'tiny.custom_buttons2' => (!empty($cb2)) ? $cb2 : $this->modx->getOption('tiny.custom_buttons2'), + 'tiny.custom_buttons3' => (!empty($cb3)) ? $cb3 : $this->modx->getOption('tiny.custom_buttons3'), + 'tiny.custom_buttons4' => (!empty($cb4)) ? $cb4 : $this->modx->getOption('tiny.custom_buttons4'), + 'tiny.custom_buttons5' => (!empty($cb5)) ? $cb5 : $this->modx->getOption('tiny.custom_buttons5'), + 'tiny.custom_plugins' => (!empty($plugins)) ? $plugins : $this->modx->getOption('tiny.custom_plugins'), + 'tiny.editor_theme' => (!empty($theme)) ? $theme : $this->modx->getOption('tiny.editor_theme'), + 'tiny.theme_advanced_blockformats' => (!empty($bfs)) ? $bfs : $this->modx->getOption('tiny.theme_advanced_blockformats'), + 'tiny.css_selectors' => (!empty($css)) ? $css : $this->modx->getOption('tiny.css_selectors'), + ]; + + require_once $tinyCorePath . 'tinymce.class.php'; + $tiny = new TinyMCE($this->modx, $tinyProperties); + $tiny->setProperties($tinyProperties); + $tiny->initialize(); + + $this->modx->regClientStartupHTMLBlock(''); + } + } elseif ($whichEditor === 'Redactor') { + /* invoke OnRichTextEditorInit event */ + $onRichTextEditorInit = $this->modx->invokeEvent('OnRichTextEditorInit', [ + 'editor' => $whichEditor, // Not necessary for Redactor + 'elements' => ['cdescription'], // Not necessary for Redactor + ]); + if (is_array($onRichTextEditorInit)) { + $onRichTextEditorInit = implode('', $onRichTextEditorInit); + } + $this->modx->setPlaceholder('onRichTextEditorInit', $onRichTextEditorInit); + } + } + + parent::initialize(); + } + + /** + * @access public + * @return array + */ + public function getLanguageTopics() + { + return array('mxcalendars:default'); + } + + /** + * @access public + * @returns bool + */ + public function checkPermissions() + { + return $this->modx->hasPermission('mxcalendars'); + } +} + +class IndexManagerController extends mxcalendarsBaseManagerController +{ + /** + * @access public. + * @return String. + */ + public static function getDefaultController() + { + return 'home'; + } +} diff --git a/core/components/mxcalendars/lexicon/cs/default.inc.php b/core/components/mxcalendars/lexicon/cs/default.inc.php new file mode 100644 index 0000000..12ec4e6 --- /dev/null +++ b/core/components/mxcalendars/lexicon/cs/default.inc.php @@ -0,0 +1,225 @@ +
Vyberte frekvenci opakování pro typ opakování (denně, týdně, měsíčně, ročně) jež jste zvolili výše'; + +$_lang['mxcalendars.label_content'] = 'Obsah'; + +//$_lang['mxcalendars.'] = ''; + +//-- Category Management +$_lang['mxcalendars.category_desc'] = 'Zde vytváříte kategorie, které se přiřazují k jednoltivým akcím. Můžete k nim také přiřadit barvu pozadí nebo textu.'; +$_lang['mxcalendars.err_category_ac'] = 'Kategorie se stejným jménem již existuje, prosím zadejte jiný název.'; +$_lang['mxcalendars.label_window_create'] = 'Vytvořit/Upravit kategorii'; +$_lang['mxcalendars.category_name_col_label'] = 'Název'; +$_lang['mxcalendars.category_isdefault_col_label'] = 'Výchozí kategorie'; +$_lang['mxcalendars.category_foregroundcss_col_label'] = 'Barva textu'; +$_lang['mxcalendars.category_backgroundcss_col_label'] = 'Barva pozadí'; +$_lang['mxcalendars.category_inlinecss_col_label'] = 'Inline CSS'; +$_lang['mxcalendars.category_disabled_col_label'] = 'Vyřazená kategorie'; +$_lang['mxcalendars.category_active_col_label'] = 'Aktivní'; +$_lang['mxcalendars.cateogry_remove_title'] = 'Odstranit kategorii'; +$_lang['mxcalendars.cateogry_remove_confirm'] = 'Opravdu chcete kategorii smazat?'; +$_lang['mxcalendars.btn_create_cat'] = 'Vytvořit kategorii'; +$_lang['mxcalendars.default_category_search'] = 'Hledat kategorie ...'; +$_lang['mxcalendars.menu_update_category'] = 'Upravit kategorii'; +$_lang['mxcalendars.menu_remove_category'] = 'Odstranit kategorii'; +$_lang['mxcalendars.label_category_heading'] = 'Kategorie:'; +$_lang['mxcalendars.label_category_viewAll'] = 'Zobrazit vše'; + +//-- Settings friendly names +$_lang['mxcalendars.set_category_required'] = 'Nastavit vynucení kategorie'; +$_lang['mxcalendars.set_event_desc_type'] = 'Typ pro pole popisu'; +$_lang['mxcalendars.set_mgr_dateformat'] = 'Formát datumu'; +$_lang['mxcalendars.set_mgr_timeformat'] = 'Formát času'; + +//-- Calendar Management +$_lang['mxcalendars.calendar_desc'] = 'Zde vytváříte kalendáře, které přiřazujete jednotlivím akcím.'; +$_lang['mxcalendars.err_ac'] = 'Kalendář se stejným jménem již existuje, prosím zadejte jiný název.'; +$_lang['mxcalendars.calendar_name_col_label'] = 'Název'; +$_lang['mxcalendars.calendar_name_col_active'] = 'Aktivní'; +$_lang['mxcalendars.calendar_default_calendar_search'] = 'Hledat kalendáře ...'; +$_lang['mxcalendars.calendar_btn_create'] = 'Vytvořit/Upravit kalendář'; +$_lang['mxcalendars.calendar_remove_title'] = 'Odstranit kalendář.'; +$_lang['mxcalendars.calendar_remove_confirm'] = 'Opravdu chcete kalendář odstranit?'; + +$_lang['mxcalendars.calendar_context_menu_update'] = 'Upravit'; +$_lang['mxcalendars.calendar_context_menu_remove'] = 'Odstranit'; + +$_lang['mxcalendars.label_select_calendar'] = 'Vybrat kalendář'; +$_lang['mxcalendars.label_select_calendar_err'] = 'Kalendář nebyl nalezen'; +$_lang['mxcalendars.grid_col_calendar'] = 'Kalendář'; + +//-- Feed lexicon entries +$_lang['mxcalendars.tab_feed'] = 'Feedy'; +$_lang['mxcalendars.feed_desc'] = 'Zde můžete vyplnit URL pro iCalendar nebo XML feed které jsou veřejně přístupné z vašeho serveru.'; +$_lang['mxcalendars.default_feed_search'] = 'Hledat feedy ...'; +$_lang['mxcalendars.feed_btn_create'] = 'Vytvořit feed'; +$_lang['mxcalendars.feed_menu_update'] = 'Upravit Feed'; +$_lang['mxcalendars.feed_menu_remove'] = 'Odstranit Feed'; +$_lang['mxcalendars.feed_remove_title'] = 'Potvrzení o odstranění feedu'; +$_lang['mxcalendars.feed_remove_confirm'] = 'Tímto kompletně feed odstraníte z databáze a nebude z něj nadále možné načítat data.'; +$_lang['mxcalendars.feed_col_feed'] = 'URL Feedu'; +$_lang['mxcalendars.feed_col_active'] = 'Aktivní'; +$_lang['mxcalendars.feed_col_type'] = 'Typ'; +$_lang['mxcalendars.lastrunon_col_label'] = 'Poslední update'; +$_lang['mxcalendars.nextrunon_col_label'] = 'Další update'; +$_lang['mxcalendars.label_default'] = 'Výchozí'; +$_lang['mxcalendars.source'] = 'Zdroj'; +$_lang['mxcalendars.label_feedmeasurementtime'] = 'Vložte počet položek'; +$_lang['mxcalendars.label_feedmeasurementtype'] = 'Typ časování'; +$_lang['mxcalendars.err_feed_req_feed'] = 'Prosím vyplňte URL Feedu'; +$_lang['mxcalendars.err_feed_req_default_category'] = 'Prosím vyplňte kategorii'; +$_lang['mxcalendars.err_feed_req_type'] = 'Prosím vyplňte typ feedu'; + +$_lang['mxcalendars.feed_type_label_select_empty'] = '--vybrat--'; +$_lang['mxcalendars.measurement_type_label_select_empty'] = '--vybrat--'; + +//-- Event Images +$_lang['mxcalendars.err_event_image_req_name'] = 'Prosím vyplňte titulek obrázku.'; +$_lang['mxcalendars.err_event_image_req_filepath'] = 'Prosím vyplňte cestu k souboru.'; +$_lang['mxcalendars.image_remove_title'] = 'Odstranit obrázek.'; +$_lang['mxcalendars.image_remove_confirm'] = 'Opravdu chcete obrázek odstranit?'; + +//-- Event Videos +$_lang['mxcalendars.err_event_video_req_name'] = 'Prosím vyplňte titulek videa.'; +$_lang['mxcalendars.err_event_video_req_video'] = 'Prosím vyplňte cestu k souboru.'; +$_lang['mxcalendars.video_remove_title'] = 'Odstranit video.'; +$_lang['mxcalendars.video_remove_confirm'] = 'Opravdu chcete video odstranit?'; + +//-- System settings +$_lang['setting_mxcalendars.tiny.buttons1'] = '1. řada TinyMCE tlačítek'; +$_lang['setting_mxcalendars.tiny.buttons2'] = '2. řada TinyMCE tlačítek'; +$_lang['setting_mxcalendars.tiny.buttons3'] = '3. řada TinyMCE tlačítek'; +$_lang['setting_mxcalendars.tiny.buttons4'] = '4. řada TinyMCE tlačítek'; +$_lang['setting_mxcalendars.tiny.buttons5'] = '5. řada TinyMCE tlačítek'; \ No newline at end of file diff --git a/core/components/mxcalendars/lexicon/cs/properties.inc.php b/core/components/mxcalendars/lexicon/cs/properties.inc.php new file mode 100644 index 0000000..ca4e8b8 --- /dev/null +++ b/core/components/mxcalendars/lexicon/cs/properties.inc.php @@ -0,0 +1,41 @@ +
Stel de herhalingsfrequentie in voor het type (dagelijks, weeklijks, maandelijks, jaarlijks) zoals hierboven gekozen.'; + +$_lang['mxcalendars.label_content'] = 'Content'; + //$_lang['mxcalendars.'] = ''; //-- Category Management $_lang['mxcalendars.category_desc'] = 'Beheer de categorieën waar elk agendapunt aan gekoppeld kan worden. Voor elke categorie is een voor- en achtergrond kleur in te stellen'; +$_lang['mxcalendars.err_category_ac'] = 'Category with the same name allready exists, please enter another name.'; $_lang['mxcalendars.label_window_create'] = 'Maak een nieuwe categorie'; $_lang['mxcalendars.category_name_col_label'] = 'Naam'; $_lang['mxcalendars.category_isdefault_col_label'] = 'Is standaard'; @@ -132,7 +154,6 @@ $_lang['mxcalendars.default_category_search'] = "Zoek categorie..."; $_lang['mxcalendars.menu_update_category'] = 'Update categorie'; $_lang['mxcalendars.menu_remove_category'] = 'Verwijder categorie'; - $_lang['mxcalendars.label_category_heading'] = 'Categorieën:'; $_lang['mxcalendars.label_category_viewAll'] = 'Laat allen zien'; @@ -144,13 +165,13 @@ //-- Calendar Management $_lang['mxcalendars.calendar_desc'] = 'Beheer agenda\'s waar evenementen aan toegevoegd kunnen worden, maak er zoveel als nodig.'; - $_lang['mxcalendars.err_ac'] = 'Fout bij opslaan agenda, probeer opnieuw.'; $_lang['mxcalendars.calendar_name_col_label'] = 'Naam'; $_lang['mxcalendars.calendar_name_col_active'] = 'Actief'; $_lang['mxcalendars.calendar_default_calendar_search'] = 'Zoek ...'; $_lang['mxcalendars.calendar_btn_create'] = 'Maak nieuwe agenda'; - +$_lang['mxcalendars.calendar_remove_title'] = 'Remove calendar.'; +$_lang['mxcalendars.calendar_remove_confirm'] = 'Do you realy want to remove selected calendar?'; $_lang['mxcalendars.calendar_context_menu_update'] = 'Update'; $_lang['mxcalendars.calendar_context_menu_remove'] = 'Verwijder'; @@ -159,6 +180,46 @@ $_lang['mxcalendars.label_select_calendar_err'] = 'Agenda niet gevonden'; $_lang['mxcalendars.grid_col_calendar'] = 'Agenda'; - - -?> +//-- Feed lexicon entries +$_lang['mxcalendars.tab_feed'] = 'Feeds'; +$_lang['mxcalendars.feed_desc'] = 'Enter an external site iCalendar or XML feed url that is public accessible via your server.'; +$_lang['mxcalendars.default_feed_search'] = 'Search Feeds'; +$_lang['mxcalendars.feed_btn_create'] = 'Create New Feed'; +$_lang['mxcalendars.feed_menu_update'] = 'Update Feed'; +$_lang['mxcalendars.feed_menu_remove'] = 'Remove Feed'; +$_lang['mxcalendars.feed_remove_title'] = 'Confirm Removal of Feed'; +$_lang['mxcalendars.feed_remove_confirm'] = 'This will remove the feed completely from the database and no further import actions will take place.'; +$_lang['mxcalendars.feed_col_feed'] = 'Feed URL'; +$_lang['mxcalendars.feed_col_active'] = 'Active'; +$_lang['mxcalendars.feed_col_type'] = 'Type'; +$_lang['mxcalendars.lastrunon_col_label'] = 'Last Update'; +$_lang['mxcalendars.nextrunon_col_label'] = 'Next Update'; +$_lang['mxcalendars.label_default'] = 'Default'; +$_lang['mxcalendars.source'] = 'Source'; +$_lang['mxcalendars.label_feedmeasurementtime'] = 'Enter number of units'; +$_lang['mxcalendars.label_feedmeasurementtype'] = 'Timer type'; +$_lang['mxcalendars.err_feed_req_feed'] = 'Please enter Feed URL'; +$_lang['mxcalendars.err_feed_req_default_category'] = 'Please select category'; +$_lang['mxcalendars.err_feed_req_type'] = 'Please enter Feed type'; + +$_lang['mxcalendars.feed_type_label_select_empty'] = '--select--'; +$_lang['mxcalendars.measurement_type_label_select_empty'] = '--select--'; + +//-- Event Images +$_lang['mxcalendars.err_event_image_req_name'] = 'Please enter image title.'; +$_lang['mxcalendars.err_event_image_req_filepath'] = 'Please enter image path.'; +$_lang['mxcalendars.image_remove_title'] = 'Delete image.'; +$_lang['mxcalendars.image_remove_confirm'] = 'Do you realy want to delete selected image?'; + +//-- Event Videos +$_lang['mxcalendars.err_event_video_req_name'] = 'Please enter video title.'; +$_lang['mxcalendars.err_event_video_req_video'] = 'Please enter video path.'; +$_lang['mxcalendars.video_remove_title'] = 'Delete video.'; +$_lang['mxcalendars.video_remove_confirm'] = 'Do you realy want to delete selected video?'; + +//-- System settings +$_lang['setting_mxcalendars.tiny.buttons1'] = '1. row of TinyMCE buttons'; +$_lang['setting_mxcalendars.tiny.buttons2'] = '2. row of TinyMCE buttons'; +$_lang['setting_mxcalendars.tiny.buttons3'] = '3. row of TinyMCE buttons'; +$_lang['setting_mxcalendars.tiny.buttons4'] = '4. row of TinyMCE buttons'; +$_lang['setting_mxcalendars.tiny.buttons5'] = '5. row of TinyMCE buttons'; \ No newline at end of file diff --git a/core/components/mxcalendars/lexicon/ru/default.inc.php b/core/components/mxcalendars/lexicon/ru/default.inc.php index f73d8ad..8b920d3 100644 --- a/core/components/mxcalendars/lexicon/ru/default.inc.php +++ b/core/components/mxcalendars/lexicon/ru/default.inc.php @@ -1,5 +1,6 @@ 1,'Tue'=>2,'Wed'=>3,'Thu'=>4,'Fri'=>5,'Sat'=>6,'Sun'=>7); + private $scriptProperties = []; + private $dowMatch = ['Mon' => 1, 'Tue' => 2, 'Wed' => 3, 'Thu' => 4, 'Fri' => 5, 'Sat' => 6, 'Sun' => 7]; public $debug = false; - - function __construct(modX &$modx,array $config = array()) { + + function __construct(modX &$modx, array $config = []) + { $this->modx =& $modx; - - $basePath = $this->modx->getOption('mxcalendars.core_path',$config,$this->modx->getOption('core_path').'components/mxcalendars/'); - $assetsUrl = $this->modx->getOption('mxcalendars.assets_url',$config,$this->modx->getOption('assets_url').'components/mxcalendars/'); - $descriptionEditorMode = $this->modx->getOption('mxcalendars.event_desc_type','htmleditor'); - $categoryRequired = $this->modx->getOption('mxcalendars.category_required','true'); + + $basePath = $this->modx->getOption('mxcalendars.core_path', $config, + $this->modx->getOption('core_path') . 'components/mxcalendars/'); + $assetsUrl = $this->modx->getOption('mxcalendars.assets_url', $config, + $this->modx->getOption('assets_url') . 'components/mxcalendars/'); + $descriptionEditorMode = $this->modx->getOption('mxcalendars.event_desc_type', 'htmleditor'); + $categoryRequired = $this->modx->getOption('mxcalendars.category_required', 'true'); $this->loggingEnabled = $this->modx->getOption('mxcalendars.mgr_log_enable', 0); - $this->config = array_merge(array( + $this->config = array_merge([ 'basePath' => $basePath, 'corePath' => $basePath, - 'modelPath' => $basePath.'model/', - 'processorsPath' => $basePath.'processors/', - 'chunksPath' => $basePath.'elements/chunks/', - 'jsUrl' => $assetsUrl.'js/', - 'cssUrl' => $assetsUrl.'css/', + 'modelPath' => $basePath . 'model/', + 'processorsPath' => $basePath . 'processors/', + 'chunksPath' => $basePath . 'elements/chunks/', + 'jsUrl' => $assetsUrl . 'js/', + 'cssUrl' => $assetsUrl . 'css/', 'assetsUrl' => $assetsUrl, - 'connectorUrl' => $assetsUrl.'connector.php', + 'connectorUrl' => $assetsUrl . 'connector.php', 'category_required' => $categoryRequired, 'event_desc_type' => $descriptionEditorMode, 'mgr_dateformat' => $this->modx->getOption('mxcalendars.mgr_dateformat', '', 'm/d/Y'), @@ -42,121 +46,144 @@ function __construct(modX &$modx,array $config = array()) { 'mgr_allday_start' => $this->modx->getOption('mxcalendars.mgr_allday_start', '', '8:00 am'), 'mgr_allday_end' => $this->modx->getOption('mxcalendars.mgr_allday_end', '', '5:00 pm'), 'isAdministrator' => $this->modx->user->isMember('Administrator'), - ),$config); - $this->modx->addPackage('mxcalendars',$this->config['modelPath']); - $this->modx->getService('lexicon','modLexicon'); + ], $config); + $this->modx->addPackage('mxcalendars', $this->config['modelPath']); + $this->modx->getService('lexicon', 'modLexicon'); $this->modx->lexicon->load('mxcalendars:default'); - - + + } - - /* - * MANAGER: Initialize the manager view for calendar item management - */ - public function initialize($ctx = 'web') { - - $this->processFeeds(); - - switch ($ctx) { - case 'mgr': - $this->modx->lexicon->load('mxcalendars:default'); - if (!$this->modx->loadClass('mxcalendarControllerRequest',$this->config['modelPath'].'mxcalendars/request/',true,true)) { - return 'Could not load controller request handler. ['.$this->config['modelPath'].'mxcalendars/request/]'; - } - $this->request = new mxcalendarControllerRequest($this); - - return $this->request->handleRequest(); - break; - } - return true; - } - - public function setProperties($p=array()){ - $this->scriptProperties = $p; + + /* + * MANAGER: Initialize the manager view for calendar item management + */ + public function initialize($ctx = 'web') + { + + $this->processFeeds(); + + switch ($ctx) { + case 'mgr': + $this->modx->lexicon->load('mxcalendars:default'); + if (!$this->modx->loadClass('mxcalendarControllerRequest', + $this->config['modelPath'] . 'mxcalendars/request/', true, true)) { + return 'Could not load controller request handler. [' . $this->config['modelPath'] . 'mxcalendars/request/]'; + } + $this->request = new mxcalendarControllerRequest($this); + + return $this->request->handleRequest(); + break; } - - /* - * GLOBAL HELPER FUNCTIONS: do what we can to making life easier - */ - public function loadChunk($name) { - $chunk = null; - if (!isset($this->chunks[$name])) { - $chunk = $this->_getTplChunk($name); - if (empty($chunk)) { - $chunk = $this->modx->getObject('modChunk',array('name' => $name)); - if ($chunk == false) return false; - } - + + return true; + } + + public function setProperties($p = []) + { + $this->scriptProperties = $p; + } + + /* + * GLOBAL HELPER FUNCTIONS: do what we can to making life easier + */ + public function loadChunk($name) + { + $chunk = null; + if (!isset($this->chunks[$name])) { + $chunk = $this->_getTplChunk($name); + if (empty($chunk)) { + $chunk = $this->modx->getObject('modChunk', ['name' => $name]); + if ($chunk == false) { + return false; } - return $chunk; - } - //@TODO remove; not used - public function parseChunk($name,$properties=array()){ - return $this->modx->getChunk($name,$properties); + } + } - - public function getChunk($name,$properties = array()) { - $chunk = null; - if (!isset($this->chunks[$name])) { - $chunk = $this->_getTplChunk($name); - if (empty($chunk)) { - $chunk = $this->modx->getObject('modChunk',array('name' => $name)); - if ($chunk == false) return false; - } - $this->chunks[$name] = $chunk->getContent(); - } else { - $o = $this->chunks[$name]; - $chunk = $this->modx->newObject('modChunk'); - $chunk->setContent($o); - } - $chunk->setCacheable(true); - return $chunk->process($properties); - } - - private function _getTplChunk($name,$postfix = '.chunk.tpl') { - $chunk = false; - $f = $this->config['chunksPath'].strtolower($name).$postfix; - if (file_exists($f)) { - $o = file_get_contents($f); - $chunk = $this->modx->newObject('modChunk'); - $chunk->set('name',$name); - $chunk->setContent($o); - } - return $chunk; - } - - private function _getMap($address=null,$gmapRegion='',$width='500px',$height='500px', $gmapLib='http://maps.google.com/maps/api/js?sensor=false'){ - $googleMap = ''; - $gmapLocations = ''; - //-- Add google Map API - if($address){ - include_once('google_geoloc.class.inc.php'); - //-- Output the Address results - if(class_exists("geoLocator") && $address){ - //-- Split addresses for multiple points on the map - $addressList = explode('|', $address); - - $mygeoloc = new geoLocator; - $mygeoloc->region = $gmapRegion; - //$mygeoloc->host = $this->config['GOOGLE_MAP_HOST']; - //$mygeoloc->apikey = $this->config['GOOGLE_MAP_KEY']; - //$mygeoloc->canvas = $this->config['mxcGoogleMapDisplayCanvasID']; - //$mygeoloc->autofitmap = (count($addressList) > 1 ? true : false); - - foreach($addressList as $loc){ - $mygeoloc->getGEO($loc); - } - $googleMap = '
'; - $gmapLocations = $mygeoloc->mapJSv3; - } else { - $googleMap = 'No class found.'; - } - return $googleMap.' + return $chunk; + } + + //@TODO remove; not used + public function parseChunk($name, $properties = []) + { + return $this->modx->getChunk($name, $properties); + } + + public function getChunk($name, $properties = []) + { + $chunk = null; + if (!isset($this->chunks[$name])) { + $chunk = $this->_getTplChunk($name); + if (empty($chunk)) { + $chunk = $this->modx->getObject('modChunk', ['name' => $name]); + if ($chunk == false) { + return false; + } + } + $this->chunks[$name] = $chunk->getContent(); + } else { + $o = $this->chunks[$name]; + $chunk = $this->modx->newObject('modChunk'); + $chunk->setContent($o); + } + $chunk->setCacheable(true); + + return $chunk->process($properties); + } + + private function _getTplChunk($name, $postfix = '.chunk.tpl') + { + $chunk = false; + $f = $this->config['chunksPath'] . strtolower($name) . $postfix; + if (file_exists($f)) { + $o = file_get_contents($f); + $chunk = $this->modx->newObject('modChunk'); + $chunk->set('name', $name); + $chunk->setContent($o); + } + + return $chunk; + } + + private function _getMap( + $address = null, + $gmapRegion = '', + $width = '500px', + $height = '500px', + $gmapLib = 'http://maps.google.com/maps/api/js?sensor=false' + ) { + $googleMap = ''; + $gmapLocations = ''; + //-- Add google Map API + if ($address) { + include_once('google_geoloc.class.inc.php'); + //-- Output the Address results + if (class_exists("geoLocator") && $address) { + //-- Split addresses for multiple points on the map + $addressList = explode('|', $address); + + $mygeoloc = new geoLocator; + $mygeoloc->region = $gmapRegion; + //$mygeoloc->host = $this->config['GOOGLE_MAP_HOST']; + //$mygeoloc->apikey = $this->config['GOOGLE_MAP_KEY']; + //$mygeoloc->canvas = $this->config['mxcGoogleMapDisplayCanvasID']; + //$mygeoloc->autofitmap = (count($addressList) > 1 ? true : false); + + foreach ($addressList as $loc) { + $mygeoloc->getGEO($loc); + } + + $googleMap = '
'; + $gmapLocations = $mygeoloc->mapJSv3; + } else { + $googleMap = 'No class found.'; + } + + return $googleMap . ' '; - } } - - public function addShadowBox($initialWidth,$initialHeight){ - $shadowPath = $this->config['assetsUrl'].'js/web/shadowbox/sa/'; - $this->modx->regClientHTMLBlock(' - + } + + public function addShadowBox($initialWidth, $initialHeight) + { + $shadowPath = $this->config['assetsUrl'] . 'js/web/shadowbox/sa/'; + $this->modx->regClientHTMLBlock(' + '); - } - public function disableModal(){ - $this->modx->regClientHTMLBLock(''); - } - - public function addLightBox(){ - $assetsPath = $this->config['assetsUrl'].'js/web/lightbox/'; - $this->modx->regClientHTMLBlock(' - + } + + public function disableModal() + { + $this->modx->regClientHTMLBLock(''); + } + + public function addLightBox() + { + $assetsPath = $this->config['assetsUrl'] . 'js/web/lightbox/'; + $this->modx->regClientHTMLBlock(' + '); + } + + + /* + * SNIPPET FUNCTIONS + */ + public function setTimeZone($newTZ = 'UTC', $debug = false) + { + if (date_default_timezone_get() != $newTZ) { + $this->tz = date_default_timezone_get(); + date_default_timezone_set($newTZ); + if ($debug) { + echo 'mxCalendar: TIMEZONE CHANGED: changed timezone for duration of this extra from ' . $this->tz . ' ' . date_default_timezone_get() . ' [' . $newTZ . ']
'; + } + } else { + if ($debug) { + echo "mxCalendar: TIMEZONE: No Change (" . date_default_timezone_get() . ")
"; + } } - - + } + + public function restoreTimeZone($debug = false) + { + if (!empty($this->tz)) { + date_default_timezone_set($this->tz); + if ($debug) { + echo "mxCalendar: TIMEZONE RESET: " . $this->tz . "
"; + } + } + } + + public function getFormatedDate($f, $t) + { + $isDST = $this->timezoneDoesDST(date_default_timezone_get()); + + if ($isDST) { + $t = $t - 3600; + } + + return str_replace('%O', date('S', $t), strftime($f, $t)); + } + + public function timezoneDoesDST($tzId) + { + $tz = new DateTimeZone($tzId); + $trans = $tz->getTransitions(); + + return ((count($trans) && $trans[count($trans) - 1]['ts'] > time())); + } + + public function custom_sort($a, $b) + { + return $a['date'] > $b['date']; + } + + //-- Custom function to get somewhat valid duration; it's fuzzy and can be updated to be more accurate + public function datediff($datefrom, $dateto, $using_timestamps = false) + { /* - * SNIPPET FUNCTIONS + * Returns an array with:years, months,days,hours,minutes */ - public function setTimeZone($newTZ='UTC',$debug=false){ - if(date_default_timezone_get() != $newTZ) { - $this->tz = date_default_timezone_get(); - date_default_timezone_set($newTZ); - if($debug) echo 'mxCalendar: TIMEZONE CHANGED: changed timezone for duration of this extra from '.$this->tz.' '.date_default_timezone_get ().' ['.$newTZ.']
'; - } else { - if($debug) echo "mxCalendar: TIMEZONE: No Change (".date_default_timezone_get().")
"; - } + if (!$using_timestamps) { + $datefrom = strtotime($datefrom, 0); + $dateto = strtotime($dateto, 0); } - public function restoreTimeZone($debug=false){ - if(!empty($this->tz)) { - date_default_timezone_set($this->tz); - if($debug) echo "mxCalendar: TIMEZONE RESET: ".$this->tz."
"; - } + $difference = $dateto - $datefrom; // Difference in seconds + //-- Year check and adjustment + if (floor($difference / 31536000) > 0) { + $diff['years'] = floor($difference / 31536000); + $difference -= floor($difference / 31536000) * 31536000; + } else { + $diff['years'] = null; } - public function getFormatedDate($f,$t){ - $isDST = $this->timezoneDoesDST(date_default_timezone_get()); - - if($isDST){ - $t = $t -3600; - } - return str_replace('%O', date('S', $t),strftime($f,$t)); + //@TODO update this to a more accurate calculation (strftime('%y%m')) + //-- Month check and adjustment + if (floor($difference / 2678400) > 0) { + $diff['months'] = floor($difference / 2678400); + $difference -= floor($difference / 2678400) * 2678400; + } else { + $diff['months'] = null; } - public function timezoneDoesDST($tzId) { - $tz = new DateTimeZone($tzId); - $trans = $tz->getTransitions(); - return ((count($trans) && $trans[count($trans) - 1]['ts'] > time())); + //-- Day check and adjustment + if (floor($difference / ((60 * 60) * 24)) > 0) { + $diff['days'] = floor($difference / ((60 * 60) * 24)); + $difference -= floor($difference / ((60 * 60) * 24)) * ((60 * 60) * 24); + } else { + $diff['days'] = null; } - public function custom_sort($a,$b){ - return $a['date']>$b['date']; + //-- Hours check and adjustment + if (floor($difference / (60 * 60)) > 0) { + $diff['hours'] = floor($difference / (60 * 60)); + $difference -= floor($difference / (60 * 60)) * (60 * 60); + } else { + $diff['hours'] = null; } - //-- Custom function to get somewhat valid duration; it's fuzzy and can be updated to be more accurate - public function datediff($datefrom, $dateto, $using_timestamps = false) - { - /* - * Returns an array with:years, months,days,hours,minutes - */ - if (!$using_timestamps) { - $datefrom = strtotime($datefrom, 0); - $dateto = strtotime($dateto, 0); - } - $difference = $dateto - $datefrom; // Difference in seconds - //-- Year check and adjustment - if( floor($difference / 31536000) > 0){ - $diff['years'] = floor($difference / 31536000); - $difference -= floor($difference / 31536000)*31536000; - } else { $diff['years']=null; } - //@TODO update this to a more accurate calculation (strftime('%y%m')) - //-- Month check and adjustment - if(floor($difference / 2678400) > 0){ - $diff['months'] = floor($difference / 2678400); - $difference -= floor($difference / 2678400)*2678400; - } else { $diff['months']=null; } - //-- Day check and adjustment - if(floor($difference / ((60 * 60)*24)) > 0){ - $diff['days'] = floor($difference / ((60 * 60)*24)); - $difference -= floor($difference / ((60 * 60)*24))*((60 * 60)*24); - } else { $diff['days']=null; } - //-- Hours check and adjustment - if(floor($difference / (60 * 60)) > 0){ - $diff['hours'] = floor($difference / (60 * 60)); - $difference -= floor($difference / (60 * 60))*(60 * 60); - } else { $diff['hours']=null; } - //-- Minutes check and adjustment - if(floor($difference / 60) > 0){ - $diff['minutes'] = floor($difference / 60); - $difference -= floor($difference / 60)*60; - } else { $diff['minutes']=null; } - //-- Seconds, that should be all we have left - $diff['seconds'] = $difference; - - return $diff; + //-- Minutes check and adjustment + if (floor($difference / 60) > 0) { + $diff['minutes'] = floor($difference / 60); + $difference -= floor($difference / 60) * 60; + } else { + $diff['minutes'] = null; } - public function makeEventDetail($events=array(),$occurance=0, $tpls=array(),$mapWidth,$mapHeight,$gmapRegion=''){ - $o = ''; - $tpls = (object)$tpls; - if(count($events)){ - $occ=0; - foreach($events AS $e){ - $output_images = ''; - $output_videos = ''; - - if($this->debug) $o .= 'Check: '.$occ.'
'; - if($occ == $occurance || ($occurance == 0 && $occ ==0)){ - $detailPH = $e[0]; - $detailPH['allplaceholders'] = implode(', ',array_keys($e[0])); - if($e[0]['map']){ - $detailPH['map'] = $this->_getMap($e[0]['location_address'],$gmapRegion,$mapWidth,$mapHeight); + //-- Seconds, that should be all we have left + $diff['seconds'] = $difference; + + return $diff; + } + + public function makeEventDetail($events = [], $occurance = 0, $tpls = [], $mapWidth, $mapHeight, $gmapRegion = '') + { + $o = ''; + $tpls = (object)$tpls; + if (count($events)) { + $occ = 0; + foreach ($events AS $e) { + $output_images = ''; + $output_videos = ''; + + if ($this->debug) { + $o .= 'Check: ' . $occ . '
'; + } + if ($occ == $occurance || ($occurance == 0 && $occ == 0)) { + $detailPH = $e[0]; + $detailPH['allplaceholders'] = implode(', ', array_keys($e[0])); + if ($e[0]['map']) { + $detailPH['map'] = $this->_getMap($e[0]['location_address'], $gmapRegion, $mapWidth, + $mapHeight); + } + + $detailPH['mapwidth'] = $mapWidth; + $detailPH['mapheight'] = $mapHeight; + + // Check for images + $images = $this->modx->getCollection('mxCalendarEventImages', + ['event_id' => $e[0]['id'], 'active' => 1]); + $detailPH['imagesTotal'] = $imgIdx = 0; + if ($images) { + foreach ($images AS $image) { + $imgIdx++; + $imgArr = $image->toArray(); + $imgArr['image_idx'] = $imgIdx; + $detailPH['images_' . $imgIdx] = $output_images .= $this->getChunk($tpls->tplImage, + $imgArr); } - - $detailPH['mapwidth'] = $mapWidth; - $detailPH['mapheight'] = $mapHeight; - - // Check for images - $images = $this->modx->getCollection('mxCalendarEventImages', array('event_id' => $e[0]['id'], 'active'=>1) ); - $detailPH['imagesTotal'] = $imgIdx = 0; - if($images){ - foreach($images AS $image){ - $imgIdx++; - $imgArr = $image->toArray(); - $imgArr['image_idx'] = $imgIdx; - $detailPH['images_'.$imgIdx] = $output_images .= $this->getChunk($tpls->tplImage, $imgArr ); - } - $detailPH['images'] = $output_images; - $detailPH['imagesTotal'] = $imgIdx; - } - - // Check for Videos - $videos = $this->modx->getCollection('mxCalendarEventVideos', array('event_id' => $e[0]['id'], 'active'=>1) ); - $detailPH['videosTotal'] = $vIdx = 0; - if($videos){ - foreach($videos AS $video){ - $vIdx++; - $videos = $video->toArray(); - $videos['video_idx'] = $vIdx; - $detailPH['videos_'.$vIdx] = $output_videos .= $this->getChunk($tpls->tplVideo, $videos ); - } - $detailPH['videos'] = $output_videos; - $detailPH['videosTotal'] = $vIdx; - } - - $o .= $this->getChunk($tpls->tplDetail,$detailPH); - break; + $detailPH['images'] = $output_images; + $detailPH['imagesTotal'] = $imgIdx; + } + + // Check for Videos + $videos = $this->modx->getCollection('mxCalendarEventVideos', + ['event_id' => $e[0]['id'], 'active' => 1]); + $detailPH['videosTotal'] = $vIdx = 0; + if ($videos) { + foreach ($videos AS $video) { + $vIdx++; + $videos = $video->toArray(); + $videos['video_idx'] = $vIdx; + $detailPH['videos_' . $vIdx] = $output_videos .= $this->getChunk($tpls->tplVideo, $videos); + } + $detailPH['videos'] = $output_videos; + $detailPH['videosTotal'] = $vIdx; } - $occ++; + + $o .= $this->getChunk($tpls->tplDetail, $detailPH); + break; } - } else { return 'No Details'; } - return $o; + $occ++; + } + } else { + return 'No Details'; } - public function makeEventList($limit=5, $events=array(),$tpls=array(),$startDate=null,$endDate=null){ - $o = ''; - $tpls = (object)$tpls; - - if(count($events)){ - $preHead = ''; - $i=0; - foreach($events AS $e){ - //-- Now we need to loop all occurances on a single date - $rvar=0; - do { - if(strftime('%b',$e[$rvar]['startdate']) != $preHead && !empty($tpls->tplElMonthHeading)){ - // Load list heading - if($preHead == '') - $e[$rvar]['altmonthheading'] = 'first'; - $o.= $this->getChunk($tpls->tplElMonthHeading,$e[$rvar]); - $preHead = strftime('%b',$e[$rvar]['startdate']); + + return $o; + } + + public function makeEventList($limit = 5, $events = [], $tpls = [], $startDate = null, $endDate = null) + { + $o = ''; + $tpls = (object)$tpls; + + if (count($events)) { + $preHead = ''; + $i = 0; + foreach ($events AS $e) { + //-- Now we need to loop all occurances on a single date + $rvar = 0; + do { + if (strftime('%b', $e[$rvar]['startdate']) != $preHead && !empty($tpls->tplElMonthHeading)) { + // Load list heading + if ($preHead == '') { + $e[$rvar]['altmonthheading'] = 'first'; } - // check for images - $output_images=''; - $images = $this->modx->getCollection('mxCalendarEventImages', array('event_id' => $e[$rvar]['id'], 'active'=>1) ); - $e[$rvar]['imagesTotal'] = $imgIdx = 0; - if($images){ - foreach($images AS $image){ - $imgIdx++; - $imgArr = $image->toArray(); - $imgArr['image_idx'] = $imgIdx; - $output_images .= $e[$rvar]['images_'.$imgIdx] = $this->getChunk($tpls->tplImage, $imgArr ); + $o .= $this->getChunk($tpls->tplElMonthHeading, $e[$rvar]); + $preHead = strftime('%b', $e[$rvar]['startdate']); + } + // check for images + $output_images = ''; + $images = $this->modx->getCollection('mxCalendarEventImages', + ['event_id' => $e[$rvar]['id'], 'active' => 1]); + $e[$rvar]['imagesTotal'] = $imgIdx = 0; + if ($images) { + foreach ($images AS $image) { + $imgIdx++; + $imgArr = $image->toArray(); + $imgArr['image_idx'] = $imgIdx; + $output_images .= $e[$rvar]['images_' . $imgIdx] = $this->getChunk($tpls->tplImage, + $imgArr); - } - } else { - //echo 'no images for '.$e[$rvar]['id'].'
'; } - - // Add the category css properties here as well - $categoryInlineCSS = array(); + } else { + //echo 'no images for '.$e[$rvar]['id'].'
'; + } - // Get the events category css info - if(!empty($e[$rvar]['categoryid'])){ - $categories = explode(',', $e[$rvar]['categoryid']); - if(count($categories)){ - foreach($categories AS $catid){ - $catQuery = $this->modx->newQuery('mxCalendarCategories'); - $catQuery->where(array('id:IN'=>$categories)); - $catproperties = $this->modx->getCollection('mxCalendarCategories',$catQuery); - if($catproperties){ - foreach($catproperties AS $catCSS){ - $categoryInlineCSS['inlinecss'] .= $catCSS->get('inlinecss'); - $categoryInlineCSS['foregroundcss'] .= $catCSS->get('foregroundcss') !== '' ? 'color:'.$catCSS->get('foregroundcss').';' : ''; - $categoryInlineCSS['backgroundcss'] .= $catCSS->get('backgroundcss') !== '' ? 'background-color:'.$catCSS->get('backgroundcss').';' : ''; - } + // Add the category css properties here as well + $categoryInlineCSS = []; + + // Get the events category css info + if (!empty($e[$rvar]['categoryid'])) { + $categories = explode(',', $e[$rvar]['categoryid']); + if (count($categories)) { + foreach ($categories AS $catid) { + $catQuery = $this->modx->newQuery('mxCalendarCategories'); + $catQuery->where(['id:IN' => $categories]); + $catproperties = $this->modx->getCollection('mxCalendarCategories', $catQuery); + if ($catproperties) { + foreach ($catproperties AS $catCSS) { + $categoryInlineCSS['inlinecss'] .= $catCSS->get('inlinecss'); + $categoryInlineCSS['foregroundcss'] .= $catCSS->get('foregroundcss') !== '' ? 'color:' . $catCSS->get('foregroundcss') . ';' : ''; + $categoryInlineCSS['backgroundcss'] .= $catCSS->get('backgroundcss') !== '' ? 'background-color:' . $catCSS->get('backgroundcss') . ';' : ''; } } } } - - $o .= $this->getChunk($tpls->tplElItem, array_merge($e[$rvar], array('images'=>$output_images), $categoryInlineCSS)); - $i++; - $rvar++; - - } while ($rvar < count($e) && $i < $limit); - if($i >= $limit) break; + } + + $o .= $this->getChunk($tpls->tplElItem, + array_merge($e[$rvar], ['images' => $output_images], $categoryInlineCSS)); + $i++; + $rvar++; + + } while ($rvar < count($e) && $i < $limit); + if ($i >= $limit) { + break; } - } else { return $this->getChunk($tpls->tplNoEvents, array('startdate'=>$startDate,'enddate'=>$endDate)); } - return $this->getChunk($tpls->tplElWrap, array('startdate'=>$startDate,'enddate'=>$endDate,'eventList'=>$o)); + } + } else { + return $this->getChunk($tpls->tplNoEvents, ['startdate' => $startDate, 'enddate' => $endDate]); } - public function getEventCalendarDateRange($activeMonthOnlyEvents=false){ - $startDate = $_REQUEST['dt'] ? $_REQUEST['dt'] : ($this->config['dt'] ? $this->config['dt'] : strftime('%Y-%m')); - $mStartDate = strftime('%Y-%m',strtotime($startDate)) . '-01 00:00:01'; - $nextMonth = strftime('%Y-%m', strtotime('+1 month',strtotime($mStartDate))); - $prevMonth = strftime('%Y-%m', strtotime('-1 month',strtotime($mStartDate))); - $startDOW = strftime('%u', strtotime($mStartDate)); - $lastDayOfMonth = strftime('%Y-%m',strtotime($mStartDate)) . '-'.date('t',strtotime($mStartDate)) .' 23:59:59'; - $startMonthCalDate = $startDOW <= 6 ? strtotime('- '.$startDOW.' day', strtotime($mStartDate)) : strtotime($mStartDate) ; - $endMonthCalDate = strtotime('+ 6 weeks', $startMonthCalDate); - if($debug) echo 'Active Month Only: '.$mStartDate.' :: '.$lastDayOfMonth.' All displayed dates: '.strftime('%Y-%m-%d',$startMonthCalDate).' :: '.strftime('%Y-%m-%d',$endMonthCalDate).'
'; - if($activeMonthOnlyEvents) return array('start'=>strtotime($mStartDate), 'end'=>strtotime($lastDayOfMonth)); else return array('start'=>$startMonthCalDate, 'end'=>$endMonthCalDate); + + return $this->getChunk($tpls->tplElWrap, ['startdate' => $startDate, 'enddate' => $endDate, 'eventList' => $o]); + } + + public function getEventCalendarDateRange($activeMonthOnlyEvents = false) + { + $startDate = $_REQUEST['dt'] ? $_REQUEST['dt'] : ($this->config['dt'] ? $this->config['dt'] : strftime('%Y-%m')); + $mStartDate = strftime('%Y-%m', strtotime($startDate)) . '-01 00:00:01'; + $nextMonth = strftime('%Y-%m', strtotime('+1 month', strtotime($mStartDate))); + $prevMonth = strftime('%Y-%m', strtotime('-1 month', strtotime($mStartDate))); + $startDOW = strftime('%u', strtotime($mStartDate)); + $lastDayOfMonth = strftime('%Y-%m', strtotime($mStartDate)) . '-' . date('t', + strtotime($mStartDate)) . ' 23:59:59'; + $startMonthCalDate = $startDOW <= 6 ? strtotime('- ' . $startDOW . ' day', + strtotime($mStartDate)) : strtotime($mStartDate); + $endMonthCalDate = strtotime('+ 6 weeks', $startMonthCalDate); + if ($debug) { + echo 'Active Month Only: ' . $mStartDate . ' :: ' . $lastDayOfMonth . ' All displayed dates: ' . strftime('%Y-%m-%d', + $startMonthCalDate) . ' :: ' . strftime('%Y-%m-%d', $endMonthCalDate) . '
'; } - public function makeEventCalendar($events=array(),$resourceId=null,$ajaxMonthResourceId=null,$tpls=array('event'=>'month.inner.container.row.day.eventclean','day'=>'month.inner.container.row.day','week'=>'month.inner.container.row','month'=>'month.inner.container','heading'=>'month.inner.container.row.heading'), $conFilter=null, $calFilter=null, $highlightToday=true){ - $time_start = microtime(true); - - $startDate = $_REQUEST['dt'] ? $_REQUEST['dt'] : strftime('%Y-%m-%d'); - $mStartDate = strftime('%Y-%m',strtotime($startDate)) . '-01 00:00:01'; - $mCurMonth = strftime('%m', strtotime($mStartDate)); - $nextMonth = strftime('%Y-%m', strtotime('+1 month',strtotime($mStartDate))); - $prevMonth = strftime('%Y-%m', strtotime('-1 month',strtotime($mStartDate))); - $startDOW = strftime('%u', strtotime($mStartDate)); - $lastDayOfMonth = strftime('%Y-%m',strtotime($mStartDate)) . '-'.date('t',strtotime($mStartDate)) .' 23:59:59'; - $endDOW = strftime('%u', strtotime($lastDayOfMonth)); - $tpls=(object)$tpls; - $out = ''; - $startMonthCalDate = $startDOW <= 6 ? strtotime('- '.$startDOW.' day', strtotime($mStartDate)) : strtotime($mStartDate) ; - $endMonthCalDate = strtotime('+ '.(6 - $endDOW).' day', strtotime($lastDayOfMonth)); - //------// - $headingLabel = strtotime($mStartDate); - $globalParams = array('conf'=>$conFilter, 'calf'=>$calFilter); - $todayLink = $this->modx->makeUrl($ajaxMonthResourceId,'', array_merge($globalParams, array('dt' => strftime('%Y-%m'), 'cid'=>$_REQUEST['cid']))); - $prevLink = $this->modx->makeUrl($ajaxMonthResourceId,'', array_merge($globalParams, array('dt' => $prevMonth, 'cid'=>$_REQUEST['cid']))); - $nextLink = $this->modx->makeUrl($ajaxMonthResourceId,'', array_merge($globalParams, array('dt' => $nextMonth, 'cid'=>$_REQUEST['cid']))); - - $chunkEvent = $this->loadChunk($tpls->event); - $chunkDay = $this->loadChunk($tpls->day); - $chunkWeek = $this->loadChunk($tpls->week); - $chunkMonth = $this->loadChunk($tpls->month); - - $heading = ''; - for($i=0;$i<7;$i++){ - if($this->debug) echo '  '.strftime('%A', strtotime('+ '.$i.' day', $startMonthCalDate)).'
'; - $thisDOW = trim('mxcalendars.label_dow_'.strtolower(strftime('%w', strtotime('+ '.$i.' day', $startMonthCalDate)))); - $heading.=$this->getChunk($tpls->heading, array('dayOfWeekId'=>'','dayOfWeekClass'=>'mxcdow', 'dayOfWeek'=> $this->modx->lexicon($thisDOW) )); + if ($activeMonthOnlyEvents) { + return ['start' => strtotime($mStartDate), 'end' => strtotime($lastDayOfMonth)]; + } else { + return ['start' => $startMonthCalDate, 'end' => $endMonthCalDate]; + } + } + + public function makeEventCalendar( + $events = [], + $resourceId = null, + $ajaxMonthResourceId = null, + $tpls = [ + 'event' => 'month.inner.container.row.day.eventclean', + 'day' => 'month.inner.container.row.day', + 'week' => 'month.inner.container.row', + 'month' => 'month.inner.container', + 'heading' => 'month.inner.container.row.heading' + ], + $conFilter = null, + $calFilter = null, + $highlightToday = true + ) { + $time_start = microtime(true); + + $startDate = $_REQUEST['dt'] ? $_REQUEST['dt'] : strftime('%Y-%m-%d'); + $mStartDate = strftime('%Y-%m', strtotime($startDate)) . '-01 00:00:01'; + $mCurMonth = strftime('%m', strtotime($mStartDate)); + $nextMonth = strftime('%Y-%m', strtotime('+1 month', strtotime($mStartDate))); + $prevMonth = strftime('%Y-%m', strtotime('-1 month', strtotime($mStartDate))); + $startDOW = strftime('%u', strtotime($mStartDate)); + $lastDayOfMonth = strftime('%Y-%m', strtotime($mStartDate)) . '-' . date('t', + strtotime($mStartDate)) . ' 23:59:59'; + $endDOW = strftime('%u', strtotime($lastDayOfMonth)); + $tpls = (object)$tpls; + $out = ''; + $startMonthCalDate = $startDOW <= 6 ? strtotime('- ' . $startDOW . ' day', + strtotime($mStartDate)) : strtotime($mStartDate); + $endMonthCalDate = strtotime('+ ' . (6 - $endDOW) . ' day', strtotime($lastDayOfMonth)); + //------// + $headingLabel = strtotime($mStartDate); + $globalParams = ['conf' => $conFilter, 'calf' => $calFilter]; + $todayLink = $this->modx->makeUrl($ajaxMonthResourceId, '', + array_merge($globalParams, ['dt' => strftime('%Y-%m'), 'cid' => $_REQUEST['cid']])); + $prevLink = $this->modx->makeUrl($ajaxMonthResourceId, '', + array_merge($globalParams, ['dt' => $prevMonth, 'cid' => $_REQUEST['cid']])); + $nextLink = $this->modx->makeUrl($ajaxMonthResourceId, '', + array_merge($globalParams, ['dt' => $nextMonth, 'cid' => $_REQUEST['cid']])); + + $chunkEvent = $this->loadChunk($tpls->event); + $chunkDay = $this->loadChunk($tpls->day); + $chunkWeek = $this->loadChunk($tpls->week); + $chunkMonth = $this->loadChunk($tpls->month); + + $heading = ''; + for ($i = 0; $i < 7; $i++) { + if ($this->debug) { + echo '  ' . strftime('%A', strtotime('+ ' . $i . ' day', $startMonthCalDate)) . '
'; } - //-- Set additional day placeholders for week - $phHeading = array( - 'weekId'=>'' - ,'weekClass'=>'' - ,'days'=>$heading - ); - //$weeks.=$chunkWeek->process($phWeek); - $heading=$this->getChunk($tpls->week, $phHeading); + $thisDOW = trim('mxcalendars.label_dow_' . strtolower(strftime('%w', + strtotime('+ ' . $i . ' day', $startMonthCalDate)))); + $heading .= $this->getChunk($tpls->heading, + ['dayOfWeekId' => '', 'dayOfWeekClass' => 'mxcdow', 'dayOfWeek' => $this->modx->lexicon($thisDOW)]); + } + //-- Set additional day placeholders for week + $phHeading = [ + 'weekId' => '' + , + 'weekClass' => '' + , + 'days' => $heading + ]; + //$weeks.=$chunkWeek->process($phWeek); + $heading = $this->getChunk($tpls->week, $phHeading); - $weeks = ''; - //-- Start the Date loop - $var=0; + $weeks = ''; + //-- Start the Date loop + $var = 0; + do { + if ($this->debug) { + echo '---------------
'; + } + if ($this->debug) { + echo 'Week ' . ($var + 1) . '
'; + } + if ($this->debug) { + echo '---------------
'; + } + // Week Start date + $iWeek = strtotime('+ ' . $var . ' week', $startMonthCalDate); + $diw = 0; + $days = ''; do { - if($this->debug) echo '---------------
'; - if($this->debug) echo 'Week '.($var + 1).'
'; - if($this->debug) echo '---------------
'; - // Week Start date - $iWeek = strtotime('+ '.$var.' week', $startMonthCalDate); - $diw = 0; - $days = ''; - do{ - // Get the week's days - $iDay = strtotime('+ '.$diw.' day', $iWeek); - $thisMonth = strftime('%m', $iDay); - if($this->debug) echo strftime('%a %b %d', $iDay).'
'; - $eventList = ''; - if(isset($events[strftime('%Y-%m-%d', $iDay)]) && count($events[strftime('%Y-%m-%d', $iDay)])){ - //-- Echo each event item - $e = $events[strftime('%Y-%m-%d', $iDay)]; - - foreach($e AS $el){ - if($this->debug) echo '  ++  '.$el['title'].'
'; - //$eventList.=$chunkEvent->process($el); - //@TODO -- FIX: Add check for display of current month - - $categoryInlineCSS = array(); - - // Get the events category css info - // Cost CPU: .5seconds for 89 events - - if(!empty($el['categoryid'])){ - $categories = explode(',', $el['categoryid']); - if(count($categories)){ - foreach($categories AS $catid){ - - $catQuery = $this->modx->newQuery('mxCalendarCategories'); - $catQuery->where(array('id:IN'=>$categories)); - $catproperties = $this->modx->getCollection('mxCalendarCategories',$catQuery); - if($catproperties){ - foreach($catproperties AS $catCSS){ - $categoryInlineCSS['inlinecss'] .= $catCSS->get('inlinecss'); - $categoryInlineCSS['foregroundcss'] .= $catCSS->get('foregroundcss') !== '' ? 'color:'.$catCSS->get('foregroundcss').';' : ''; - $categoryInlineCSS['backgroundcss'] .= $catCSS->get('backgroundcss') !== '' ? 'background-color:'.$catCSS->get('backgroundcss').';' : ''; - } + // Get the week's days + $iDay = strtotime('+ ' . $diw . ' day', $iWeek); + $thisMonth = strftime('%m', $iDay); + if ($this->debug) { + echo strftime('%a %b %d', $iDay) . '
'; + } + $eventList = ''; + if (isset($events[strftime('%Y-%m-%d', $iDay)]) && count($events[strftime('%Y-%m-%d', $iDay)])) { + //-- Echo each event item + $e = $events[strftime('%Y-%m-%d', $iDay)]; + + foreach ($e AS $el) { + if ($this->debug) { + echo '  ++  ' . $el['title'] . '
'; + } + //$eventList.=$chunkEvent->process($el); + //@TODO -- FIX: Add check for display of current month + + $categoryInlineCSS = []; + + // Get the events category css info + // Cost CPU: .5seconds for 89 events + + if (!empty($el['categoryid'])) { + $categories = explode(',', $el['categoryid']); + if (count($categories)) { + foreach ($categories AS $catid) { + + $catQuery = $this->modx->newQuery('mxCalendarCategories'); + $catQuery->where(['id:IN' => $categories]); + $catproperties = $this->modx->getCollection('mxCalendarCategories', $catQuery); + if ($catproperties) { + foreach ($catproperties AS $catCSS) { + $categoryInlineCSS['inlinecss'] .= $catCSS->get('inlinecss'); + $categoryInlineCSS['foregroundcss'] .= $catCSS->get('foregroundcss') !== '' ? 'color:' . $catCSS->get('foregroundcss') . ';' : ''; + $categoryInlineCSS['backgroundcss'] .= $catCSS->get('backgroundcss') !== '' ? 'background-color:' . $catCSS->get('backgroundcss') . ';' : ''; } - } + } } - - // Check for images - $images = $this->modx->getCollection('mxCalendarEventImages', array('event_id' => $el['id'], 'active'=>1) ); - $el['imagesTotal'] = $imgIdx = 0; - if($images){ - foreach($images AS $image){ - $imgIdx++; - $imgArr = $image->toArray(); - $imgArr['image_idx'] = $imgIdx; - $el['images_'.$imgIdx] = $output_images .= $this->getChunk($tpls->tplImage, $imgArr ); - } - $el['images'] = $output_images; - $el['imagesTotal'] = $imgIdx; - } - - $el['startdate'] = strftime('%l:%M %p', $el['startdate']); - - /** - * @todo Remove this once final performance testing is completed - */ - /* - $event_html = '
- '.$el['startdate'].' - - Images: '.$imgIdx.' - '.$el['title'].' -
'; - */ - $eventList.= $this->getChunk($tpls->event, array_merge($el,$categoryInlineCSS)); - } - } else { if($this->debug) echo '  --  '.strftime('%m-%d', $iDay).'
'; } - - //-- Set additional day placeholders for day - $isToday = (strftime('%m-%d') == strftime('%m-%d', $iDay) && $highlightToday==true ? 'today ' : ''); - $dayMonthName = strftime('%b',$iDay); - $dayMonthDay = strftime('%d',$iDay); - $dayMonthDay = (strftime('%d',$iDay) == 1 ? strftime('%b ',$iDay).( substr($dayMonthDay,0,1) == '0' ? ' '.substr($dayMonthDay,1) : $dayMonthDay ) : ( substr($dayMonthDay,0,1) == '0' ? ' '.substr($dayMonthDay,1) : $dayMonthDay )); - $phDay = array( - //'dayOfMonth'=> str_replace('0', ' ', (strftime('%d',$iDay) == 1 ? strftime('%b %d',$iDay) : strftime('%d',$iDay))) - 'dayOfMonth' => $dayMonthDay - ,'dayOfMonthID'=>'dom-'.strftime('%A%d',$iDay) - ,'events'=>$eventList - ,'fulldate'=>strftime('%m/%d/%Y', $iDay) - ,'tomorrow'=>strftime('%m/%d/%Y', strtotime('+1 day', $iDay )) - ,'yesterday'=>strftime('%m/%d/%Y', strtotime('-1 day', $iDay )) - ,'class'=> $isToday.(array_key_exists(strftime('%Y-%m-%d', $iDay),$events) ? 'hasEvents' : 'noEvents').($mCurMonth == $thisMonth ? '' : ' ncm') - ); - //$days.=$chunkDay->process($phDay); - $days.=$this->getChunk($tpls->day, $phDay); - } while (++$diw < 7); - - if($this->debug) echo '
'; - //-- Set additional day placeholders for week - $phWeek = array( - 'weekId'=>'mxcWeek'.$var - ,'weekClass'=>strftime('%A%d',$iDay) - ,'days'=>$days - ); - //$weeks.=$chunkWeek->process($phWeek); - $weeks.=$this->getChunk($tpls->week, $phWeek); - - } while (++$var < 6); //Only advance 5 weeks giving total of 6 weeks - - // - $time_end = microtime(true); - $time = $time_end - $time_start; - //echo '

mxCalendar=>makeEventCalendar() processed in '.$time.'

'; - - //-- Set additional day placeholders for month - $phMonth = array( - 'containerID'=>strftime('%a',$iDay) - ,'containerClass'=>strftime('%a%Y',$iDay) - ,'weeks'=>$heading.$weeks - ,'headingLabel'=>$headingLabel - ,'todayLink'=>$todayLink - ,'todayLabel'=> $this->modx->lexicon('mxcalendars.label_today') - ,'prevLink'=>$prevLink - ,'nextLink'=>$nextLink - ); - //return $chunkMonth->process($phMonth); - return $this->getChunk($tpls->month, $phMonth); - } - - public function makeCategoryList($labelCategory=null,$filteredCategoryId=null,$resourceId=null,$tpls=array()){ - $output = ''; - $tpls = (object)$tpls; - // build category query - $c = $this->modx->newQuery('mxCalendarCategories'); - $c->where(array( - //'name:LIKE' => '%'.$query.'%', - 'disable' => 0, - 'active' => 1, - )); - $c->sortby('name','ASC'); - $mxcalendarsCats = $this->modx->getCollection('mxCalendarCategories', $c); - // iterate - // $list = array(); - // $output .= ''; + //-- Set additional day placeholders for week + $phWeek = [ + 'weekId' => 'mxcWeek' . $var + , + 'weekClass' => strftime('%A%d', $iDay) + , + 'days' => $days + ]; + //$weeks.=$chunkWeek->process($phWeek); + $weeks .= $this->getChunk($tpls->week, $phWeek); + + } while (++$var < 6); //Only advance 5 weeks giving total of 6 weeks + + // + $time_end = microtime(true); + $time = $time_end - $time_start; + //echo '

mxCalendar=>makeEventCalendar() processed in '.$time.'

'; + + //-- Set additional day placeholders for month + $phMonth = [ + 'containerID' => strftime('%a', $iDay) + , + 'containerClass' => strftime('%a%Y', $iDay) + , + 'weeks' => $heading . $weeks + , + 'headingLabel' => $headingLabel + , + 'todayLink' => $todayLink + , + 'todayLabel' => $this->modx->lexicon('mxcalendars.label_today') + , + 'prevLink' => $prevLink + , + 'nextLink' => $nextLink + ]; + + //return $chunkMonth->process($phMonth); + return $this->getChunk($tpls->month, $phMonth); + } + + public function makeCategoryList($labelCategory = null, $filteredCategoryId = null, $resourceId = null, $tpls = []) + { + $output = ''; + $tpls = (object)$tpls; + // build category query + $c = $this->modx->newQuery('mxCalendarCategories'); + $c->where([ + //'name:LIKE' => '%'.$query.'%', + 'disable' => 0, + 'active' => 1, + ]); + $c->sortby('name', 'ASC'); + $mxcalendarsCats = $this->modx->getCollection('mxCalendarCategories', $c); + // iterate + // $list = array(); + // $output .= ''; + } + + public function processFeeds($setFeedTZ = null) + { + + require_once dirname(__FILE__) . '/mxcalendars.ics.class.php'; + + $f = $this->modx->newQuery('mxCalendarFeed'); + $f->where(['active:=' => 1, 'nextrunon:<=' => time()]); + $f->prepare(); + + $mxcfeeds = $this->modx->getCollection('mxCalendarFeed', $f); + + if ($this->loggingEnabled) { + $this->logEvent('feed', 'feeds processor called\n\nSQL:\n' . $f->toSql()); + } + + if (!empty($setFeedTZ) && is_array(json_decode($setFeedTZ, true))) { + $feedTzSettings = json_decode($setFeedTZ, true); + } else { + $feedTzSettings = null; + } + + //$this->modx->setLogLevel(modX::LOG_LEVEL_INFO); + foreach ($mxcfeeds AS $feed) { + $hadmodifications = 0; + if ($feed->get('type') == 'ical') { + + $activeUrl = $feed->get('feed'); + + $currentTZ = date_default_timezone_get(); + + if (!empty($feedTzSettings) && array_key_exists($feed->get('id'), $feedTzSettings)) { + //echo '

CURRENT TIMEZONE: '.date_default_timezone_get().'


'; + date_default_timezone_set($feedTzSettings[$feed->get('id')]); + //echo '

NEW TIMEZONE: '.date_default_timezone_get().'


'; + } + + $config = [ + "unique_id" => 'mxcfeed-' . $feed->get('id') . '-' . time(), + "url" => $activeUrl, + ]; + $vcalendar = new vcalendar($config); + $vcalendar->parse(); + + + //echo '
'.print_r($vcalendar,true).'
'; + //echo '

=========================================================

'; + + + if ($this->loggingEnabled) { + $this->logEvent('feed parse', + 'Parsing feed #' . $feed->get('id') . ' events. [' . $feed->get('feed') . ']\n\nResponse:\n' . $myics); + } + + + while ($vevent = $vcalendar->getComponent("vevent")) { + + if (!empty($feedTzSettings) && array_key_exists($feed->get('id'), $feedTzSettings)) { //echo '

CURRENT TIMEZONE: '.date_default_timezone_get().'


'; - date_default_timezone_set($feedTzSettings[$feed->get('id')]); + //date_default_timezone_set($feedTzSettings[$feed->get('id')]); //echo '

NEW TIMEZONE: '.date_default_timezone_get().'


'; } - - $config = array( "unique_id" => 'mxcfeed-'.$feed->get('id').'-'.time(), - "url" => $activeUrl, - ); - $vcalendar = new vcalendar( $config ); - $vcalendar->parse(); - - - //echo '
'.print_r($vcalendar,true).'
'; - //echo '

=========================================================

'; - - - if($this->loggingEnabled) $this->logEvent('feed parse','Parsing feed #'.$feed->get('id').' events. ['.$feed->get('feed').']\n\nResponse:\n'.$myics); - - - while( $vevent = $vcalendar->getComponent( "vevent" )) { - - if(!empty($feedTzSettings) && array_key_exists($feed->get('id'), $feedTzSettings)){ - //echo '

CURRENT TIMEZONE: '.date_default_timezone_get().'


'; - //date_default_timezone_set($feedTzSettings[$feed->get('id')]); - //echo '

NEW TIMEZONE: '.date_default_timezone_get().'


'; - } - - if($vevent->dtstart['value']){ - $start = strtotime( - implode('-',array($vevent->dtstart['value']['year'],$vevent->dtstart['value']['month'],$vevent->dtstart['value']['day'])) - .'T'. - implode(':',array($vevent->dtstart['value']['hour'],$vevent->dtstart['value']['min'],$vevent->dtstart['value']['sec'])) - . $vevent->dtstart['value']['tz'] - );// 2013-03-18T11:19:28-04:00 $this->getFormatedDate(null,,true); - - } else { $start=''; } - - if($vevent->dtend['value']){ - $end =strtotime( - implode('-',array($vevent->dtend['value']['year'],$vevent->dtend['value']['month'],$vevent->dtend['value']['day'])) - .'T'. - implode(':',array($vevent->dtend['value']['hour'],$vevent->dtend['value']['min'],$vevent->dtend['value']['sec'])) - . $vevent->dtend['value']['tz'] - ); - } else { $end = ''; } - - if($vevent->lastmodified['value']){ - $lastchange = mktime( - $vevent->lastmodified['value']['hour'], - $vevent->lastmodified['value']['min'], - $vevent->lastmodified['value']['sec'], - $vevent->lastmodified['value']['month'], - $vevent->lastmodified['value']['day'], - $vevent->lastmodified['value']['year'] - ,0 - ); - } else {$lastchange = ''; } - - if($vevent->created['value']){ - $createdDate = mktime( - $vevent->created['value']['hour'], - $vevent->created['value']['min'], - $vevent->created['value']['sec'], - $vevent->created['value']['month'], - $vevent->created['value']['day'], - $vevent->created['value']['year'] - ,0 - ); - } else { $createdDate = ''; } - - $description = str_replace(array("\r\n", "\n", "\r","\\r\\n","\\n","\\r"), '
', $vevent->getProperty( "description" )); // one occurrence - $location = $vevent->getProperty( "location" ); - $title = $vevent->getProperty( "summary" ); - $feedEventUID = $vevent->getProperty("uid"); - - //-- Multiple Occurances - //while( $comment = $vevent->getProperty( "comment" )) { // MAY occur more than once - // echo json_encode($comment).'


'; - //} - // Output for testing - $event = array( - 'title'=>$title, - 'description'=>(!empty($description) ? $description : ''), - 'location_name'=>$location, - 'startdate'=>$start, - 'enddate'=>$end, - 'source'=>'feed', - 'lastedit'=>$lastchange, - 'feeds_id'=>$feed->get('id'), - 'feeds_uid'=>$feedEventUID, - 'context'=>'', - //'categoryid'=>$feed->get('defaultcategoryid'), - 'createdon'=>$createDate, - 'repeattype'=>0, - 'repeaton'=>'', - 'repeatfrequency'=>0 - ); - //echo 'Title: '.$title.'
'.json_encode($event).'



'; - - //-- Save the new event - if(!empty($feedEventUID)){ - $existingEvent = $this->modx->getObject('mxCalendarEvents',array('feeds_uid' => $feedEventUID)); - //if(!is_object($existingEvent)){ - // $existingEvent = $this->modx->getObject('mxCalendarEvents',array('title' => $title)); - //} - } //else { - // Disable the TITLE as a valid itdentifier for duplicated events as it breaks the repeating events - // $existingEvent = $this->modx->getObject('mxCalendarEvents',array('title' => $title)); + if ($vevent->dtstart['value']) { + $start = strtotime( + implode('-', [ + $vevent->dtstart['value']['year'], + $vevent->dtstart['value']['month'], + $vevent->dtstart['value']['day'] + ]) + . 'T' . + implode(':', [ + $vevent->dtstart['value']['hour'], + $vevent->dtstart['value']['min'], + $vevent->dtstart['value']['sec'] + ]) + . $vevent->dtstart['value']['tz'] + );// 2013-03-18T11:19:28-04:00 $this->getFormatedDate(null,,true); + + } else { + $start = ''; + } + + if ($vevent->dtend['value']) { + $end = strtotime( + implode('-', [ + $vevent->dtend['value']['year'], + $vevent->dtend['value']['month'], + $vevent->dtend['value']['day'] + ]) + . 'T' . + implode(':', [ + $vevent->dtend['value']['hour'], + $vevent->dtend['value']['min'], + $vevent->dtend['value']['sec'] + ]) + . $vevent->dtend['value']['tz'] + ); + } else { + $end = ''; + } + + if ($vevent->lastmodified['value']) { + $lastchange = mktime( + $vevent->lastmodified['value']['hour'], + $vevent->lastmodified['value']['min'], + $vevent->lastmodified['value']['sec'], + $vevent->lastmodified['value']['month'], + $vevent->lastmodified['value']['day'], + $vevent->lastmodified['value']['year'] + , 0 + ); + } else { + $lastchange = ''; + } + + if ($vevent->created['value']) { + $createdDate = mktime( + $vevent->created['value']['hour'], + $vevent->created['value']['min'], + $vevent->created['value']['sec'], + $vevent->created['value']['month'], + $vevent->created['value']['day'], + $vevent->created['value']['year'] + , 0 + ); + } else { + $createdDate = ''; + } + + $description = str_replace(["\r\n", "\n", "\r", "\\r\\n", "\\n", "\\r"], '
', + $vevent->getProperty("description")); // one occurrence + $location = $vevent->getProperty("location"); + $title = $vevent->getProperty("summary"); + $feedEventUID = $vevent->getProperty("uid"); + + //-- Multiple Occurances + //while( $comment = $vevent->getProperty( "comment" )) { // MAY occur more than once + // echo json_encode($comment).'


'; + //} + + // Output for testing + $event = [ + 'title' => $title, + 'description' => (!empty($description) ? $description : ''), + 'location_name' => $location, + 'startdate' => $start, + 'enddate' => $end, + 'source' => 'feed', + 'lastedit' => $lastchange, + 'feeds_id' => $feed->get('id'), + 'feeds_uid' => $feedEventUID, + 'context' => '', + //'categoryid'=>$feed->get('defaultcategoryid'), + 'createdon' => $createDate, + 'repeattype' => 0, + 'repeaton' => '', + 'repeatfrequency' => 0 + ]; + //echo 'Title: '.$title.'
'.json_encode($event).'



'; + + //-- Save the new event + if (!empty($feedEventUID)) { + $existingEvent = $this->modx->getObject('mxCalendarEvents', ['feeds_uid' => $feedEventUID]); + //if(!is_object($existingEvent)){ + // $existingEvent = $this->modx->getObject('mxCalendarEvents',array('title' => $title)); //} - if(is_object($existingEvent)){ - // Check and modify existing event if modified since last update - if($existingEvent->get('lastedit') <= $lastchange && $existingEvent->get('source') === 'feed'){ - // Event has been updated so lets just update all properties - $existingEvent->fromArray($event); - $existingEvent->save(); - if($this->loggingEnabled){ - $this->logEvent('feed','Update Event ('.$existingEvent->get('id').') for feed #'.$feed->get('id').'\n\nEvent JSON:\n'.json_encode($event)); - } - $hadmodifications++; - } - } else { - // Create the newly found event from the feed - $feedEvent = $this->modx->newObject('mxCalendarEvents'); - - $event['categoryid']=$feed->get('defaultcategoryid'); - - $feedEvent->fromArray($event); - $feedEvent->save(); - if($this->loggingEnabled){ - $this->logEvent('feed','New Event ('.$feedEvent->get('id').') for feed #'.$feed->get('id').'\n\nEvent JSON:\n'.json_encode($event)); + } //else { + // Disable the TITLE as a valid itdentifier for duplicated events as it breaks the repeating events + // $existingEvent = $this->modx->getObject('mxCalendarEvents',array('title' => $title)); + //} + if (is_object($existingEvent)) { + // Check and modify existing event if modified since last update + if ($existingEvent->get('lastedit') <= $lastchange && $existingEvent->get('source') === 'feed') { + // Event has been updated so lets just update all properties + $existingEvent->fromArray($event); + $existingEvent->save(); + if ($this->loggingEnabled) { + $this->logEvent('feed', + 'Update Event (' . $existingEvent->get('id') . ') for feed #' . $feed->get('id') . '\n\nEvent JSON:\n' . json_encode($event)); } $hadmodifications++; } - - - } - - // Set back current TIME ZONE - date_default_timezone_set($currentTZ); - - //-- Update the feed next run time - $nextTime = strtotime('+'.$feed->get('timerint').' '.$feed->get('timermeasurement')); - $feed->set('lastrunon',time()); - $feed->set('nextrunon',$nextTime); - $feed->save(); - - if($hadmodifications){ - $this->logEvent('feed','Parsing feed #'.$feed->get('id').' had '.$hadmodifications.' event'.($hadmodifications > 1 ? 's' : '').' added/updated ['.$feed->get('feed').']'); } else { - $this->logEvent('feed','Parsing feed #'.$feed->get('id').' had no changes. ['.$feed->get('feed').']'); + // Create the newly found event from the feed + $event['categoryid'] = $feed->get('defaultcategoryid'); + $feedEvent = $this->modx->newObject('mxCalendarEvents', $event); + $feedEvent->save(); + if ($this->loggingEnabled) { + $this->logEvent('feed', + 'New Event (' . $feedEvent->get('id') . ') for feed #' . $feed->get('id') . '\n\nEvent JSON:\n' . json_encode($event)); + } + $hadmodifications++; } - + + + } + + // Set back current TIME ZONE + date_default_timezone_set($currentTZ); + + //-- Update the feed next run time + $nextTime = strtotime('+' . $feed->get('timerint') . ' ' . $feed->get('timermeasurement')); + $feed->set('lastrunon', time()); + $feed->set('nextrunon', $nextTime); + $feed->save(); + + if ($hadmodifications) { + $this->logEvent('feed', + 'Parsing feed #' . $feed->get('id') . ' had ' . $hadmodifications . ' event' . ($hadmodifications > 1 ? 's' : '') . ' added/updated [' . $feed->get('feed') . ']'); } else { - //-- ==================== --// - //-- Process the XML feed --// - //-- ==================== --// - $activeUrl = $feed->get('feed'); - $xmlEvents = file_get_contents($activeUrl); + $this->logEvent('feed', + 'Parsing feed #' . $feed->get('id') . ' had no changes. [' . $feed->get('feed') . ']'); + } + + } else { + //-- ==================== --// + //-- Process the XML feed --// + //-- ==================== --// + $activeUrl = $feed->get('feed'); + $xmlEvents = file_get_contents($activeUrl); + if (!empty($xmlEvents)) { $events = new SimpleXMLElement($xmlEvents); $idx = 0; foreach ($events->event as $event) { - if(strtolower($event->timebegin) !== 'all day'){ - $startDateTime = strtotime($event->date.' '.$event->timebegin); - $endDateTime = strtotime($event->date.' '.str_replace('- ', '', $event->timeend)); + if (strtolower($event->timebegin) !== 'all day') { + $startDateTime = strtotime($event->date . ' ' . $event->timebegin); + $endDateTime = strtotime($event->date . ' ' . str_replace('- ', '', $event->timeend)); } else { - $startDateTime = strtotime($event->date.' 00:00:00'); - $endDateTime = strtotime($event->date.' 23:59:59'); + $startDateTime = strtotime($event->date . ' 00:00:00'); + $endDateTime = strtotime($event->date . ' 23:59:59'); } $lastchange = (!empty($event->lastedit) ? $event->lastedit : time()); // Output for testing - $eventdata = array( - 'title'=>$event->title, - 'description'=>(!empty($event->description) ? $event->description : ''), - 'location_name'=>(!empty($event->location) ? $event->location : ''), - 'startdate'=>$startDateTime, - 'enddate'=>$endDateTime, - 'source'=>'feed', - 'lastedit'=>$lastchange, - 'feeds_id'=>$feed->get('id'), - 'feeds_uid'=> (!empty($event->eventid) ? $event->eventid : ''), - 'context'=>'', - 'categoryid'=>$feed->get('defaultcategoryid'), - 'createdon'=>(!empty($event->createDate) ? $event->createDate : time()), - 'repeattype'=>0, - 'repeaton'=>'', - 'repeatfrequency'=>0 - ); + $eventdata = [ + 'title' => $event->title, + 'description' => (!empty($event->description) ? $event->description : ''), + 'location_name' => (!empty($event->location) ? $event->location : ''), + 'startdate' => $startDateTime, + 'enddate' => $endDateTime, + 'source' => 'feed', + 'lastedit' => $lastchange, + 'feeds_id' => $feed->get('id'), + 'feeds_uid' => (!empty($event->eventid) ? $event->eventid : ''), + 'context' => '', + 'categoryid' => $feed->get('defaultcategoryid'), + 'createdon' => (!empty($event->createDate) ? $event->createDate : time()), + 'repeattype' => 0, + 'repeaton' => '', + 'repeatfrequency' => 0 + ]; //-- Save the new event - if(!empty($event->eventid) && isset($event->eventid) ){ - $q = $this->modx->newQuery('mxCalendarEvents'); - $title = (string)$event->title; - $feeduid = (string)$event->eventid; - $q->where(array( - 'mxCalendarEvents.title' => $title, - 'mxCalendarEvents.feeds_id' => $feed->get('id'), - 'mxCalendarEvents.feeds_uid' => $feeduid - )); - $q->prepare(); - //echo 'SQL ['.$event->title.' '.$event->eventid.']:
'.$q->toSQL().'

'; - $existingEvent = $this->modx->getObject('mxCalendarEvents',$q); + if (!empty($event->eventid) && isset($event->eventid)) { + $q = $this->modx->newQuery('mxCalendarEvents'); + $title = (string)$event->title; + $feeduid = (string)$event->eventid; + $q->where([ + 'mxCalendarEvents.title' => $title, + 'mxCalendarEvents.feeds_id' => $feed->get('id'), + 'mxCalendarEvents.feeds_uid' => $feeduid + ]); + $q->prepare(); + //echo 'SQL ['.$event->title.' '.$event->eventid.']:
'.$q->toSQL().'

'; + $existingEvent = $this->modx->getObject('mxCalendarEvents', $q); //$existingEvent = $this->modx->getObject('mxCalendarEvents',array()); } else { $existingEvent = false; } - if(is_object($existingEvent)){ + if (is_object($existingEvent)) { // Check and modify existing event if modified since last update - if($existingEvent->get('lastedit') <= $lastchange){ + if ($existingEvent->get('lastedit') <= $lastchange) { // Event has been updated so lets just update all properties $existingEvent->fromArray($eventdata); $existingEvent->save(); - if($this->loggingEnabled){ - $this->logEvent('feed','Update Event ('.$existingEvent->get('id').')['.$event->eventid.'] for feed #'.$feed->get('id').'\n\nEvent JSON:\n'.json_encode($event)); + if ($this->loggingEnabled) { + $this->logEvent('feed', + 'Update Event (' . $existingEvent->get('id') . ')[' . $event->eventid . '] for feed #' . $feed->get('id') . '\n\nEvent JSON:\n' . json_encode($event)); } $hadmodifications++; } @@ -878,8 +1068,9 @@ public function processFeeds($setFeedTZ=null){ $feedEvent = $this->modx->newObject('mxCalendarEvents'); $feedEvent->fromArray($eventdata); $feedEvent->save(); - if($this->loggingEnabled){ - $this->logEvent('feed','New Event ('.$feedEvent->get('id').') for feed #'.$feed->get('id').'\n\nEvent JSON:\n'.json_encode($event)); + if ($this->loggingEnabled) { + $this->logEvent('feed', + 'New Event (' . $feedEvent->get('id') . ') for feed #' . $feed->get('id') . '\n\nEvent JSON:\n' . json_encode($event)); } $hadmodifications++; } @@ -887,72 +1078,90 @@ public function processFeeds($setFeedTZ=null){ $idx++; } //-- Update the feed next run time - $nextTime = strtotime('+'.$feed->get('timerint').' '.$feed->get('timermeasurement')); - $feed->set('lastrunon',time()); - $feed->set('nextrunon',$nextTime); + $nextTime = strtotime('+' . $feed->get('timerint') . ' ' . $feed->get('timermeasurement')); + $feed->set('lastrunon', time()); + $feed->set('nextrunon', $nextTime); $feed->save(); - if($hadmodifications){ - $this->logEvent('feed','Parsing feed #'.$feed->get('id').' had '.$hadmodifications.' event'.($hadmodifications > 1 ? 's' : '').' added/updated ['.$feed->get('feed').']'); + if ($hadmodifications) { + $this->logEvent('feed', + 'Parsing feed #' . $feed->get('id') . ' had ' . $hadmodifications . ' event' . ($hadmodifications > 1 ? 's' : '') . ' added/updated [' . $feed->get('feed') . ']'); } else { - $this->logEvent('feed','Parsing feed #'.$feed->get('id').' had no changes. ['.$feed->get('feed').']'); + $this->logEvent('feed', + 'Parsing feed #' . $feed->get('id') . ' had no changes. [' . $feed->get('feed') . ']'); } - } } - - - } - - public function logEvent($itemType='',$log=''){ - $mxclog = $this->modx->newObject('mxCalendarLog',array( - 'itemtype' => $itemType, - 'log' => $log, - 'datetime' => time(), - )); - $mxclog->save(); } + + + } + + public function logEvent($itemType = '', $log = '') + { + $mxclog = $this->modx->newObject('mxCalendarLog', [ + 'itemtype' => $itemType, + 'log' => $log, + 'datetime' => time(), + ]); + $mxclog->save(); + } } /** * Class to help with tracking processing times - * + * */ -class makeProcessTime { +class makeProcessTime +{ public $globalStartProcess, $startProcess, $endProcess, $debug; - public function __construct($gsProc=null,$debug){ + + public function __construct($gsProc = null, $debug) + { $this->debug = !empty($debug) ? $debug : 0; $now = microtime(true); - if(!empty($gsProc)){ - self::set('globalStartProcess',$gsProc); + if (!empty($gsProc)) { + $this->set('globalStartProcess', $gsProc); } - self::set('startProcess',$now); - + $this->set('startProcess', $now); + } - public function set($property='',$val=null){ - if(!empty($property)){ + + public function set($property = '', $val = null) + { + if (!empty($property)) { $this->{$property} = $val; } } - public function get($property=''){ - if(!empty($property)){ + + public function get($property = '') + { + if (!empty($property)) { return $this->{$property}; } + return false; } - public function getTime(){ + + public function getTime() + { return $this->endProcess - $this->startProcess; } - public function end($echoMessage=''){ - self::set('endProcess',microtime(true)); - if(!empty($echoMessage) && $this->debug){ - if(!empty($this->globalStartProcess)) - echo $echoMessage.' started @'.($this->startProcess - $this->globalStartProcess).' and ended @'.($this->endProcess - $this->globalStartProcess).' for total processing time of '.self::getTime().' seconds
'; - else - echo $echoMessage.' had a total processing time of '.self::getTime().' seconds
'; - } else { - return self::getTime(); + + public function end($echoMessage = '') + { + $this->set('endProcess', microtime(true)); + if (!empty($echoMessage) && $this->debug) { + if (!empty($this->globalStartProcess)) { + echo $echoMessage . ' started @' . ($this->startProcess - $this->globalStartProcess) . ' and ended @' . ($this->endProcess - $this->globalStartProcess) . ' for total processing time of ' . $this->getTime() . ' seconds
'; + } else { + echo $echoMessage . ' had a total processing time of ' . $this->getTime() . ' seconds
'; + } + + return ''; } + + return $this->getTime(); } } \ No newline at end of file diff --git a/core/components/mxcalendars/model/mxcalendars/mxcalendars.class.php b/core/components/mxcalendars/model/mxcalendars/mxcalendars.class.php index ffb31e9..1f499dc 100644 --- a/core/components/mxcalendars/model/mxcalendars/mxcalendars.class.php +++ b/core/components/mxcalendars/model/mxcalendars/mxcalendars.class.php @@ -1,39 +1,43 @@ 1,'Tue'=>2,'Wed'=>3,'Thu'=>4,'Fri'=>5,'Sat'=>6,'Sun'=>7); + private $scriptProperties = []; + private $dowMatch = ['Mon' => 1, 'Tue' => 2, 'Wed' => 3, 'Thu' => 4, 'Fri' => 5, 'Sat' => 6, 'Sun' => 7]; public $debug = false; - - function __construct(modX &$modx,array $config = array()) { + + function __construct(modX &$modx, array $config = []) + { $this->modx =& $modx; - - $basePath = $this->modx->getOption('mxcalendars.core_path',$config,$this->modx->getOption('core_path').'components/mxcalendars/'); - $assetsUrl = $this->modx->getOption('mxcalendars.assets_url',$config,$this->modx->getOption('assets_url').'components/mxcalendars/'); - $descriptionEditorMode = $this->modx->getOption('mxcalendars.event_desc_type','htmleditor'); - $categoryRequired = $this->modx->getOption('mxcalendars.category_required','true'); + + $basePath = $this->modx->getOption('mxcalendars.core_path', $config, + $this->modx->getOption('core_path') . 'components/mxcalendars/'); + $assetsUrl = $this->modx->getOption('mxcalendars.assets_url', $config, + $this->modx->getOption('assets_url') . 'components/mxcalendars/'); + $descriptionEditorMode = $this->modx->getOption('mxcalendars.event_desc_type', 'htmleditor'); + $categoryRequired = $this->modx->getOption('mxcalendars.category_required', 'true'); $this->loggingEnabled = $this->modx->getOption('mxcalendars.mgr_log_enable', 0); - $this->config = array_merge(array( + $this->config = array_merge([ 'basePath' => $basePath, 'corePath' => $basePath, - 'modelPath' => $basePath.'model/', - 'processorsPath' => $basePath.'processors/', - 'chunksPath' => $basePath.'elements/chunks/', - 'jsUrl' => $assetsUrl.'js/', - 'cssUrl' => $assetsUrl.'css/', + 'modelPath' => $basePath . 'model/', + 'processorsPath' => $basePath . 'processors/', + 'chunksPath' => $basePath . 'elements/chunks/', + 'jsUrl' => $assetsUrl . 'js/', + 'cssUrl' => $assetsUrl . 'css/', 'assetsUrl' => $assetsUrl, - 'connectorUrl' => $assetsUrl.'connector.php', + 'connectorUrl' => $assetsUrl . 'connector.php', 'category_required' => $categoryRequired, 'event_desc_type' => $descriptionEditorMode, 'mgr_dateformat' => $this->modx->getOption('mxcalendars.mgr_dateformat', '', 'm/d/Y'), @@ -42,121 +46,144 @@ function __construct(modX &$modx,array $config = array()) { 'mgr_allday_start' => $this->modx->getOption('mxcalendars.mgr_allday_start', '', '8:00 am'), 'mgr_allday_end' => $this->modx->getOption('mxcalendars.mgr_allday_end', '', '5:00 pm'), 'isAdministrator' => $this->modx->user->isMember('Administrator'), - ),$config); - $this->modx->addPackage('mxcalendars',$this->config['modelPath']); - $this->modx->getService('lexicon','modLexicon'); + ], $config); + $this->modx->addPackage('mxcalendars', $this->config['modelPath']); + $this->modx->getService('lexicon', 'modLexicon'); $this->modx->lexicon->load('mxcalendars:default'); - - + + } - - /* - * MANAGER: Initialize the manager view for calendar item management - */ - public function initialize($ctx = 'web') { - - $this->processFeeds(); - - switch ($ctx) { - case 'mgr': - $this->modx->lexicon->load('mxcalendars:default'); - if (!$this->modx->loadClass('mxcalendarControllerRequest',$this->config['modelPath'].'mxcalendars/request/',true,true)) { - return 'Could not load controller request handler. ['.$this->config['modelPath'].'mxcalendars/request/]'; - } - $this->request = new mxcalendarControllerRequest($this); - - return $this->request->handleRequest(); - break; - } - return true; - } - - public function setProperties($p=array()){ - $this->scriptProperties = $p; + + /* + * MANAGER: Initialize the manager view for calendar item management + */ + public function initialize($ctx = 'web') + { + + $this->processFeeds(); + + switch ($ctx) { + case 'mgr': + $this->modx->lexicon->load('mxcalendars:default'); + if (!$this->modx->loadClass('mxcalendarControllerRequest', + $this->config['modelPath'] . 'mxcalendars/request/', true, true)) { + return 'Could not load controller request handler. [' . $this->config['modelPath'] . 'mxcalendars/request/]'; + } + $this->request = new mxcalendarControllerRequest($this); + + return $this->request->handleRequest(); + break; } - - /* - * GLOBAL HELPER FUNCTIONS: do what we can to making life easier - */ - public function loadChunk($name) { - $chunk = null; - if (!isset($this->chunks[$name])) { - $chunk = $this->_getTplChunk($name); - if (empty($chunk)) { - $chunk = $this->modx->getObject('modChunk',array('name' => $name)); - if ($chunk == false) return false; - } - + + return true; + } + + public function setProperties($p = []) + { + $this->scriptProperties = $p; + } + + /* + * GLOBAL HELPER FUNCTIONS: do what we can to making life easier + */ + public function loadChunk($name) + { + $chunk = null; + if (!isset($this->chunks[$name])) { + $chunk = $this->_getTplChunk($name); + if (empty($chunk)) { + $chunk = $this->modx->getObject('modChunk', ['name' => $name]); + if ($chunk == false) { + return false; } - return $chunk; - } - //@TODO remove; not used - public function parseChunk($name,$properties=array()){ - return $this->modx->getChunk($name,$properties); + } + } - - public function getChunk($name,$properties = array()) { - $chunk = null; - if (!isset($this->chunks[$name])) { - $chunk = $this->_getTplChunk($name); - if (empty($chunk)) { - $chunk = $this->modx->getObject('modChunk',array('name' => $name)); - if ($chunk == false) return false; - } - $this->chunks[$name] = $chunk->getContent(); - } else { - $o = $this->chunks[$name]; - $chunk = $this->modx->newObject('modChunk'); - $chunk->setContent($o); - } - $chunk->setCacheable(true); - return $chunk->process($properties); - } - - private function _getTplChunk($name,$postfix = '.chunk.tpl') { - $chunk = false; - $f = $this->config['chunksPath'].strtolower($name).$postfix; - if (file_exists($f)) { - $o = file_get_contents($f); - $chunk = $this->modx->newObject('modChunk'); - $chunk->set('name',$name); - $chunk->setContent($o); - } - return $chunk; - } - - private function _getMap($address=null,$gmapRegion='',$width='500px',$height='500px', $gmapLib='http://maps.google.com/maps/api/js?sensor=false'){ - $googleMap = ''; - $gmapLocations = ''; - //-- Add google Map API - if($address){ - include_once('google_geoloc.class.inc'); - //-- Output the Address results - if(class_exists("geoLocator") && $address){ - //-- Split addresses for multiple points on the map - $addressList = explode('|', $address); - - $mygeoloc = new geoLocator; - $mygeoloc->region = $gmapRegion; - //$mygeoloc->host = $this->config['GOOGLE_MAP_HOST']; - //$mygeoloc->apikey = $this->config['GOOGLE_MAP_KEY']; - //$mygeoloc->canvas = $this->config['mxcGoogleMapDisplayCanvasID']; - //$mygeoloc->autofitmap = (count($addressList) > 1 ? true : false); - - foreach($addressList as $loc){ - $mygeoloc->getGEO($loc); - } - $googleMap = '
'; - $gmapLocations = $mygeoloc->mapJSv3; - } else { - $googleMap = 'No class found.'; - } - return $googleMap.' + return $chunk; + } + + //@TODO remove; not used + public function parseChunk($name, $properties = []) + { + return $this->modx->getChunk($name, $properties); + } + + public function getChunk($name, $properties = []) + { + $chunk = null; + if (!isset($this->chunks[$name])) { + $chunk = $this->_getTplChunk($name); + if (empty($chunk)) { + $chunk = $this->modx->getObject('modChunk', ['name' => $name]); + if ($chunk == false) { + return false; + } + } + $this->chunks[$name] = $chunk->getContent(); + } else { + $o = $this->chunks[$name]; + $chunk = $this->modx->newObject('modChunk'); + $chunk->setContent($o); + } + $chunk->setCacheable(true); + + return $chunk->process($properties); + } + + private function _getTplChunk($name, $postfix = '.chunk.tpl') + { + $chunk = false; + $f = $this->config['chunksPath'] . strtolower($name) . $postfix; + if (file_exists($f)) { + $o = file_get_contents($f); + $chunk = $this->modx->newObject('modChunk'); + $chunk->set('name', $name); + $chunk->setContent($o); + } + + return $chunk; + } + + private function _getMap( + $address = null, + $gmapRegion = '', + $width = '500px', + $height = '500px', + $gmapLib = 'http://maps.google.com/maps/api/js?sensor=false' + ) { + $googleMap = ''; + $gmapLocations = ''; + //-- Add google Map API + if ($address) { + include_once('google_geoloc.class.inc'); + //-- Output the Address results + if (class_exists("geoLocator") && $address) { + //-- Split addresses for multiple points on the map + $addressList = explode('|', $address); + + $mygeoloc = new geoLocator; + $mygeoloc->region = $gmapRegion; + //$mygeoloc->host = $this->config['GOOGLE_MAP_HOST']; + //$mygeoloc->apikey = $this->config['GOOGLE_MAP_KEY']; + //$mygeoloc->canvas = $this->config['mxcGoogleMapDisplayCanvasID']; + //$mygeoloc->autofitmap = (count($addressList) > 1 ? true : false); + + foreach ($addressList as $loc) { + $mygeoloc->getGEO($loc); + } + + $googleMap = '
'; + $gmapLocations = $mygeoloc->mapJSv3; + } else { + $googleMap = 'No class found.'; + } + + return $googleMap . ' '; - } } - - public function addShadowBox($initialWidth,$initialHeight){ - $shadowPath = $this->config['assetsUrl'].'js/web/shadowbox/sa/'; - $this->modx->regClientHTMLBlock(' - + } + + public function addShadowBox($initialWidth, $initialHeight) + { + $shadowPath = $this->config['assetsUrl'] . 'js/web/shadowbox/sa/'; + $this->modx->regClientHTMLBlock(' + '); - } - public function disableModal(){ - $this->modx->regClientHTMLBLock(''); - } - - public function addLightBox(){ - $assetsPath = $this->config['assetsUrl'].'js/web/lightbox/'; - $this->modx->regClientHTMLBlock(' - + } + + public function disableModal() + { + $this->modx->regClientHTMLBLock(''); + } + + public function addLightBox() + { + $assetsPath = $this->config['assetsUrl'] . 'js/web/lightbox/'; + $this->modx->regClientHTMLBlock(' + '); + } + + + /* + * SNIPPET FUNCTIONS + */ + public function setTimeZone($newTZ = 'UTC', $debug = false) + { + if (date_default_timezone_get() != $newTZ) { + $this->tz = date_default_timezone_get(); + date_default_timezone_set($newTZ); + if ($debug) { + echo 'mxCalendar: TIMEZONE CHANGED: changed timezone for duration of this extra from ' . $this->tz . ' ' . date_default_timezone_get() . ' [' . $newTZ . ']
'; + } + } else { + if ($debug) { + echo "mxCalendar: TIMEZONE: No Change (" . date_default_timezone_get() . ")
"; + } + } + } + + public function restoreTimeZone($debug = false) + { + if (!empty($this->tz)) { + date_default_timezone_set($this->tz); + if ($debug) { + echo "mxCalendar: TIMEZONE RESET: " . $this->tz . "
"; + } } - - + } + + public function getFormatedDate($f, $t) + { + $isDST = $this->timezoneDoesDST(date_default_timezone_get()); + + if ($isDST) { + $t = $t - 3600; + } + + return str_replace('%O', date('S', $t), strftime($f, $t)); + } + + public function timezoneDoesDST($tzId) + { + $tz = new DateTimeZone($tzId); + $trans = $tz->getTransitions(); + + return ((count($trans) && $trans[count($trans) - 1]['ts'] > time())); + } + + public function custom_sort($a, $b) + { + return $a['date'] > $b['date']; + } + + //-- Custom function to get somewhat valid duration; it's fuzzy and can be updated to be more accurate + public function datediff($datefrom, $dateto, $using_timestamps = false) + { /* - * SNIPPET FUNCTIONS + * Returns an array with:years, months,days,hours,minutes */ - public function setTimeZone($newTZ='UTC',$debug=false){ - if(date_default_timezone_get() != $newTZ) { - $this->tz = date_default_timezone_get(); - date_default_timezone_set($newTZ); - if($debug) echo 'mxCalendar: TIMEZONE CHANGED: changed timezone for duration of this extra from '.$this->tz.' '.date_default_timezone_get ().' ['.$newTZ.']
'; - } else { - if($debug) echo "mxCalendar: TIMEZONE: No Change (".date_default_timezone_get().")
"; - } + if (!$using_timestamps) { + $datefrom = strtotime($datefrom, 0); + $dateto = strtotime($dateto, 0); } - public function restoreTimeZone($debug=false){ - if(!empty($this->tz)) { - date_default_timezone_set($this->tz); - if($debug) echo "mxCalendar: TIMEZONE RESET: ".$this->tz."
"; - } + $difference = $dateto - $datefrom; // Difference in seconds + //-- Year check and adjustment + if (floor($difference / 31536000) > 0) { + $diff['years'] = floor($difference / 31536000); + $difference -= floor($difference / 31536000) * 31536000; + } else { + $diff['years'] = null; } - public function getFormatedDate($f,$t){ - $isDST = $this->timezoneDoesDST(date_default_timezone_get()); - - if($isDST){ - $t = $t -3600; - } - return str_replace('%O', date('S', $t),strftime($f,$t)); + //@TODO update this to a more accurate calculation (strftime('%y%m')) + //-- Month check and adjustment + if (floor($difference / 2678400) > 0) { + $diff['months'] = floor($difference / 2678400); + $difference -= floor($difference / 2678400) * 2678400; + } else { + $diff['months'] = null; } - public function timezoneDoesDST($tzId) { - $tz = new DateTimeZone($tzId); - $trans = $tz->getTransitions(); - return ((count($trans) && $trans[count($trans) - 1]['ts'] > time())); + //-- Day check and adjustment + if (floor($difference / ((60 * 60) * 24)) > 0) { + $diff['days'] = floor($difference / ((60 * 60) * 24)); + $difference -= floor($difference / ((60 * 60) * 24)) * ((60 * 60) * 24); + } else { + $diff['days'] = null; } - public function custom_sort($a,$b){ - return $a['date']>$b['date']; + //-- Hours check and adjustment + if (floor($difference / (60 * 60)) > 0) { + $diff['hours'] = floor($difference / (60 * 60)); + $difference -= floor($difference / (60 * 60)) * (60 * 60); + } else { + $diff['hours'] = null; } - //-- Custom function to get somewhat valid duration; it's fuzzy and can be updated to be more accurate - public function datediff($datefrom, $dateto, $using_timestamps = false) - { - /* - * Returns an array with:years, months,days,hours,minutes - */ - if (!$using_timestamps) { - $datefrom = strtotime($datefrom, 0); - $dateto = strtotime($dateto, 0); - } - $difference = $dateto - $datefrom; // Difference in seconds - //-- Year check and adjustment - if( floor($difference / 31536000) > 0){ - $diff['years'] = floor($difference / 31536000); - $difference -= floor($difference / 31536000)*31536000; - } else { $diff['years']=null; } - //@TODO update this to a more accurate calculation (strftime('%y%m')) - //-- Month check and adjustment - if(floor($difference / 2678400) > 0){ - $diff['months'] = floor($difference / 2678400); - $difference -= floor($difference / 2678400)*2678400; - } else { $diff['months']=null; } - //-- Day check and adjustment - if(floor($difference / ((60 * 60)*24)) > 0){ - $diff['days'] = floor($difference / ((60 * 60)*24)); - $difference -= floor($difference / ((60 * 60)*24))*((60 * 60)*24); - } else { $diff['days']=null; } - //-- Hours check and adjustment - if(floor($difference / (60 * 60)) > 0){ - $diff['hours'] = floor($difference / (60 * 60)); - $difference -= floor($difference / (60 * 60))*(60 * 60); - } else { $diff['hours']=null; } - //-- Minutes check and adjustment - if(floor($difference / 60) > 0){ - $diff['minutes'] = floor($difference / 60); - $difference -= floor($difference / 60)*60; - } else { $diff['minutes']=null; } - //-- Seconds, that should be all we have left - $diff['seconds'] = $difference; - - return $diff; + //-- Minutes check and adjustment + if (floor($difference / 60) > 0) { + $diff['minutes'] = floor($difference / 60); + $difference -= floor($difference / 60) * 60; + } else { + $diff['minutes'] = null; } - public function makeEventDetail($events=array(),$occurance=0, $tpls=array(),$mapWidth,$mapHeight,$gmapRegion=''){ - $o = ''; - $tpls = (object)$tpls; - if(count($events)){ - $occ=0; - foreach($events AS $e){ - $output_images = ''; - $output_videos = ''; - - if($this->debug) $o .= 'Check: '.$occ.'
'; - if($occ == $occurance || ($occurance == 0 && $occ ==0)){ - $detailPH = $e[0]; - $detailPH['allplaceholders'] = implode(', ',array_keys($e[0])); - if($e[0]['map']){ - $detailPH['map'] = $this->_getMap($e[0]['location_address'],$gmapRegion,$mapWidth,$mapHeight); + //-- Seconds, that should be all we have left + $diff['seconds'] = $difference; + + return $diff; + } + + public function makeEventDetail($events = [], $occurance = 0, $tpls = [], $mapWidth, $mapHeight, $gmapRegion = '') + { + $o = ''; + $tpls = (object)$tpls; + if (count($events)) { + $occ = 0; + foreach ($events AS $e) { + $output_images = ''; + $output_videos = ''; + + if ($this->debug) { + $o .= 'Check: ' . $occ . '
'; + } + if ($occ == $occurance || ($occurance == 0 && $occ == 0)) { + $detailPH = $e[0]; + $detailPH['allplaceholders'] = implode(', ', array_keys($e[0])); + if ($e[0]['map']) { + $detailPH['map'] = $this->_getMap($e[0]['location_address'], $gmapRegion, $mapWidth, + $mapHeight); + } + + $detailPH['mapwidth'] = $mapWidth; + $detailPH['mapheight'] = $mapHeight; + + // Check for images + $images = $this->modx->getCollection('mxCalendarEventImages', + ['event_id' => $e[0]['id'], 'active' => 1]); + $detailPH['imagesTotal'] = $imgIdx = 0; + if ($images) { + foreach ($images AS $image) { + $imgIdx++; + $imgArr = $image->toArray(); + $imgArr['image_idx'] = $imgIdx; + $detailPH['images_' . $imgIdx] = $output_images .= $this->getChunk($tpls->tplImage, + $imgArr); } - - $detailPH['mapwidth'] = $mapWidth; - $detailPH['mapheight'] = $mapHeight; - - // Check for images - $images = $this->modx->getCollection('mxCalendarEventImages', array('event_id' => $e[0]['id'], 'active'=>1) ); - $detailPH['imagesTotal'] = $imgIdx = 0; - if($images){ - foreach($images AS $image){ - $imgIdx++; - $imgArr = $image->toArray(); - $imgArr['image_idx'] = $imgIdx; - $detailPH['images_'.$imgIdx] = $output_images .= $this->getChunk($tpls->tplImage, $imgArr ); - } - $detailPH['images'] = $output_images; - $detailPH['imagesTotal'] = $imgIdx; - } - - // Check for Videos - $videos = $this->modx->getCollection('mxCalendarEventVideos', array('event_id' => $e[0]['id'], 'active'=>1) ); - $detailPH['videosTotal'] = $vIdx = 0; - if($videos){ - foreach($videos AS $video){ - $vIdx++; - $videos = $video->toArray(); - $videos['video_idx'] = $vIdx; - $detailPH['videos_'.$vIdx] = $output_videos .= $this->getChunk($tpls->tplVideo, $videos ); - } - $detailPH['videos'] = $output_videos; - $detailPH['videosTotal'] = $vIdx; - } - - $o .= $this->getChunk($tpls->tplDetail,$detailPH); - break; + $detailPH['images'] = $output_images; + $detailPH['imagesTotal'] = $imgIdx; + } + + // Check for Videos + $videos = $this->modx->getCollection('mxCalendarEventVideos', + ['event_id' => $e[0]['id'], 'active' => 1]); + $detailPH['videosTotal'] = $vIdx = 0; + if ($videos) { + foreach ($videos AS $video) { + $vIdx++; + $videos = $video->toArray(); + $videos['video_idx'] = $vIdx; + $detailPH['videos_' . $vIdx] = $output_videos .= $this->getChunk($tpls->tplVideo, $videos); + } + $detailPH['videos'] = $output_videos; + $detailPH['videosTotal'] = $vIdx; } - $occ++; + + $o .= $this->getChunk($tpls->tplDetail, $detailPH); + break; } - } else { return 'No Details'; } - return $o; + $occ++; + } + } else { + return 'No Details'; } - public function makeEventList($limit=5, $events=array(),$tpls=array(),$startDate=null,$endDate=null){ - $o = ''; - $tpls = (object)$tpls; - $output_images=''; - if(count($events)){ - $preHead = ''; - $i=0; - foreach($events AS $e){ - //-- Now we need to loop all occurances on a single date - $rvar=0; - do { - if(strftime('%b',$e[$rvar]['startdate']) != $preHead && !empty($tpls->tplElMonthHeading)){ - // Load list heading - if($preHead == '') - $e[$rvar]['altmonthheading'] = 'first'; - $o.= $this->getChunk($tpls->tplElMonthHeading,$e[$rvar]); - $preHead = strftime('%b',$e[$rvar]['startdate']); + + return $o; + } + + public function makeEventList($limit = 5, $events = [], $tpls = [], $startDate = null, $endDate = null) + { + $o = ''; + $tpls = (object)$tpls; + $output_images = ''; + if (count($events)) { + $preHead = ''; + $i = 0; + foreach ($events AS $e) { + //-- Now we need to loop all occurances on a single date + $rvar = 0; + do { + if (strftime('%b', $e[$rvar]['startdate']) != $preHead && !empty($tpls->tplElMonthHeading)) { + // Load list heading + if ($preHead == '') { + $e[$rvar]['altmonthheading'] = 'first'; } - // check for images - $images = $this->modx->getCollection('mxCalendarEventImages', array('event_id' => $e[$rvar]['id'], 'active'=>1) ); - $e[$rvar]['imagesTotal'] = $imgIdx = 0; - if($images){ - foreach($images AS $image){ - $imgIdx++; - $imgArr = $image->toArray(); - $imgArr['image_idx'] = $imgIdx; - $e[$rvar]['images_'.$imgIdx] = $output_images .= $this->getChunk($tpls->tplImage, $imgArr ); - } - } else { - //echo 'no images for '.$e[$rvar]['id'].'
'; + $o .= $this->getChunk($tpls->tplElMonthHeading, $e[$rvar]); + $preHead = strftime('%b', $e[$rvar]['startdate']); + } + // check for images + $images = $this->modx->getCollection('mxCalendarEventImages', + ['event_id' => $e[$rvar]['id'], 'active' => 1]); + $e[$rvar]['imagesTotal'] = $imgIdx = 0; + if ($images) { + foreach ($images AS $image) { + $imgIdx++; + $imgArr = $image->toArray(); + $imgArr['image_idx'] = $imgIdx; + $e[$rvar]['images_' . $imgIdx] = $output_images .= $this->getChunk($tpls->tplImage, + $imgArr); } - - // Add the category css properties here as well - $categoryInlineCSS = array(); + } else { + //echo 'no images for '.$e[$rvar]['id'].'
'; + } - // Get the events category css info - if(!empty($e[$rvar]['categoryid'])){ - $categories = explode(',', $e[$rvar]['categoryid']); - if(count($categories)){ - foreach($categories AS $catid){ - $catQuery = $this->modx->newQuery('mxCalendarCategories'); - $catQuery->where(array('id:IN'=>$categories)); - $catproperties = $this->modx->getCollection('mxCalendarCategories',$catQuery); - if($catproperties){ - foreach($catproperties AS $catCSS){ - $categoryInlineCSS['inlinecss'] .= $catCSS->get('inlinecss'); - $categoryInlineCSS['foregroundcss'] .= $catCSS->get('foregroundcss') !== '' ? 'color:'.$catCSS->get('foregroundcss').';' : ''; - $categoryInlineCSS['backgroundcss'] .= $catCSS->get('backgroundcss') !== '' ? 'background-color:'.$catCSS->get('backgroundcss').';' : ''; - } + // Add the category css properties here as well + $categoryInlineCSS = []; + + // Get the events category css info + if (!empty($e[$rvar]['categoryid'])) { + $categories = explode(',', $e[$rvar]['categoryid']); + if (count($categories)) { + foreach ($categories AS $catid) { + $catQuery = $this->modx->newQuery('mxCalendarCategories'); + $catQuery->where(['id:IN' => $categories]); + $catproperties = $this->modx->getCollection('mxCalendarCategories', $catQuery); + if ($catproperties) { + foreach ($catproperties AS $catCSS) { + $categoryInlineCSS['inlinecss'] .= $catCSS->get('inlinecss'); + $categoryInlineCSS['foregroundcss'] .= $catCSS->get('foregroundcss') !== '' ? 'color:' . $catCSS->get('foregroundcss') . ';' : ''; + $categoryInlineCSS['backgroundcss'] .= $catCSS->get('backgroundcss') !== '' ? 'background-color:' . $catCSS->get('backgroundcss') . ';' : ''; } } } } - - $o .= $this->getChunk($tpls->tplElItem, array_merge($e[$rvar], array('images'=>$output_images), $categoryInlineCSS)); - $i++; - $rvar++; - - } while ($rvar < count($e) && $i < $limit); - if($i >= $limit) break; + } + + $o .= $this->getChunk($tpls->tplElItem, + array_merge($e[$rvar], ['images' => $output_images], $categoryInlineCSS)); + $i++; + $rvar++; + + } while ($rvar < count($e) && $i < $limit); + if ($i >= $limit) { + break; } - } else { return $this->getChunk($tpls->tplNoEvents, array('startdate'=>$startDate,'enddate'=>$endDate)); } - return $this->getChunk($tpls->tplElWrap, array('startdate'=>$startDate,'enddate'=>$endDate,'eventList'=>$o)); + } + } else { + return $this->getChunk($tpls->tplNoEvents, ['startdate' => $startDate, 'enddate' => $endDate]); } - public function getEventCalendarDateRange($activeMonthOnlyEvents=false){ - $startDate = $_REQUEST['dt'] ? $_REQUEST['dt'] : ($this->config['dt'] ? $this->config['dt'] : strftime('%Y-%m')); - $mStartDate = strftime('%Y-%m',strtotime($startDate)) . '-01 00:00:01'; - $nextMonth = strftime('%Y-%m', strtotime('+1 month',strtotime($mStartDate))); - $prevMonth = strftime('%Y-%m', strtotime('-1 month',strtotime($mStartDate))); - $startDOW = strftime('%u', strtotime($mStartDate)); - $lastDayOfMonth = strftime('%Y-%m',strtotime($mStartDate)) . '-'.date('t',strtotime($mStartDate)) .' 23:59:59'; - $startMonthCalDate = $startDOW <= 6 ? strtotime('- '.$startDOW.' day', strtotime($mStartDate)) : strtotime($mStartDate) ; - $endMonthCalDate = strtotime('+ 6 weeks', $startMonthCalDate); - if($debug) echo 'Active Month Only: '.$mStartDate.' :: '.$lastDayOfMonth.' All displayed dates: '.strftime('%Y-%m-%d',$startMonthCalDate).' :: '.strftime('%Y-%m-%d',$endMonthCalDate).'
'; - if($activeMonthOnlyEvents) return array('start'=>strtotime($mStartDate), 'end'=>strtotime($lastDayOfMonth)); else return array('start'=>$startMonthCalDate, 'end'=>$endMonthCalDate); + + return $this->getChunk($tpls->tplElWrap, ['startdate' => $startDate, 'enddate' => $endDate, 'eventList' => $o]); + } + + public function getEventCalendarDateRange($activeMonthOnlyEvents = false) + { + $startDate = $_REQUEST['dt'] ? $_REQUEST['dt'] : ($this->config['dt'] ? $this->config['dt'] : strftime('%Y-%m')); + $mStartDate = strftime('%Y-%m', strtotime($startDate)) . '-01 00:00:01'; + $nextMonth = strftime('%Y-%m', strtotime('+1 month', strtotime($mStartDate))); + $prevMonth = strftime('%Y-%m', strtotime('-1 month', strtotime($mStartDate))); + $startDOW = strftime('%u', strtotime($mStartDate)); + $lastDayOfMonth = strftime('%Y-%m', strtotime($mStartDate)) . '-' . date('t', + strtotime($mStartDate)) . ' 23:59:59'; + $startMonthCalDate = $startDOW <= 6 ? strtotime('- ' . $startDOW . ' day', + strtotime($mStartDate)) : strtotime($mStartDate); + $endMonthCalDate = strtotime('+ 6 weeks', $startMonthCalDate); + if ($debug) { + echo 'Active Month Only: ' . $mStartDate . ' :: ' . $lastDayOfMonth . ' All displayed dates: ' . strftime('%Y-%m-%d', + $startMonthCalDate) . ' :: ' . strftime('%Y-%m-%d', $endMonthCalDate) . '
'; } - public function makeEventCalendar($events=array(),$resourceId=null,$ajaxMonthResourceId=null,$tpls=array('event'=>'month.inner.container.row.day.eventclean','day'=>'month.inner.container.row.day','week'=>'month.inner.container.row','month'=>'month.inner.container','heading'=>'month.inner.container.row.heading'), $conFilter=null, $calFilter=null, $highlightToday=true){ - $time_start = microtime(true); - - $startDate = $_REQUEST['dt'] ? $_REQUEST['dt'] : strftime('%Y-%m-%d'); - $mStartDate = strftime('%Y-%m',strtotime($startDate)) . '-01 00:00:01'; - $mCurMonth = strftime('%m', strtotime($mStartDate)); - $nextMonth = strftime('%Y-%m', strtotime('+1 month',strtotime($mStartDate))); - $prevMonth = strftime('%Y-%m', strtotime('-1 month',strtotime($mStartDate))); - $startDOW = strftime('%u', strtotime($mStartDate)); - $lastDayOfMonth = strftime('%Y-%m',strtotime($mStartDate)) . '-'.date('t',strtotime($mStartDate)) .' 23:59:59'; - $endDOW = strftime('%u', strtotime($lastDayOfMonth)); - $tpls=(object)$tpls; - $out = ''; - $startMonthCalDate = $startDOW <= 6 ? strtotime('- '.$startDOW.' day', strtotime($mStartDate)) : strtotime($mStartDate) ; - $endMonthCalDate = strtotime('+ '.(6 - $endDOW).' day', strtotime($lastDayOfMonth)); - //------// - $headingLabel = strtotime($mStartDate); - $globalParams = array('conf'=>$conFilter, 'calf'=>$calFilter); - $todayLink = $this->modx->makeUrl($ajaxMonthResourceId,'', array_merge($globalParams, array('dt' => strftime('%Y-%m'), 'cid'=>$_REQUEST['cid']))); - $prevLink = $this->modx->makeUrl($ajaxMonthResourceId,'', array_merge($globalParams, array('dt' => $prevMonth, 'cid'=>$_REQUEST['cid']))); - $nextLink = $this->modx->makeUrl($ajaxMonthResourceId,'', array_merge($globalParams, array('dt' => $nextMonth, 'cid'=>$_REQUEST['cid']))); - - $chunkEvent = $this->loadChunk($tpls->event); - $chunkDay = $this->loadChunk($tpls->day); - $chunkWeek = $this->loadChunk($tpls->week); - $chunkMonth = $this->loadChunk($tpls->month); - - $heading = ''; - $startDOW = $this->modx->getOption('mxcalendars.start_monday') ? 1 : 0; - for($i=0;$i<7;$i++){ - $numberDOW = $startDOW + $i; - if($this->debug) echo '  '.strftime('%A', strtotime("+ {$numberDOW} day", $startMonthCalDate)).'
'; - $thisDOW = trim('mxcalendars.label_dow_'.strtolower(strftime('%w', strtotime("+ {$numberDOW} day", $startMonthCalDate)))); - $heading.=$this->getChunk($tpls->heading, array('dayOfWeekId'=>$numberDOW,'dayOfWeekClass'=>'mxcdow', 'dayOfWeek'=> $this->modx->lexicon($thisDOW) )); + if ($activeMonthOnlyEvents) { + return ['start' => strtotime($mStartDate), 'end' => strtotime($lastDayOfMonth)]; + } else { + return ['start' => $startMonthCalDate, 'end' => $endMonthCalDate]; + } + } + + public function makeEventCalendar( + $events = [], + $resourceId = null, + $ajaxMonthResourceId = null, + $tpls = [ + 'event' => 'month.inner.container.row.day.eventclean', + 'day' => 'month.inner.container.row.day', + 'week' => 'month.inner.container.row', + 'month' => 'month.inner.container', + 'heading' => 'month.inner.container.row.heading' + ], + $conFilter = null, + $calFilter = null, + $highlightToday = true + ) { + $time_start = microtime(true); + + $startDate = $_REQUEST['dt'] ? $_REQUEST['dt'] : strftime('%Y-%m-%d'); + $mStartDate = strftime('%Y-%m', strtotime($startDate)) . '-01 00:00:01'; + $mCurMonth = strftime('%m', strtotime($mStartDate)); + $nextMonth = strftime('%Y-%m', strtotime('+1 month', strtotime($mStartDate))); + $prevMonth = strftime('%Y-%m', strtotime('-1 month', strtotime($mStartDate))); + $startDOW = strftime('%u', strtotime($mStartDate)); + $lastDayOfMonth = strftime('%Y-%m', strtotime($mStartDate)) . '-' . date('t', + strtotime($mStartDate)) . ' 23:59:59'; + $endDOW = strftime('%u', strtotime($lastDayOfMonth)); + $tpls = (object)$tpls; + $out = ''; + $startMonthCalDate = $startDOW <= 6 ? strtotime('- ' . $startDOW . ' day', + strtotime($mStartDate)) : strtotime($mStartDate); + $endMonthCalDate = strtotime('+ ' . (6 - $endDOW) . ' day', strtotime($lastDayOfMonth)); + //------// + $headingLabel = strtotime($mStartDate); + $globalParams = ['conf' => $conFilter, 'calf' => $calFilter]; + $todayLink = $this->modx->makeUrl($ajaxMonthResourceId, '', + array_merge($globalParams, ['dt' => strftime('%Y-%m'), 'cid' => $_REQUEST['cid']])); + $prevLink = $this->modx->makeUrl($ajaxMonthResourceId, '', + array_merge($globalParams, ['dt' => $prevMonth, 'cid' => $_REQUEST['cid']])); + $nextLink = $this->modx->makeUrl($ajaxMonthResourceId, '', + array_merge($globalParams, ['dt' => $nextMonth, 'cid' => $_REQUEST['cid']])); + + $chunkEvent = $this->loadChunk($tpls->event); + $chunkDay = $this->loadChunk($tpls->day); + $chunkWeek = $this->loadChunk($tpls->week); + $chunkMonth = $this->loadChunk($tpls->month); + + $heading = ''; + $startDOW = $this->modx->getOption('mxcalendars.start_monday') ? 1 : 0; + for ($i = 0; $i < 7; $i++) { + $numberDOW = $startDOW + $i; + if ($this->debug) { + echo '  ' . strftime('%A', strtotime("+ {$numberDOW} day", $startMonthCalDate)) . '
'; } - //-- Set additional day placeholders for week - $phHeading = array( - 'weekId'=>'' - ,'weekClass'=>'' - ,'days'=>$heading - ); - //$weeks.=$chunkWeek->process($phWeek); - $heading=$this->getChunk($tpls->week, $phHeading); + $thisDOW = trim('mxcalendars.label_dow_' . strtolower(strftime('%w', + strtotime("+ {$numberDOW} day", $startMonthCalDate)))); + $heading .= $this->getChunk($tpls->heading, [ + 'dayOfWeekId' => $numberDOW, + 'dayOfWeekClass' => 'mxcdow', + 'dayOfWeek' => $this->modx->lexicon($thisDOW) + ]); + } + //-- Set additional day placeholders for week + $phHeading = [ + 'weekId' => '' + , + 'weekClass' => '' + , + 'days' => $heading + ]; + //$weeks.=$chunkWeek->process($phWeek); + $heading = $this->getChunk($tpls->week, $phHeading); - $weeks = ''; - //-- Start the Date loop - $var=0; + $weeks = ''; + //-- Start the Date loop + $var = 0; + do { + if ($this->debug) { + echo '---------------
'; + } + if ($this->debug) { + echo 'Week ' . ($var + 1) . '
'; + } + if ($this->debug) { + echo '---------------
'; + } + // Week Start date + $iWeek = strtotime('+ ' . $var . ' week', $startMonthCalDate); + $i = 0; + $days = ''; do { - if($this->debug) echo '---------------
'; - if($this->debug) echo 'Week '.($var + 1).'
'; - if($this->debug) echo '---------------
'; - // Week Start date - $iWeek = strtotime('+ '.$var.' week', $startMonthCalDate); - $i = 0; - $days = ''; - do{ - $diw = $startDOW + $i; - // Get the week's days - $iDay = strtotime('+ '.$diw.' day', $iWeek); - $thisMonth = strftime('%m', $iDay); - if($this->debug) echo strftime('%a %b %d', $iDay).'
'; - $eventList = ''; - if(isset($events[strftime('%Y-%m-%d', $iDay)]) && count($events[strftime('%Y-%m-%d', $iDay)])){ - //-- Echo each event item - $e = $events[strftime('%Y-%m-%d', $iDay)]; - - foreach($e AS $el){ - if($this->debug) echo '  ++  '.$el['title'].'
'; - //$eventList.=$chunkEvent->process($el); - //@TODO -- FIX: Add check for display of current month - - $categoryInlineCSS = array(); - - // Get the events category css info - // Cost CPU: .5seconds for 89 events - - if(!empty($el['categoryid'])){ - $categories = explode(',', $el['categoryid']); - if(count($categories)){ - foreach($categories AS $catid){ - - $catQuery = $this->modx->newQuery('mxCalendarCategories'); - $catQuery->where(array('id:IN'=>$categories)); - $catproperties = $this->modx->getCollection('mxCalendarCategories',$catQuery); - if($catproperties){ - foreach($catproperties AS $catCSS){ - $categoryInlineCSS['inlinecss'] .= $catCSS->get('inlinecss'); - $categoryInlineCSS['foregroundcss'] .= $catCSS->get('foregroundcss') !== '' ? 'color:'.$catCSS->get('foregroundcss').';' : ''; - $categoryInlineCSS['backgroundcss'] .= $catCSS->get('backgroundcss') !== '' ? 'background-color:'.$catCSS->get('backgroundcss').';' : ''; - } + $diw = $startDOW + $i; + // Get the week's days + $iDay = strtotime('+ ' . $diw . ' day', $iWeek); + $thisMonth = strftime('%m', $iDay); + if ($this->debug) { + echo strftime('%a %b %d', $iDay) . '
'; + } + $eventList = ''; + if (isset($events[strftime('%Y-%m-%d', $iDay)]) && count($events[strftime('%Y-%m-%d', $iDay)])) { + //-- Echo each event item + $e = $events[strftime('%Y-%m-%d', $iDay)]; + + foreach ($e AS $el) { + if ($this->debug) { + echo '  ++  ' . $el['title'] . '
'; + } + //$eventList.=$chunkEvent->process($el); + //@TODO -- FIX: Add check for display of current month + + $categoryInlineCSS = []; + + // Get the events category css info + // Cost CPU: .5seconds for 89 events + + if (!empty($el['categoryid'])) { + $categories = explode(',', $el['categoryid']); + if (count($categories)) { + foreach ($categories AS $catid) { + + $catQuery = $this->modx->newQuery('mxCalendarCategories'); + $catQuery->where(['id:IN' => $categories]); + $catproperties = $this->modx->getCollection('mxCalendarCategories', $catQuery); + if ($catproperties) { + foreach ($catproperties AS $catCSS) { + $categoryInlineCSS['inlinecss'] .= $catCSS->get('inlinecss'); + $categoryInlineCSS['foregroundcss'] .= $catCSS->get('foregroundcss') !== '' ? 'color:' . $catCSS->get('foregroundcss') . ';' : ''; + $categoryInlineCSS['backgroundcss'] .= $catCSS->get('backgroundcss') !== '' ? 'background-color:' . $catCSS->get('backgroundcss') . ';' : ''; } - } + } } - - // Check for images - $images = $this->modx->getCollection('mxCalendarEventImages', array('event_id' => $el['id'], 'active'=>1) ); - $el['imagesTotal'] = $imgIdx = 0; - if($images){ - foreach($images AS $image){ - $imgIdx++; - $imgArr = $image->toArray(); - $imgArr['image_idx'] = $imgIdx; - $el['images_'.$imgIdx] = $output_images .= $this->getChunk($tpls->tplImage, $imgArr ); - } - $el['images'] = $output_images; - $el['imagesTotal'] = $imgIdx; - } - - $el['startdate'] = strftime('%l:%M %p', $el['startdate']); - $el['startdateraw'] = $el['startdate']; //-- Add for full control via output modifier - - - /** - * @todo Remove this once final performance testing is completed - */ - /* - $event_html = '
- '.$el['startdate'].' - - Images: '.$imgIdx.' - '.$el['title'].' -
'; - */ - $eventList.= $this->getChunk($tpls->event, array_merge($el,$categoryInlineCSS)); - } - } else { if($this->debug) echo '  --  '.strftime('%m-%d', $iDay).'
'; } - - //-- Set additional day placeholders for day - $isToday = (strftime('%m-%d') == strftime('%m-%d', $iDay) && $highlightToday==true ? 'today ' : ''); - $dayMonthName = strftime('%b',$iDay); - $dayMonthDay = strftime('%d',$iDay); - $dayMonthDay = (strftime('%d',$iDay) == 1 ? strftime('%b ',$iDay).( substr($dayMonthDay,0,1) == '0' ? ' '.substr($dayMonthDay,1) : $dayMonthDay ) : ( substr($dayMonthDay,0,1) == '0' ? ' '.substr($dayMonthDay,1) : $dayMonthDay )); - $phDay = array( - //'dayOfMonth'=> str_replace('0', ' ', (strftime('%d',$iDay) == 1 ? strftime('%b %d',$iDay) : strftime('%d',$iDay))) - 'dayOfMonth' => $dayMonthDay - ,'dayOfMonthID'=>'dom-'.strftime('%A%d',$iDay) - ,'events'=>$eventList - ,'fulldate'=>strftime('%m/%d/%Y', $iDay) - ,'tomorrow'=>strftime('%m/%d/%Y', strtotime('+1 day', $iDay )) - ,'yesterday'=>strftime('%m/%d/%Y', strtotime('-1 day', $iDay )) - ,'class'=> $isToday.(array_key_exists(strftime('%Y-%m-%d', $iDay),$events) ? 'hasEvents' : 'noEvents').($mCurMonth == $thisMonth ? '' : ' ncm') - ); - //$days.=$chunkDay->process($phDay); - $days.=$this->getChunk($tpls->day, $phDay); - } while (++$i < 7); - - if($this->debug) echo '
'; - //-- Set additional day placeholders for week - $phWeek = array( - 'weekId'=>'mxcWeek'.$var - ,'weekClass'=>strftime('%A%d',$iDay) - ,'days'=>$days - ); - //$weeks.=$chunkWeek->process($phWeek); - $weeks.=$this->getChunk($tpls->week, $phWeek); - - } while (++$var < 6); //Only advance 5 weeks giving total of 6 weeks - - // - $time_end = microtime(true); - $time = $time_end - $time_start; - //echo '

mxCalendar=>makeEventCalendar() processed in '.$time.'

'; - - //-- Set additional day placeholders for month - $phMonth = array( - 'containerID'=>strftime('%a',$iDay) - ,'containerClass'=>strftime('%a%Y',$iDay) - ,'weeks'=>$heading.$weeks - ,'headingLabel'=>$headingLabel - ,'todayLink'=>$todayLink - ,'todayLabel'=> $this->modx->lexicon('mxcalendars.label_today') - ,'prevLink'=>$prevLink - ,'nextLink'=>$nextLink - ); - //return $chunkMonth->process($phMonth); - return $this->getChunk($tpls->month, $phMonth); - } - - public function makeCategoryList($labelCategory=null,$filteredCategoryId=null,$resourceId=null,$tpls=array()){ - $output = ''; - $tpls = (object)$tpls; - // build category query - $c = $this->modx->newQuery('mxCalendarCategories'); - $c->where(array( - //'name:LIKE' => '%'.$query.'%', - 'disable' => 0, - 'active' => 1, - )); - $c->sortby('name','ASC'); - $mxcalendarsCats = $this->modx->getCollection('mxCalendarCategories', $c); - // iterate - // $list = array(); - // $output .= ''; + //-- Set additional day placeholders for week + $phWeek = [ + 'weekId' => 'mxcWeek' . $var + , + 'weekClass' => strftime('%A%d', $iDay) + , + 'days' => $days + ]; + //$weeks.=$chunkWeek->process($phWeek); + $weeks .= $this->getChunk($tpls->week, $phWeek); + + } while (++$var < 6); //Only advance 5 weeks giving total of 6 weeks + + // + $time_end = microtime(true); + $time = $time_end - $time_start; + //echo '

mxCalendar=>makeEventCalendar() processed in '.$time.'

'; + + //-- Set additional day placeholders for month + $phMonth = [ + 'containerID' => strftime('%a', $iDay) + , + 'containerClass' => strftime('%a%Y', $iDay) + , + 'weeks' => $heading . $weeks + , + 'headingLabel' => $headingLabel + , + 'todayLink' => $todayLink + , + 'todayLabel' => $this->modx->lexicon('mxcalendars.label_today') + , + 'prevLink' => $prevLink + , + 'nextLink' => $nextLink + ]; + + //return $chunkMonth->process($phMonth); + return $this->getChunk($tpls->month, $phMonth); + } + + public function makeCategoryList($labelCategory = null, $filteredCategoryId = null, $resourceId = null, $tpls = []) + { + $output = ''; + $tpls = (object)$tpls; + // build category query + $c = $this->modx->newQuery('mxCalendarCategories'); + $c->where([ + //'name:LIKE' => '%'.$query.'%', + 'disable' => 0, + 'active' => 1, + ]); + $c->sortby('name', 'ASC'); + $mxcalendarsCats = $this->modx->getCollection('mxCalendarCategories', $c); + // iterate + // $list = array(); + // $output .= ''; + } + + public function processFeeds($setFeedTZ = null) + { + + require_once dirname(__FILE__) . '/mxcalendars.ics.class.php'; + + $f = $this->modx->newQuery('mxCalendarFeed'); + $f->where(['active:=' => 1, 'nextrunon:<=' => time()]); + $f->prepare(); + + $mxcfeeds = $this->modx->getCollection('mxCalendarFeed', $f); + + if ($this->loggingEnabled) { + $this->logEvent('feed', 'feeds processor called\n\nSQL:\n' . $f->toSql()); + } + + if (!empty($setFeedTZ) && is_array(json_decode($setFeedTZ, true))) { + $feedTzSettings = json_decode($setFeedTZ, true); + } else { + $feedTzSettings = null; + } + + //$this->modx->setLogLevel(modX::LOG_LEVEL_INFO); + foreach ($mxcfeeds AS $feed) { + $hadmodifications = 0; + if ($feed->get('type') === 'ical') { + + $activeUrl = $feed->get('feed'); + + $currentTZ = date_default_timezone_get(); + + if (!empty($feedTzSettings) && array_key_exists($feed->get('id'), $feedTzSettings)) { + //echo '

CURRENT TIMEZONE: '.date_default_timezone_get().'


'; + date_default_timezone_set($feedTzSettings[$feed->get('id')]); + //echo '

NEW TIMEZONE: '.date_default_timezone_get().'


'; + } + + $config = [ + 'unique_id' => 'mxcfeed-' . $feed->get('id') . '-' . time(), + 'url' => $activeUrl, + ]; + $vcalendar = new vcalendar($config); + $vcalendar->parse(); + + + //echo '
'.print_r($vcalendar,true).'
'; + //echo '

=========================================================

'; + + $myics = ''; + if ($this->loggingEnabled) { + $this->logEvent('feed parse', + 'Parsing feed #' . $feed->get('id') . ' events. [' . $feed->get('feed') . ']\n\nResponse:\n' . $myics); + } + + + while ($vevent = $vcalendar->getComponent('vevent')) { + + //if (!empty($feedTzSettings) && array_key_exists($feed->get('id'), $feedTzSettings)) { //echo '

CURRENT TIMEZONE: '.date_default_timezone_get().'


'; - date_default_timezone_set($feedTzSettings[$feed->get('id')]); + //date_default_timezone_set($feedTzSettings[$feed->get('id')]); //echo '

NEW TIMEZONE: '.date_default_timezone_get().'


'; + //} + + if ($vevent->dtstart['value']) { + $start = strtotime( + implode('-', [ + $vevent->dtstart['value']['year'], + $vevent->dtstart['value']['month'], + $vevent->dtstart['value']['day'] + ]) + . 'T' . + implode(':', [ + $vevent->dtstart['value']['hour'], + $vevent->dtstart['value']['min'], + $vevent->dtstart['value']['sec'] + ]) + . $vevent->dtstart['value']['tz'] + ); + // 2013-03-18T11:19:28-04:00 $this->getFormatedDate(null,,true); + + } else { + $start = ''; } - - $config = array( "unique_id" => 'mxcfeed-'.$feed->get('id').'-'.time(), - "url" => $activeUrl, - ); - $vcalendar = new vcalendar( $config ); - $vcalendar->parse(); - - - //echo '
'.print_r($vcalendar,true).'
'; - //echo '

=========================================================

'; - - - if($this->loggingEnabled) $this->logEvent('feed parse','Parsing feed #'.$feed->get('id').' events. ['.$feed->get('feed').']\n\nResponse:\n'.$myics); - - - while( $vevent = $vcalendar->getComponent( "vevent" )) { - - if(!empty($feedTzSettings) && array_key_exists($feed->get('id'), $feedTzSettings)){ - //echo '

CURRENT TIMEZONE: '.date_default_timezone_get().'


'; - //date_default_timezone_set($feedTzSettings[$feed->get('id')]); - //echo '

NEW TIMEZONE: '.date_default_timezone_get().'


'; - } - - if($vevent->dtstart['value']){ - $start = strtotime( - implode('-',array($vevent->dtstart['value']['year'],$vevent->dtstart['value']['month'],$vevent->dtstart['value']['day'])) - .'T'. - implode(':',array($vevent->dtstart['value']['hour'],$vevent->dtstart['value']['min'],$vevent->dtstart['value']['sec'])) - . $vevent->dtstart['value']['tz'] - );// 2013-03-18T11:19:28-04:00 $this->getFormatedDate(null,,true); - - } else { $start=''; } - - if($vevent->dtend['value']){ - $end =strtotime( - implode('-',array($vevent->dtend['value']['year'],$vevent->dtend['value']['month'],$vevent->dtend['value']['day'])) - .'T'. - implode(':',array($vevent->dtend['value']['hour'],$vevent->dtend['value']['min'],$vevent->dtend['value']['sec'])) - . $vevent->dtend['value']['tz'] - ); - } else { $end = ''; } - - if($vevent->lastmodified['value']){ - $lastchange = mktime( - $vevent->lastmodified['value']['hour'], - $vevent->lastmodified['value']['min'], - $vevent->lastmodified['value']['sec'], - $vevent->lastmodified['value']['month'], - $vevent->lastmodified['value']['day'], - $vevent->lastmodified['value']['year'] - ,0 - ); - } else {$lastchange = ''; } - - if($vevent->created['value']){ - $createdDate = mktime( - $vevent->created['value']['hour'], - $vevent->created['value']['min'], - $vevent->created['value']['sec'], - $vevent->created['value']['month'], - $vevent->created['value']['day'], - $vevent->created['value']['year'] - ,0 - ); - } else { $createdDate = ''; } - - $description = str_replace(array("\r\n", "\n", "\r","\\r\\n","\\n","\\r"), '
', $vevent->getProperty( "description" )); // one occurrence - $location = $vevent->getProperty( "location" ); - $title = $vevent->getProperty( "summary" ); - $feedEventUID = $vevent->getProperty("uid"); - - //-- Multiple Occurances - //while( $comment = $vevent->getProperty( "comment" )) { // MAY occur more than once - // echo json_encode($comment).'


'; - //} - // Output for testing - $event = array( - 'title'=>$title, - 'description'=>(!empty($description) ? $description : ''), - 'location_name'=>$location, - 'startdate'=>$start, - 'enddate'=>$end, - 'source'=>'feed', - 'lastedit'=>$lastchange, - 'feeds_id'=>$feed->get('id'), - 'feeds_uid'=>$feedEventUID, - 'context'=>'', - //'categoryid'=>$feed->get('defaultcategoryid'), - 'createdon'=>$createDate, - 'repeattype'=>0, - 'repeaton'=>'', - 'repeatfrequency'=>0 - ); - //echo 'Title: '.$title.'
'.json_encode($event).'



'; - - //-- Save the new event - if(!empty($feedEventUID)){ - $existingEvent = $this->modx->getObject('mxCalendarEvents',array('feeds_uid' => $feedEventUID)); - //if(!is_object($existingEvent)){ - // $existingEvent = $this->modx->getObject('mxCalendarEvents',array('title' => $title)); - //} - } //else { - // Disable the TITLE as a valid itdentifier for duplicated events as it breaks the repeating events - // $existingEvent = $this->modx->getObject('mxCalendarEvents',array('title' => $title)); + if ($vevent->dtend['value']) { + $end = strtotime( + implode('-', [ + $vevent->dtend['value']['year'], + $vevent->dtend['value']['month'], + $vevent->dtend['value']['day'] + ]) + . 'T' . + implode(':', [ + $vevent->dtend['value']['hour'], + $vevent->dtend['value']['min'], + $vevent->dtend['value']['sec'] + ]) + . $vevent->dtend['value']['tz'] + ); + } else { + $end = ''; + } + + if ($vevent->lastmodified['value']) { + $lastchange = mktime( + $vevent->lastmodified['value']['hour'], + $vevent->lastmodified['value']['min'], + $vevent->lastmodified['value']['sec'], + $vevent->lastmodified['value']['month'], + $vevent->lastmodified['value']['day'], + $vevent->lastmodified['value']['year'] + , 0 + ); + } else { + $lastchange = ''; + } + + if ($vevent->created['value']) { + $createdDate = mktime( + $vevent->created['value']['hour'], + $vevent->created['value']['min'], + $vevent->created['value']['sec'], + $vevent->created['value']['month'], + $vevent->created['value']['day'], + $vevent->created['value']['year'] + , 0 + ); + } else { + $createdDate = ''; + } + + $description = str_replace( + ['\r\n', '\n', '\r', '\\r\\n', '\\n', '\\r'], + '
', + $vevent->getProperty('description') + ); // one occurrence + $location = $vevent->getProperty('location'); + $title = $vevent->getProperty('summary'); + $feedEventUID = $vevent->getProperty('uid'); + + //-- Multiple Occurances + //while( $comment = $vevent->getProperty( "comment" )) { // MAY occur more than once + // echo json_encode($comment).'


'; + //} + + // Output for testing + $event = [ + 'title' => $title, + 'description' => (!empty($description) ? $description : ''), + 'location_name' => $location, + 'startdate' => $start, + 'enddate' => $end, + 'source' => 'feed', + 'lastedit' => $lastchange, + 'feeds_id' => $feed->get('id'), + 'feeds_uid' => $feedEventUID, + 'context' => '', + //'categoryid'=>$feed->get('defaultcategoryid'), + 'createdon' => $createDate, + 'repeattype' => 0, + 'repeaton' => '', + 'repeatfrequency' => 0 + ]; + //echo 'Title: '.$title.'
'.json_encode($event).'



'; + + //-- Save the new event + $existingEvent = ''; + if (!empty($feedEventUID)) { + $existingEvent = $this->modx->getObject('mxCalendarEvents', ['feeds_uid' => $feedEventUID]); + //if(!is_object($existingEvent)){ + // $existingEvent = $this->modx->getObject('mxCalendarEvents',array('title' => $title)); //} - if(is_object($existingEvent)){ - // Check and modify existing event if modified since last update - if($existingEvent->get('lastedit') <= $lastchange && $existingEvent->get('source') === 'feed'){ - // Event has been updated so lets just update all properties - $existingEvent->fromArray($event); - $existingEvent->save(); - if($this->loggingEnabled){ - $this->logEvent('feed','Update Event ('.$existingEvent->get('id').') for feed #'.$feed->get('id').'\n\nEvent JSON:\n'.json_encode($event)); - } - $hadmodifications++; - } - } else { - // Create the newly found event from the feed - $feedEvent = $this->modx->newObject('mxCalendarEvents'); - - $event['categoryid']=$feed->get('defaultcategoryid'); - - $feedEvent->fromArray($event); - $feedEvent->save(); - if($this->loggingEnabled){ - $this->logEvent('feed','New Event ('.$feedEvent->get('id').') for feed #'.$feed->get('id').'\n\nEvent JSON:\n'.json_encode($event)); + } //else { + // Disable the TITLE as a valid itdentifier for duplicated events as it breaks the repeating events + // $existingEvent = $this->modx->getObject('mxCalendarEvents',array('title' => $title)); + //} + if (is_object($existingEvent)) { + // Check and modify existing event if modified since last update + if ($existingEvent->get('lastedit') <= $lastchange && $existingEvent->get('source') === 'feed') { + // Event has been updated so lets just update all properties + $existingEvent->fromArray($event); + $existingEvent->save(); + if ($this->loggingEnabled) { + $this->logEvent('feed', + 'Update Event (' . $existingEvent->get('id') . ') for feed #' . $feed->get('id') . '\n\nEvent JSON:\n' . json_encode($event)); } $hadmodifications++; } - - - } - - // Set back current TIME ZONE - date_default_timezone_set($currentTZ); - - //-- Update the feed next run time - $nextTime = strtotime('+'.$feed->get('timerint').' '.$feed->get('timermeasurement')); - $feed->set('lastrunon',time()); - $feed->set('nextrunon',$nextTime); - $feed->save(); - - if($hadmodifications){ - $this->logEvent('feed','Parsing feed #'.$feed->get('id').' had '.$hadmodifications.' event'.($hadmodifications > 1 ? 's' : '').' added/updated ['.$feed->get('feed').']'); } else { - $this->logEvent('feed','Parsing feed #'.$feed->get('id').' had no changes. ['.$feed->get('feed').']'); + // Create the newly found event from the feed + $event['categoryid'] = $feed->get('defaultcategoryid'); + $feedEvent = $this->modx->newObject('mxCalendarEvents', $event); + $feedEvent->save(); + if ($this->loggingEnabled) { + $this->logEvent('feed', + 'New Event (' . $feedEvent->get('id') . ') for feed #' . $feed->get('id') . '\n\nEvent JSON:\n' . json_encode($event)); + } + $hadmodifications++; } - + + + } + + // Set back current TIME ZONE + date_default_timezone_set($currentTZ); + + //-- Update the feed next run time + $nextTime = strtotime('+' . $feed->get('timerint') . ' ' . $feed->get('timermeasurement')); + $feed->set('lastrunon', time()); + $feed->set('nextrunon', $nextTime); + $feed->save(); + + if ($hadmodifications) { + $this->logEvent('feed', + 'Parsing feed #' . $feed->get('id') . ' had ' . $hadmodifications . ' event' . ($hadmodifications > 1 ? 's' : '') . ' added/updated [' . $feed->get('feed') . ']'); } else { - //-- ==================== --// - //-- Process the XML feed --// - //-- ==================== --// - $activeUrl = $feed->get('feed'); - $xmlEvents = file_get_contents($activeUrl); + $this->logEvent('feed', + 'Parsing feed #' . $feed->get('id') . ' had no changes. [' . $feed->get('feed') . ']'); + } + + } else { + //-- ==================== --// + //-- Process the XML feed --// + //-- ==================== --// + $activeUrl = $feed->get('feed'); + $xmlEvents = file_get_contents($activeUrl); + if (!empty($xmlEvents)) { $events = new SimpleXMLElement($xmlEvents); $idx = 0; foreach ($events->event as $event) { - if(strtolower($event->timebegin) !== 'all day'){ - $startDateTime = strtotime($event->date.' '.$event->timebegin); - $endDateTime = strtotime($event->date.' '.str_replace('- ', '', $event->timeend)); + if (strtolower($event->timebegin) !== 'all day') { + $startDateTime = strtotime($event->date . ' ' . $event->timebegin); + $endDateTime = strtotime($event->date . ' ' . str_replace('- ', '', $event->timeend)); } else { - $startDateTime = strtotime($event->date.' 00:00:00'); - $endDateTime = strtotime($event->date.' 23:59:59'); + $startDateTime = strtotime($event->date . ' 00:00:00'); + $endDateTime = strtotime($event->date . ' 23:59:59'); } $lastchange = (!empty($event->lastedit) ? $event->lastedit : time()); // Output for testing - $eventdata = array( - 'title'=>$event->title, - 'description'=>(!empty($event->description) ? $event->description : ''), - 'location_name'=>(!empty($event->location) ? $event->location : ''), - 'startdate'=>$startDateTime, - 'enddate'=>$endDateTime, - 'source'=>'feed', - 'lastedit'=>$lastchange, - 'feeds_id'=>$feed->get('id'), - 'feeds_uid'=> (!empty($event->eventid) ? $event->eventid : ''), - 'context'=>'', - 'categoryid'=>$feed->get('defaultcategoryid'), - 'createdon'=>(!empty($event->createDate) ? $event->createDate : time()), - 'repeattype'=>0, - 'repeaton'=>'', - 'repeatfrequency'=>0 - ); + $eventdata = [ + 'title' => $event->title, + 'description' => (!empty($event->description) ? $event->description : ''), + 'location_name' => (!empty($event->location) ? $event->location : ''), + 'startdate' => $startDateTime, + 'enddate' => $endDateTime, + 'source' => 'feed', + 'lastedit' => $lastchange, + 'feeds_id' => $feed->get('id'), + 'feeds_uid' => (!empty($event->eventid) ? $event->eventid : ''), + 'context' => '', + 'categoryid' => $feed->get('defaultcategoryid'), + 'createdon' => (!empty($event->createDate) ? $event->createDate : time()), + 'repeattype' => 0, + 'repeaton' => '', + 'repeatfrequency' => 0 + ]; //-- Save the new event - if(!empty($event->eventid) && isset($event->eventid) ){ - $q = $this->modx->newQuery('mxCalendarEvents'); - $title = (string)$event->title; - $feeduid = (string)$event->eventid; - $q->where(array( - 'mxCalendarEvents.title' => $title, - 'mxCalendarEvents.feeds_id' => $feed->get('id'), - 'mxCalendarEvents.feeds_uid' => $feeduid - )); - $q->prepare(); - //echo 'SQL ['.$event->title.' '.$event->eventid.']:
'.$q->toSQL().'

'; - $existingEvent = $this->modx->getObject('mxCalendarEvents',$q); + if (!empty($event->eventid) && isset($event->eventid)) { + $q = $this->modx->newQuery('mxCalendarEvents'); + $title = (string)$event->title; + $feeduid = (string)$event->eventid; + $q->where([ + 'mxCalendarEvents.title' => $title, + 'mxCalendarEvents.feeds_id' => $feed->get('id'), + 'mxCalendarEvents.feeds_uid' => $feeduid + ]); + $q->prepare(); + //echo 'SQL ['.$event->title.' '.$event->eventid.']:
'.$q->toSQL().'

'; + $existingEvent = $this->modx->getObject('mxCalendarEvents', $q); //$existingEvent = $this->modx->getObject('mxCalendarEvents',array()); } else { $existingEvent = false; } - if(is_object($existingEvent)){ + if (is_object($existingEvent)) { // Check and modify existing event if modified since last update - if($existingEvent->get('lastedit') <= $lastchange){ + if ($existingEvent->get('lastedit') <= $lastchange) { // Event has been updated so lets just update all properties $existingEvent->fromArray($eventdata); $existingEvent->save(); - if($this->loggingEnabled){ - $this->logEvent('feed','Update Event ('.$existingEvent->get('id').')['.$event->eventid.'] for feed #'.$feed->get('id').'\n\nEvent JSON:\n'.json_encode($event)); + if ($this->loggingEnabled) { + $this->logEvent('feed', + 'Update Event (' . $existingEvent->get('id') . ')[' . $event->eventid . '] for feed #' . $feed->get('id') . '\n\nEvent JSON:\n' . json_encode($event)); } $hadmodifications++; } } else { // Create the newly found event from the feed - $feedEvent = $this->modx->newObject('mxCalendarEvents'); - $feedEvent->fromArray($eventdata); + $feedEvent = $this->modx->newObject('mxCalendarEvents', $eventdata); + //$feedEvent->fromArray($eventdata); $feedEvent->save(); - if($this->loggingEnabled){ - $this->logEvent('feed','New Event ('.$feedEvent->get('id').') for feed #'.$feed->get('id').'\n\nEvent JSON:\n'.json_encode($event)); + if ($this->loggingEnabled) { + $this->logEvent('feed', + 'New Event (' . $feedEvent->get('id') . ') for feed #' . $feed->get('id') . '\n\nEvent JSON:\n' . json_encode($event)); } $hadmodifications++; } @@ -890,72 +1089,91 @@ public function processFeeds($setFeedTZ=null){ $idx++; } //-- Update the feed next run time - $nextTime = strtotime('+'.$feed->get('timerint').' '.$feed->get('timermeasurement')); - $feed->set('lastrunon',time()); - $feed->set('nextrunon',$nextTime); + $nextTime = strtotime('+' . $feed->get('timerint') . ' ' . $feed->get('timermeasurement')); + $feed->set('lastrunon', time()); + $feed->set('nextrunon', $nextTime); $feed->save(); - if($hadmodifications){ - $this->logEvent('feed','Parsing feed #'.$feed->get('id').' had '.$hadmodifications.' event'.($hadmodifications > 1 ? 's' : '').' added/updated ['.$feed->get('feed').']'); + if ($hadmodifications) { + $this->logEvent('feed', + 'Parsing feed #' . $feed->get('id') . ' had ' . $hadmodifications . ' event' . ($hadmodifications > 1 ? 's' : '') . ' added/updated [' . $feed->get('feed') . ']'); } else { - $this->logEvent('feed','Parsing feed #'.$feed->get('id').' had no changes. ['.$feed->get('feed').']'); + $this->logEvent('feed', + 'Parsing feed #' . $feed->get('id') . ' had no changes. [' . $feed->get('feed') . ']'); } - } + } - - - } - - public function logEvent($itemType='',$log=''){ - $mxclog = $this->modx->newObject('mxCalendarLog',array( - 'itemtype' => $itemType, - 'log' => $log, - 'datetime' => time(), - )); - $mxclog->save(); } + + + } + + public function logEvent($itemType = '', $log = '') + { + $mxclog = $this->modx->newObject('mxCalendarLog', [ + 'itemtype' => $itemType, + 'log' => $log, + 'datetime' => time(), + ]); + $mxclog->save(); + } } /** * Class to help with tracking processing times - * + * */ -class makeProcessTime { +class makeProcessTime +{ public $globalStartProcess, $startProcess, $endProcess, $debug; - public function __construct($gsProc=null,$debug){ + + public function __construct($debug, $gsProc = null) + { $this->debug = !empty($debug) ? $debug : 0; $now = microtime(true); - if(!empty($gsProc)){ - self::set('globalStartProcess',$gsProc); + if (!empty($gsProc)) { + $this->set('globalStartProcess', $gsProc); } - self::set('startProcess',$now); - + $this->set('startProcess', $now); + } - public function set($property='',$val=null){ - if(!empty($property)){ + + public function set($property = '', $val = null) + { + if (!empty($property)) { $this->{$property} = $val; } } - public function get($property=''){ - if(!empty($property)){ + + public function get($property = '') + { + if (!empty($property)) { return $this->{$property}; } + return false; } - public function getTime(){ + + public function getTime() + { return $this->endProcess - $this->startProcess; } - public function end($echoMessage=''){ - self::set('endProcess',microtime(true)); - if(!empty($echoMessage) && $this->debug){ - if(!empty($this->globalStartProcess)) - echo $echoMessage.' started @'.($this->startProcess - $this->globalStartProcess).' and ended @'.($this->endProcess - $this->globalStartProcess).' for total processing time of '.self::getTime().' seconds
'; - else - echo $echoMessage.' had a total processing time of '.self::getTime().' seconds
'; - } else { - return self::getTime(); + + public function end($echoMessage = ''): string + { + $this->set('endProcess', microtime(true)); + if (!empty($echoMessage) && $this->debug) { + if (!empty($this->globalStartProcess)) { + echo $echoMessage . ' started @' . ($this->startProcess - $this->globalStartProcess) . ' and ended @' . ($this->endProcess - $this->globalStartProcess) . ' for total processing time of ' . $this->getTime() . ' seconds
'; + } else { + echo $echoMessage . ' had a total processing time of ' . $this->getTime() . ' seconds
'; + } + + return''; } + + return $this->getTime(); } } diff --git a/core/components/mxcalendars/model/mxcalendars/mysql/mxcalendarevents.map.inc.php b/core/components/mxcalendars/model/mxcalendars/mysql/mxcalendarevents.map.inc.php index 44e34af..8681175 100644 --- a/core/components/mxcalendars/model/mxcalendars/mysql/mxcalendarevents.map.inc.php +++ b/core/components/mxcalendars/model/mxcalendars/mysql/mxcalendarevents.map.inc.php @@ -1,335 +1,369 @@ 'mxcalendars', - 'version' => NULL, - 'table' => 'mxcalendars_events', - 'extends' => 'xPDOSimpleObject', - 'fields' => - array ( - 'title' => '', - 'description' => '', - 'content' => '', - 'categoryid' => NULL, - 'link' => '', - 'linkrel' => '', - 'linktarget' => '', - 'location_name' => '', - 'location_address' => '', - 'map' => 0, - 'allday' => 0, - 'startdate' => NULL, - 'enddate' => NULL, - 'repeating' => 0, - 'repeattype' => NULL, - 'repeaton' => NULL, - 'repeatfrequency' => NULL, - 'repeatenddate' => NULL, - 'repeatdates' => NULL, - 'source' => 'local', - 'feeds_id' => 0, - 'feeds_uid' => '', - 'lastedit' => NULL, - 'context' => '', - 'calendar_id' => 0, - 'form_chunk' => '', - 'createdon' => NULL, - 'createdby' => 0, - 'editedon' => NULL, - 'editedby' => 0, - 'active' => 1, - ), - 'fieldMeta' => - array ( - 'title' => - array ( - 'dbtype' => 'varchar', - 'precision' => '255', - 'phptype' => 'string', - 'null' => false, - 'default' => '', - ), - 'description' => - array ( - 'dbtype' => 'text', - 'phptype' => 'string', - 'null' => false, - 'default' => '', - ), - 'content' => - array ( - 'dbtype' => 'text', - 'phptype' => 'string', - 'null' => false, - 'default' => '', - ), - 'categoryid' => - array ( - 'dbtype' => 'varchar', - 'precision' => '10', - 'phptype' => 'string', - 'null' => true, - ), - 'link' => - array ( - 'dbtype' => 'varchar', - 'precision' => '255', - 'phptype' => 'string', - 'null' => false, - 'default' => '', - ), - 'linkrel' => - array ( - 'dbtype' => 'varchar', - 'precision' => '255', - 'phptype' => 'string', - 'null' => false, - 'default' => '', - ), - 'linktarget' => - array ( - 'dbtype' => 'varchar', - 'precision' => '255', - 'phptype' => 'string', - 'null' => false, - 'default' => '', - ), - 'location_name' => - array ( - 'dbtype' => 'varchar', - 'precision' => '255', - 'phptype' => 'string', - 'null' => false, - 'default' => '', - ), - 'location_address' => - array ( - 'dbtype' => 'text', - 'phptype' => 'string', - 'null' => false, - 'default' => '', - ), - 'map' => - array ( - 'dbtype' => 'boolean', - 'phptype' => 'boolean', - 'null' => false, - 'default' => 0, - ), - 'allday' => - array ( - 'dbtype' => 'boolean', - 'phptype' => 'boolean', - 'null' => false, - 'default' => 0, - ), - 'startdate' => - array ( - 'dbtype' => 'int', - 'precision' => '20', - 'phptype' => 'integer', - 'null' => true, - ), - 'enddate' => - array ( - 'dbtype' => 'int', - 'precision' => '20', - 'phptype' => 'integer', - 'null' => true, - ), - 'repeating' => - array ( - 'dbtype' => 'boolean', - 'phptype' => 'boolean', - 'null' => false, - 'default' => 0, - ), - 'repeattype' => - array ( - 'dbtype' => 'int', - 'precision' => '1', - 'phptype' => 'integer', - 'null' => true, - ), - 'repeaton' => - array ( - 'dbtype' => 'varchar', - 'precision' => '15', - 'phptype' => 'string', - 'null' => true, - ), - 'repeatfrequency' => - array ( - 'dbtype' => 'int', - 'precision' => '2', - 'phptype' => 'int', - 'null' => true, - ), - 'repeatenddate' => - array ( - 'dbtype' => 'int', - 'precision' => '20', - 'phptype' => 'int', - 'null' => true, - ), - 'repeatdates' => - array ( - 'dbtype' => 'text', - 'phptype' => 'string', - 'null' => true, - ), - 'source' => - array ( - 'dbtype' => 'varchar', - 'precision' => '32', - 'phptype' => 'string', - 'null' => false, - 'default' => 'local', - ), - 'feeds_id' => - array ( - 'dbtype' => 'int', - 'precision' => '20', - 'phptype' => 'integer', - 'null' => true, - 'default' => 0, - ), - 'feeds_uid' => - array ( - 'dbtype' => 'varchar', - 'precision' => '255', - 'phptype' => 'string', - 'null' => true, - 'default' => '', - ), - 'lastedit' => - array ( - 'dbtype' => 'int', - 'precision' => '20', - 'phptype' => 'integer', - 'null' => true, - ), - 'context' => - array ( - 'dbtype' => 'varchar', - 'precision' => '255', - 'phptype' => 'string', - 'null' => false, - 'default' => '', - ), - 'calendar_id' => - array ( - 'dbtype' => 'int', - 'precision' => '20', - 'phptype' => 'integer', - 'null' => true, - 'default' => 0, - ), - 'form_chunk' => - array ( - 'dbtype' => 'varchar', - 'precision' => '255', - 'phptype' => 'string', - 'null' => false, - 'default' => '', - ), - 'createdon' => - array ( - 'dbtype' => 'int', - 'precision' => '20', - 'phptype' => 'integer', - 'null' => true, - ), - 'createdby' => - array ( - 'dbtype' => 'int', - 'precision' => '10', - 'attributes' => 'unsigned', - 'phptype' => 'integer', - 'null' => false, - 'default' => 0, - ), - 'editedon' => - array ( - 'dbtype' => 'int', - 'precision' => '20', - 'phptype' => 'integer', - 'null' => true, - ), - 'editedby' => - array ( - 'dbtype' => 'int', - 'precision' => '10', - 'attributes' => 'unsigned', - 'phptype' => 'integer', - 'null' => false, - 'default' => 0, - ), - 'active' => - array ( - 'dbtype' => 'boolean', - 'phptype' => 'boolean', - 'null' => false, - 'default' => 1, - ), - ), - 'composites' => - array ( - 'images' => - array ( - 'class' => 'mxCalendarEventImages', - 'local' => 'id', - 'foreign' => 'event_id', - 'cardinality' => 'many', - ), - 'videos' => - array ( - 'class' => 'mxCalendarEventVideos', - 'local' => 'id', - 'foreign' => 'event_id', - 'cardinality' => 'many', - ), - ), - 'aggregates' => - array ( - 'CalendarId' => - array ( - 'class' => 'mxCalendarCalendars', - 'local' => 'calendar_id', - 'foreign' => 'id', - 'cardinality' => 'one', - 'owner' => 'foreign', - ), - 'eventfeed' => - array ( - 'class' => 'mxCalendarFeed', - 'local' => 'feeds_id', - 'foreign' => 'id', - 'cardinality' => 'one', - 'owner' => 'foreign', - ), - 'WebUserGroup' => - array ( - 'class' => 'mxCalendarEventWUG', - 'local' => 'id', - 'foreign' => 'webusergroup', - 'cardinality' => 'many', - 'owner' => 'foreign', - ), - 'CreatedBy' => - array ( - 'class' => 'modUser', - 'local' => 'createdby', - 'foreign' => 'id', - 'cardinality' => 'one', - 'owner' => 'foreign', - ), - 'EditedBy' => - array ( - 'class' => 'modUser', - 'local' => 'editedby', - 'foreign' => 'id', - 'cardinality' => 'one', - 'owner' => 'foreign', - ), - ), -); +$xpdo_meta_map['mxCalendarEvents'] = [ + 'package' => 'mxcalendars', + 'version' => null, + 'table' => 'mxcalendars_events', + 'extends' => 'xPDOSimpleObject', + 'fields' => + [ + 'title' => '', + 'description' => '', + 'content' => '', + 'categoryid' => null, + 'link' => '', + 'linkrel' => '', + 'linktarget' => '', + 'location_name' => '', + 'location_address' => '', + 'map' => 0, + 'price' => '', + 'food' => '', + 'age' => '', + 'capacity' => 0, + 'allday' => 0, + 'startdate' => null, + 'enddate' => null, + 'repeating' => 0, + 'repeattype' => null, + 'repeaton' => null, + 'repeatfrequency' => null, + 'repeatenddate' => null, + 'repeatdates' => null, + 'source' => 'local', + 'feeds_id' => 0, + 'feeds_uid' => '', + 'lastedit' => null, + 'context' => '', + 'calendar_id' => 0, + 'form_chunk' => '', + 'createdon' => null, + 'createdby' => 0, + 'editedon' => null, + 'editedby' => 0, + 'active' => 1, + ], + 'fieldMeta' => + [ + 'title' => + [ + 'dbtype' => 'varchar', + 'precision' => '255', + 'phptype' => 'string', + 'null' => false, + 'default' => '', + ], + 'description' => + [ + 'dbtype' => 'text', + 'phptype' => 'string', + 'null' => false, + 'default' => '', + ], + 'content' => + [ + 'dbtype' => 'text', + 'phptype' => 'string', + 'null' => false, + 'default' => '', + ], + 'categoryid' => + [ + 'dbtype' => 'varchar', + 'precision' => '10', + 'phptype' => 'string', + 'null' => true, + ], + 'link' => + [ + 'dbtype' => 'varchar', + 'precision' => '255', + 'phptype' => 'string', + 'null' => false, + 'default' => '', + ], + 'linkrel' => + [ + 'dbtype' => 'varchar', + 'precision' => '255', + 'phptype' => 'string', + 'null' => false, + 'default' => '', + ], + 'linktarget' => + [ + 'dbtype' => 'varchar', + 'precision' => '255', + 'phptype' => 'string', + 'null' => false, + 'default' => '', + ], + 'location_name' => + [ + 'dbtype' => 'varchar', + 'precision' => '255', + 'phptype' => 'string', + 'null' => false, + 'default' => '', + ], + 'location_address' => + [ + 'dbtype' => 'text', + 'phptype' => 'string', + 'null' => false, + 'default' => '', + ], + 'map' => + [ + 'dbtype' => 'boolean', + 'phptype' => 'boolean', + 'null' => false, + 'default' => 0, + ], + 'price' => + [ + 'dbtype' => 'varchar', + 'precision' => '255', + 'phptype' => 'string', + 'null' => false, + 'default' => '', + ], + 'food' => + [ + 'dbtype' => 'text', + 'phptype' => 'string', + 'null' => false, + 'default' => '', + ], + 'age' => + [ + 'dbtype' => 'varchar', + 'precision' => '255', + 'phptype' => 'string', + 'null' => false, + 'default' => '', + ], + 'capacity' => + [ + 'dbtype' => 'int', + 'precision' => '3', + 'phptype' => 'integer', + 'null' => true, + ], + 'allday' => + [ + 'dbtype' => 'boolean', + 'phptype' => 'boolean', + 'null' => false, + 'default' => 0, + ], + 'startdate' => + [ + 'dbtype' => 'int', + 'precision' => '20', + 'phptype' => 'integer', + 'null' => true, + ], + 'enddate' => + [ + 'dbtype' => 'int', + 'precision' => '20', + 'phptype' => 'integer', + 'null' => true, + ], + 'repeating' => + [ + 'dbtype' => 'boolean', + 'phptype' => 'boolean', + 'null' => false, + 'default' => 0, + ], + 'repeattype' => + [ + 'dbtype' => 'int', + 'precision' => '1', + 'phptype' => 'integer', + 'null' => true, + ], + 'repeaton' => + [ + 'dbtype' => 'varchar', + 'precision' => '15', + 'phptype' => 'string', + 'null' => true, + ], + 'repeatfrequency' => + [ + 'dbtype' => 'int', + 'precision' => '2', + 'phptype' => 'int', + 'null' => true, + ], + 'repeatenddate' => + [ + 'dbtype' => 'int', + 'precision' => '20', + 'phptype' => 'int', + 'null' => true, + ], + 'repeatdates' => + [ + 'dbtype' => 'text', + 'phptype' => 'string', + 'null' => true, + ], + 'source' => + [ + 'dbtype' => 'varchar', + 'precision' => '32', + 'phptype' => 'string', + 'null' => false, + 'default' => 'local', + ], + 'feeds_id' => + [ + 'dbtype' => 'int', + 'precision' => '20', + 'phptype' => 'integer', + 'null' => true, + 'default' => 0, + ], + 'feeds_uid' => + [ + 'dbtype' => 'varchar', + 'precision' => '255', + 'phptype' => 'string', + 'null' => true, + 'default' => '', + ], + 'lastedit' => + [ + 'dbtype' => 'int', + 'precision' => '20', + 'phptype' => 'integer', + 'null' => true, + ], + 'context' => + [ + 'dbtype' => 'varchar', + 'precision' => '255', + 'phptype' => 'string', + 'null' => false, + 'default' => '', + ], + 'calendar_id' => + [ + 'dbtype' => 'int', + 'precision' => '20', + 'phptype' => 'integer', + 'null' => true, + 'default' => 0, + ], + 'form_chunk' => + [ + 'dbtype' => 'varchar', + 'precision' => '255', + 'phptype' => 'string', + 'null' => false, + 'default' => '', + ], + 'createdon' => + [ + 'dbtype' => 'int', + 'precision' => '20', + 'phptype' => 'integer', + 'null' => true, + ], + 'createdby' => + [ + 'dbtype' => 'int', + 'precision' => '10', + 'attributes' => 'unsigned', + 'phptype' => 'integer', + 'null' => false, + 'default' => 0, + ], + 'editedon' => + [ + 'dbtype' => 'int', + 'precision' => '20', + 'phptype' => 'integer', + 'null' => true, + ], + 'editedby' => + [ + 'dbtype' => 'int', + 'precision' => '10', + 'attributes' => 'unsigned', + 'phptype' => 'integer', + 'null' => false, + 'default' => 0, + ], + 'active' => + [ + 'dbtype' => 'boolean', + 'phptype' => 'boolean', + 'null' => false, + 'default' => 1, + ], + ], + 'composites' => + [ + 'images' => + [ + 'class' => 'mxCalendarEventImages', + 'local' => 'id', + 'foreign' => 'event_id', + 'cardinality' => 'many', + ], + 'videos' => + [ + 'class' => 'mxCalendarEventVideos', + 'local' => 'id', + 'foreign' => 'event_id', + 'cardinality' => 'many', + ], + ], + 'aggregates' => + [ + 'CalendarId' => + [ + 'class' => 'mxCalendarCalendars', + 'local' => 'calendar_id', + 'foreign' => 'id', + 'cardinality' => 'one', + 'owner' => 'foreign', + ], + 'eventfeed' => + [ + 'class' => 'mxCalendarFeed', + 'local' => 'feeds_id', + 'foreign' => 'id', + 'cardinality' => 'one', + 'owner' => 'foreign', + ], + 'WebUserGroup' => + [ + 'class' => 'mxCalendarEventWUG', + 'local' => 'id', + 'foreign' => 'webusergroup', + 'cardinality' => 'many', + 'owner' => 'foreign', + ], + 'CreatedBy' => + [ + 'class' => 'modUser', + 'local' => 'createdby', + 'foreign' => 'id', + 'cardinality' => 'one', + 'owner' => 'foreign', + ], + 'EditedBy' => + [ + 'class' => 'modUser', + 'local' => 'editedby', + 'foreign' => 'id', + 'cardinality' => 'one', + 'owner' => 'foreign', + ], + ], +]; diff --git a/core/components/mxcalendars/model/schema/mxcalendars.mysql.schema.xml b/core/components/mxcalendars/model/schema/mxcalendars.mysql.schema.xml index 957c3df..acb986f 100644 --- a/core/components/mxcalendars/model/schema/mxcalendars.mysql.schema.xml +++ b/core/components/mxcalendars/model/schema/mxcalendars.mysql.schema.xml @@ -11,6 +11,10 @@ + + + + diff --git a/core/components/mxcalendars/processors/mgr/calendar/create.class.php b/core/components/mxcalendars/processors/mgr/calendar/create.class.php new file mode 100644 index 0000000..21a0295 --- /dev/null +++ b/core/components/mxcalendars/processors/mgr/calendar/create.class.php @@ -0,0 +1,78 @@ +getProperty('name'); + if (empty($name)) { + $this->addFieldError('name', $this->modx->lexicon('mxcalendars.err_ns_name')); + } else { + //-- Enforce a duplicate name check + $alreadyExists = $this->modx->getObject('mxCalendarCalendars', array('name' => $name)); + if ($alreadyExists) { + $this->addFieldError('name', $this->modx->lexicon('mxcalendars.err_ac')); + } + } + + // // not implemented yet + // //-- Set the createdby property of the current manager user + // $createdby = $this->getProperty('createdby'); + // if (empty($createdby)) { + // $this->setProperty('createdby', $this->modx->getLoginUserID()); + // } + // + // //-- Set the create date with current timestamp + // $this->setProperty('createdon', time()); + + $active = $this->getProperty('active'); + if (isset($active) && ((int)$active === 1 || $active === 'on')) { + $this->setProperty('active', 1); + } else { + $this->setProperty('active', 0); + } + + //-- show error messages + if ($this->hasErrors()) { + $errors = ''; + foreach($this->modx->error->getFields() as $error) { + $errors .= $error . '
'; + } + + $this->modx->error->failure($errors); + } + + return parent::beforeSet(); + } +} +return 'CalendarsCreateProcessor'; diff --git a/core/components/mxcalendars/processors/mgr/calendar/create.php b/core/components/mxcalendars/processors/mgr/calendar/create.php deleted file mode 100644 index 8c2b8b6..0000000 --- a/core/components/mxcalendars/processors/mgr/calendar/create.php +++ /dev/null @@ -1,33 +0,0 @@ -error->addField('name',$modx->lexicon('mxcalendars.err_ns_name')); -} else { - //-- Enforce a duplicate name check - $alreadyExists = $modx->getObject('mxCalendarCalendars',array('name' => $scriptProperties['name'])); - if ($alreadyExists) { - $modx->error->addField('name',$modx->lexicon('mxcalendars.err_ac')); - } -} - -//-- Check for any errors -if ($modx->error->hasError()) { return $modx->error->failure(); } - -if(isset($scriptProperties['active'])) - $scriptProperties['active']=1; -else - $scriptProperties['active']=0; - -//-- Get the mxCalendar object and set the values from form -$mxcalendar = $modx->newObject('mxCalendarCalendars'); -$mxcalendar->fromArray($scriptProperties); - -//-- Try to save the new record -if ($mxcalendar->save() == false) { - return $modx->error->failure($modx->lexicon('mxcalendars.err_save')); -} - -//-- If no errors return success -return $modx->error->success('',$mxcalendar); - -?> diff --git a/core/components/mxcalendars/processors/mgr/calendar/getlist.class.php b/core/components/mxcalendars/processors/mgr/calendar/getlist.class.php new file mode 100644 index 0000000..c9962ef --- /dev/null +++ b/core/components/mxcalendars/processors/mgr/calendar/getlist.class.php @@ -0,0 +1,76 @@ +getProperty('limit')); + $start = $this->getProperty('start'); + $limit = $this->getProperty('limit'); + $sort = $this->getProperty('sort'); + $dir = $this->getProperty('dir'); + $query = $this->getProperty('query'); + + /* build query */ + $c->select([ + 'mxCalendarCalendars.*', + ]); + if (!empty($query)) { + $c->where(array( + 'name:LIKE' => '%' . $query . '%', + )); + } + + $c->sortby($sort, $dir); + if ($isLimit) { + $c->limit($limit, $start); + } + + return $c; + } +} +return 'CalendarsGetListProcessor'; \ No newline at end of file diff --git a/core/components/mxcalendars/processors/mgr/calendar/getlist.php b/core/components/mxcalendars/processors/mgr/calendar/getlist.php deleted file mode 100644 index fffc031..0000000 --- a/core/components/mxcalendars/processors/mgr/calendar/getlist.php +++ /dev/null @@ -1,30 +0,0 @@ -getOption('start',$scriptProperties,0); -$limit = $modx->getOption('limit',$scriptProperties,10); -$sort = $modx->getOption('sort',$scriptProperties,'name'); -$dir = $modx->getOption('dir',$scriptProperties,'ASC'); -$query = $modx->getOption('query',$scriptProperties,''); - -/* build query */ -$c = $modx->newQuery('mxCalendarCalendars'); -if (!empty($query)) { - $c->where(array( - 'name:LIKE' => '%'.$query.'%' - )); -} -$count = $modx->getCount('mxCalendarCalendars',$c); -$c->sortby($sort,$dir); -if ($isLimit) $c->limit($limit,$start); -$mxcalendarsCals = $modx->getIterator('mxCalendarCalendars', $c); - -/* iterate */ -$list = array(); -foreach ($mxcalendarsCals as $mxc) { - $mxcArray = $mxc->toArray(); - $list[]= $mxcArray; -} -return $this->outputArray($list,$count); - -?> diff --git a/core/components/mxcalendars/processors/mgr/calendar/remove.class.php b/core/components/mxcalendars/processors/mgr/calendar/remove.class.php new file mode 100644 index 0000000..2b4497a --- /dev/null +++ b/core/components/mxcalendars/processors/mgr/calendar/remove.class.php @@ -0,0 +1,31 @@ +error->failure($modx->lexicon('mxcalendars.mxcalendars_err_ns')); -$mxcalendar = $modx->getObject('mxCalendarCalendars',$scriptProperties['id']); -if (empty($mxcalendar)) return $modx->error->failure($modx->lexicon('mxcalendars.mxcalendars_err_nf')); - -//-- Remove the calendar record -if ($mxcalendar->remove() == false) { - return $modx->error->failure($modx->lexicon('mxcalendars.mxcalendars_err_remove')); -} - -//-- If no errors return success -return $modx->error->success('',$mxcalendar); - -?> diff --git a/core/components/mxcalendars/processors/mgr/calendar/update.class.php b/core/components/mxcalendars/processors/mgr/calendar/update.class.php new file mode 100644 index 0000000..ac402b1 --- /dev/null +++ b/core/components/mxcalendars/processors/mgr/calendar/update.class.php @@ -0,0 +1,95 @@ +getProperty('id'); + if (empty($id)) { + $this->addFieldError('id', 'ID Not found ' . $this->modx->lexicon('mxcalendars.err_nf')); + } + + //-- Now check to make sure that the calendar item exist and can be updated + $mxcalendar = $this->modx->getObject('mxCalendarCalendars', $id); + if (empty($mxcalendar)) { + $this->addFieldError('id', 'ID Not found ' . $this->modx->lexicon('mxcalendars.mxcalendars_err_nf')); + } + + //-- Validation for the Name field + $name = $this->getProperty('name'); + if (!isset($name)) { + $this->addFieldError('name', $this->modx->lexicon('mxcalendars.err_ns_name')); + } else { + //-- Enforce a duplicate name check + $query = $this->modx->newQuery('mxCalendarCalendars'); + $query->where(array( + 'name:LIKE' => '%' . $name . '%', + 'id:!=' => $id, + )); + $alreadyExists = $this->modx->getCollection('mxCalendarCalendars', $query); + if ($alreadyExists) { + $this->addFieldError('name', $this->modx->lexicon('mxcalendars.err_ac')); + } + } + + $active = $this->getProperty('active'); + if (isset($active) && ((int)$active === 1 || $active === 'on')) { + $this->setProperty('active', 1); + } else { + $this->setProperty('active', 0); + } + + // //not implemented yet + // //-- Set the edited by user id based on authenticated user + // $editedBy = $this->getProperty('editedby'); + // if (empty($editedBy)) { + // $this->setProperty('editedby', $this->modx->getLoginUserID()); + // } + // + // //-- Set the edited date/time stamp + // $this->setProperty('editedon', time()); + + //-- show error messages + if ($this->hasErrors()) { + $errors = ''; + foreach($this->modx->error->getFields() as $error) { + $errors .= $error . '
'; + } + + $this->modx->error->failure($errors); + } + + return parent::beforeSet(); + } +} +return 'CalendarsUpdateProcessor'; diff --git a/core/components/mxcalendars/processors/mgr/calendar/update.php b/core/components/mxcalendars/processors/mgr/calendar/update.php deleted file mode 100644 index cb50895..0000000 --- a/core/components/mxcalendars/processors/mgr/calendar/update.php +++ /dev/null @@ -1,29 +0,0 @@ -error->failure($modx->lexicon('mxcalendars.mxcalendars_err_ns')); - -//-- Now check to make sure that the calendar item exist and can be updated -$mxcalendar = $modx->getObject('mxCalendarCalendars',$scriptProperties['id']); -if (empty($mxcalendar)) - return $modx->error->failure($modx->lexicon('mxcalendars.mxcalendars_err_nf')); - -if(isset($scriptProperties['active'])) - $scriptProperties['active']=1; -else - $scriptProperties['active']=0; - - -//-- Set mxcalendar fields -$mxcalendar->fromArray($scriptProperties); - -//-- Try to update calendar item -if ($mxcalendar->save() == false) { - return $modx->error->failure($modx->lexicon('mxcalendars.mxcalendars_err_save')); -} - -//-- Return success message if no error was found on update (save) -return $modx->error->success('',$mxcalendar); -?> diff --git a/core/components/mxcalendars/processors/mgr/calendar/updatefromgrid.class.php b/core/components/mxcalendars/processors/mgr/calendar/updatefromgrid.class.php new file mode 100644 index 0000000..2903615 --- /dev/null +++ b/core/components/mxcalendars/processors/mgr/calendar/updatefromgrid.class.php @@ -0,0 +1,34 @@ +getProperty('data'); + if (empty($data)) { + return $this->modx->lexicon('invalid_data'); + } + $data = $this->modx->fromJSON($data); + //-- Both date and time are always posted back + if (empty($data)) { + return $this->modx->lexicon('invalid_data'); + } + + $data['updatefromgrid'] = 1; + + $this->setProperties($data); + $this->unsetProperty('data'); + + return parent::initialize(); + } + +} +return 'CalendarsUpdateFromGridProcessor'; \ No newline at end of file diff --git a/core/components/mxcalendars/processors/mgr/calendar/updatefromgrid.php b/core/components/mxcalendars/processors/mgr/calendar/updatefromgrid.php deleted file mode 100644 index 013bfac..0000000 --- a/core/components/mxcalendars/processors/mgr/calendar/updatefromgrid.php +++ /dev/null @@ -1,33 +0,0 @@ -error->failure('Invalid calendar data (1a).'); - $_DATA = $modx->fromJSON($_REQUEST['data']); -if (!is_array($_DATA)) return $modx->error->failure('Invalid calendar data (1b).'); - -//-- Check for the required category ID -if (empty($_DATA['id'])) - return $modx->error->failure($modx->lexicon('mxcalendars.err_ns')); - -if(isset($_DATA['active'])) - $_DATA['active']=1; -else - $_DATA['active']=0; - -//-- Now check to make sure that the category item exist and can be updated -$mxcalendar = $modx->getObject('mxCalendarCalendars',$_DATA['id']); -if (empty($mxcalendar)) - return $modx->error->failure($modx->lexicon('mxcalendars.err_nf')); - - -//-- Set mxcalendar fields -$mxcalendar->fromArray($_DATA); - -//-- Try to update calendar item -if ($mxcalendar->save() == false) { - return $modx->error->failure($modx->lexicon('mxcalendars.err_save')); -} - -//-- Return success message if no error was found on update (save) -return $modx->error->success('',$mxcalendar); -?> diff --git a/core/components/mxcalendars/processors/mgr/category/create.class.php b/core/components/mxcalendars/processors/mgr/category/create.class.php new file mode 100644 index 0000000..e7a2f5c --- /dev/null +++ b/core/components/mxcalendars/processors/mgr/category/create.class.php @@ -0,0 +1,91 @@ +getProperty('name'); + if (empty($name)) { + $this->addFieldError('name', $this->modx->lexicon('mxcalendars.err_ns_name')); + } else { + //-- Enforce a duplicate name check + $alreadyExists = $this->modx->getObject('mxCalendarCategories', array('name' => $name)); + if ($alreadyExists) { + $this->addFieldError('name', $this->modx->lexicon('mxcalendars.err_category_ac')); + } + } + + //-- Set the createdby property of the current manager user + $createdby = $this->getProperty('createdby'); + if (empty($createdby)) { + $this->setProperty('createdby', $this->modx->getLoginUserID()); + } + + //-- Set the create date with current timestamp + $this->setProperty('createdon', time()); + + $active = $this->getProperty('active'); + if (isset($active) && ((int)$active === 1 || $active === 'on')) { + $this->setProperty('active', 1); + } else { + $this->setProperty('active', 0); + } + + $disable = $this->getProperty('disable'); + if (isset($disable) && ((int)$disable === 1 || $disable === 'on')) { + $this->setProperty('disable', 1); + } else { + $this->setProperty('disable', 0); + } + + $isdefault = $this->getProperty('isdefault'); + if (isset($isdefault) && ((int)$isdefault === 1 || $isdefault === 'on')) { + $this->setProperty('isdefault', 1); + } else { + $this->setProperty('isdefault', 0); + } + + //-- show error messages + if ($this->hasErrors()) { + $errors = ''; + foreach($this->modx->error->getFields() as $error) { + $errors .= $error . '
'; + } + + $this->modx->error->failure($errors); + } + + return parent::beforeSet(); + } +} +return 'CategoriesCreateProcessor'; diff --git a/core/components/mxcalendars/processors/mgr/category/create.php b/core/components/mxcalendars/processors/mgr/category/create.php deleted file mode 100644 index 47e04ed..0000000 --- a/core/components/mxcalendars/processors/mgr/category/create.php +++ /dev/null @@ -1,43 +0,0 @@ -error->addField('name',$modx->lexicon('mxcalendars.err_ns_name')); -} else { - //-- Enforce a duplicate name check - $alreadyExists = $modx->getObject('mxCalendarCategories',array('name' => $scriptProperties['name'])); - if ($alreadyExists) { - $modx->error->addField('name',$modx->lexicon('mxcalendars.err_ae')); - } -} - -//-- Set the createdby property of the current manager user -if(empty($scriptProperties['createdby'])){ - $scriptProperties['createdby'] = $modx->getLoginUserID(); -} - -//-- Set the create date with current timestamp -$scriptProperties['createdon'] = time(); - -//-- Check for any errors -if ($modx->error->hasError()) { return $modx->error->failure(); } - -if(isset($scriptProperties['active'])) - $scriptProperties['active']=1; -if(isset($scriptProperties['disabled'])) - $scriptProperties['disabled'] = 1; -if(isset($scriptProperties['isdefault'])) - $scriptProperties['isdefault']=1; - -//-- Get the mxCalendar object and set the values from form -$mxcalendar = $modx->newObject('mxCalendarCategories'); -$mxcalendar->fromArray($scriptProperties); - -//-- Try to save the new record -if ($mxcalendar->save() == false) { - return $modx->error->failure($modx->lexicon('mxcalendars.err_save')); -} - -//-- If no errors return success -return $modx->error->success('',$mxcalendar); - -?> diff --git a/core/components/mxcalendars/processors/mgr/category/getlist.class.php b/core/components/mxcalendars/processors/mgr/category/getlist.class.php new file mode 100644 index 0000000..fed8f35 --- /dev/null +++ b/core/components/mxcalendars/processors/mgr/category/getlist.class.php @@ -0,0 +1,77 @@ +getProperty('limit')); + $start = $this->getProperty('start'); + $limit = $this->getProperty('limit'); + $sort = $this->getProperty('sort'); + $dir = $this->getProperty('dir'); + $query = $this->getProperty('query'); + + /* build query */ + $c->select([ + 'mxCalendarCategories.*', + ]); + if (!empty($query)) { + $c->where(array( + 'name:LIKE' => '%'.$query.'%', + 'OR:description:LIKE' => '%'.$query.'%', + )); + } + + $c->sortby($sort, $dir); + if ($isLimit) { + $c->limit($limit, $start); + } + + return $c; + } +} +return 'CategoriesGetListProcessor'; \ No newline at end of file diff --git a/core/components/mxcalendars/processors/mgr/category/getlist.php b/core/components/mxcalendars/processors/mgr/category/getlist.php deleted file mode 100644 index ae95a8b..0000000 --- a/core/components/mxcalendars/processors/mgr/category/getlist.php +++ /dev/null @@ -1,31 +0,0 @@ -getOption('start',$scriptProperties,0); -$limit = $modx->getOption('limit',$scriptProperties,10); -$sort = $modx->getOption('sort',$scriptProperties,'name'); -$dir = $modx->getOption('dir',$scriptProperties,'ASC'); -$query = $modx->getOption('query',$scriptProperties,''); - -/* build query */ -$c = $modx->newQuery('mxCalendarCategories'); -if (!empty($query)) { - $c->where(array( - 'name:LIKE' => '%'.$query.'%', - 'OR:description:LIKE' => '%'.$query.'%', - )); -} -$count = $modx->getCount('mxCalendarCategories',$c); -$c->sortby($sort,$dir); -if ($isLimit) $c->limit($limit,$start); -$mxcalendarsCats = $modx->getIterator('mxCalendarCategories', $c); - -/* iterate */ -$list = array(); -foreach ($mxcalendarsCats as $mxc) { - $mxcArray = $mxc->toArray(); - $list[]= $mxcArray; -} -return $this->outputArray($list,$count); - -?> diff --git a/core/components/mxcalendars/processors/mgr/category/remove.class.php b/core/components/mxcalendars/processors/mgr/category/remove.class.php new file mode 100644 index 0000000..5192a8e --- /dev/null +++ b/core/components/mxcalendars/processors/mgr/category/remove.class.php @@ -0,0 +1,31 @@ +error->failure($modx->lexicon('mxcalendars.mxcalendars_err_ns')); -$mxcalendar = $modx->getObject('mxCalendarCategories',$scriptProperties['id']); -if (empty($mxcalendar)) return $modx->error->failure($modx->lexicon('mxcalendars.mxcalendars_err_nf')); - -//-- Remove the category record -if ($mxcalendar->remove() == false) { - return $modx->error->failure($modx->lexicon('mxcalendars.mxcalendars_err_remove')); -} - -//-- If no errors return success -return $modx->error->success('',$mxcalendar); - -?> diff --git a/core/components/mxcalendars/processors/mgr/category/update.class.php b/core/components/mxcalendars/processors/mgr/category/update.class.php new file mode 100644 index 0000000..17e329b --- /dev/null +++ b/core/components/mxcalendars/processors/mgr/category/update.class.php @@ -0,0 +1,109 @@ +getProperty('id'); + if (empty($id)) { + $this->addFieldError('id', 'ID Not found ' . $this->modx->lexicon('mxcalendars.err_nf')); + } + + //-- Now check to make sure that the calendar item exist and can be updated + $mxcalendar = $this->modx->getObject('mxCalendarCategories', $id); + if (empty($mxcalendar)) { + $this->addFieldError('id', 'ID Not found ' . $this->modx->lexicon('mxcalendars.mxcalendars_err_nf')); + } + + //-- Validation for the Name field + $name = $this->getProperty('name'); + if (!isset($name)) { + $this->addFieldError('name', $this->modx->lexicon('mxcalendars.err_ns_name')); + } else { + //-- Enforce a duplicate name check + $query = $this->modx->newQuery('mxCalendarCategories'); + $query->where(array( + 'name:LIKE' => '%' . $name . '%', + 'id:!=' => $id, + )); + $alreadyExists = $this->modx->getCollection('mxCalendarCategories', $query); + if ($alreadyExists) { + $this->addFieldError('name', $this->modx->lexicon('mxcalendars.err_category_ac')); + } + } + + $active = $this->getProperty('active'); + if (isset($active) && ((int)$active === 1 || $active === 'on')) { + $this->setProperty('active', 1); + } else { + $this->setProperty('active', 0); + } + + $disable = $this->getProperty('disable'); + if (isset($disable) && ((int)$disable === 1 || $disable === 'on')) { + $this->setProperty('disable', 1); + } else { + $this->setProperty('disable', 0); + } + + $isdefault = $this->getProperty('isdefault'); + if (isset($isdefault) && ((int)$isdefault === 1 || $isdefault === 'on')) { + $this->setProperty('isdefault', 1); + } else { + $this->setProperty('isdefault', 0); + } + + //-- Set the edited by user id based on authenticated user + $editedBy = $this->getProperty('editedby'); + if (empty($editedBy)) { + $this->setProperty('editedby', $this->modx->getLoginUserID()); + } + + //-- Set the edited date/time stamp + $this->setProperty('editedon', time()); + + //-- show error messages + if ($this->hasErrors()) { + $errors = ''; + foreach($this->modx->error->getFields() as $error) { + $errors .= $error . '
'; + } + + $this->modx->error->failure($errors); + } + + return parent::beforeSet(); + } +} +return 'CategoriesUpdateProcessor'; diff --git a/core/components/mxcalendars/processors/mgr/category/update.php b/core/components/mxcalendars/processors/mgr/category/update.php deleted file mode 100644 index 78812d2..0000000 --- a/core/components/mxcalendars/processors/mgr/category/update.php +++ /dev/null @@ -1,39 +0,0 @@ -error->failure($modx->lexicon('mxcalendars.mxcalendars_err_ns')); - -//-- Now check to make sure that the calendar item exist and can be updated -$mxcalendar = $modx->getObject('mxCalendarCategories',$scriptProperties['id']); -if (empty($mxcalendar)) - return $modx->error->failure($modx->lexicon('mxcalendars.mxcalendars_err_nf')); - -if(isset($scriptProperties['active'])) - $scriptProperties['active']=1; -if(isset($scriptProperties['disable'])) - $scriptProperties['disable'] = 1; -if(isset($scriptProperties['isdefault'])) - $scriptProperties['isdefault']=1; - -//-- Set the edited by user id based on authenticated user -if(empty($scriptProperties['editedby'])){ - $scriptProperties['editedby'] = $modx->getLoginUserID(); -} - -//-- Set the edited date/time stamp -$scriptProperties['editedon'] = time(); - - -//-- Set mxcalendar fields -$mxcalendar->fromArray($scriptProperties); - -//-- Try to update calendar item -if ($mxcalendar->save() == false) { - return $modx->error->failure($modx->lexicon('mxcalendars.mxcalendars_err_save')); -} - -//-- Return success message if no error was found on update (save) -return $modx->error->success('',$mxcalendar); -?> diff --git a/core/components/mxcalendars/processors/mgr/category/updatefromgrid.class.php b/core/components/mxcalendars/processors/mgr/category/updatefromgrid.class.php new file mode 100644 index 0000000..8d9c64c --- /dev/null +++ b/core/components/mxcalendars/processors/mgr/category/updatefromgrid.class.php @@ -0,0 +1,34 @@ +getProperty('data'); + if (empty($data)) { + return $this->modx->lexicon('invalid_data'); + } + $data = $this->modx->fromJSON($data); + //-- Both date and time are always posted back + if (empty($data)) { + return $this->modx->lexicon('invalid_data'); + } + + $data['updatefromgrid'] = 1; + + $this->setProperties($data); + $this->unsetProperty('data'); + + return parent::initialize(); + } + +} +return 'CategoriesUpdateFromGridProcessor'; \ No newline at end of file diff --git a/core/components/mxcalendars/processors/mgr/category/updatefromgrid.php b/core/components/mxcalendars/processors/mgr/category/updatefromgrid.php deleted file mode 100644 index 15cecad..0000000 --- a/core/components/mxcalendars/processors/mgr/category/updatefromgrid.php +++ /dev/null @@ -1,34 +0,0 @@ -error->failure('Invalid data (1a).'); - $_DATA = $modx->fromJSON($_REQUEST['data']); -if (!is_array($_DATA)) return $modx->error->failure('Invalid data (1b).'); - -//-- Check for the required category ID -if (empty($_DATA['id'])) - return $modx->error->failure($modx->lexicon('mxcalendars.err_ns')); - -//-- Now check to make sure that the category item exist and can be updated -$mxcalendar = $modx->getObject('mxCalendarCategories',$_DATA['id']); -if (empty($mxcalendar)) - return $modx->error->failure($modx->lexicon('mxcalendars.err_nf')); - -//-- Set the edited by user id based on authenticated user -if(empty($_DATA['editedby'])){ - $_DATA['editedby'] = $modx->getLoginUserID(); -} -//-- Set the edited date/time stamp -$_DATA['editedon'] = time(); - -//-- Set mxcalendar fields -$mxcalendar->fromArray($_DATA); - -//-- Try to update calendar item -if ($mxcalendar->save() == false) { - return $modx->error->failure($modx->lexicon('mxcalendars.err_save')); -} - -//-- Return success message if no error was found on update (save) -return $modx->error->success('',$mxcalendar); -?> diff --git a/core/components/mxcalendars/processors/mgr/events/create.class.php b/core/components/mxcalendars/processors/mgr/events/create.class.php new file mode 100644 index 0000000..34545f1 --- /dev/null +++ b/core/components/mxcalendars/processors/mgr/events/create.class.php @@ -0,0 +1,162 @@ +getProperty('title'); + if (empty($title)) { + $this->addFieldError('title', $this->modx->lexicon('mxcalendars.err_event_req_name')); + } + + //-- Server Side Validation of Required Fields + if (!$this->modx->user->isMember('Administrator') && empty($this->getProperty('context'))) { + $this->addFieldError('context', $this->modx->lexicon('mxcalendars.err_event_req_context')); + } + + if (empty($this->getProperty('startdate_date'))) { + $this->addFieldError('startdate_date', $this->modx->lexicon('mxcalendars.err_event_req_startdate')); + } + if (empty($this->getProperty('startdate_time'))) { + $this->addFieldError('startdate_time', $this->modx->lexicon('mxcalendars.err_event_req_starttime')); + } + if (empty($this->getProperty('enddate_date'))) { + $this->addFieldError('enddate_date', $this->modx->lexicon('mxcalendars.err_event_req_enddate')); + } + if (empty($this->getProperty('enddate_time'))) { + $this->addFieldError('enddate_time', $this->modx->lexicon('mxcalendars.err_event_req_endtime')); + } + + //-- Both date and time are always posted back + if (!empty($this->getProperty('startdate_date')) && !empty($this->getProperty('startdate_time'))) { + $this->setProperty('startdate', + tstamptotime($this->getProperty('startdate_date'), $this->getProperty('startdate_time'), + true)); + } + if (!empty($this->getProperty('enddate_date')) && !empty($this->getProperty('enddate_time'))) { + $this->setProperty('enddate', + tstamptotime($this->getProperty('enddate_date'), $this->getProperty('enddate_time'), + true)); + } + if (!empty($this->getProperty('repeatenddate'))) { + $this->setProperty('repeatenddate', tstamptotime($this->getProperty('repeatenddate'))); + } else { + $this->setProperty('repeatenddate', null); + } + + if ((int)$this->getProperty('repeating') === 1) { + //-- Do some error checking just for repeating dates + if (null === $this->getProperty('repeattype')) { + $this->addFieldError('repeattype', $this->modx->lexicon('mxcalendars.err_event_req_repeattype')); + } elseif (empty($this->getProperty('repeaton')) && (int)$this->getProperty('repeattype') === 1) { + $this->addFieldError('repeaton', $this->modx->lexicon('mxcalendars.err_event_req_repeaton')); + } elseif (empty($this->getProperty('repeatfrequency')) && ((int)$this->getProperty('repeattype') === 2 || (int)$this->getProperty('repeattype') === 3)) { + $this->addFieldError('repeatfrequency', $this->modx->lexicon('mxcalendars.err_event_req_repeatfrequency')); + } + + if (empty($this->getProperty('repeatenddate'))) { + $this->addFieldError('repeatenddate', $this->modx->lexicon('mxcalendars.err_event_req_repeatenddate')); + } + } + + //-- Check if we have all the data to create the repeating field information + if ((int)$this->getProperty('repeating') === 1 && null !== $this->getProperty('repeattype') && null !== $this->getProperty('repeatfrequency') && !empty($this->getProperty('repeatenddate'))) { + $repeatDates = _getRepeatDates( + $this->getProperty('repeattype'), + $this->getProperty('repeatfrequency'), + 365, + $this->getProperty('startdate'), + $this->getProperty('repeatenddate'), + explode(',', substr($this->getProperty('repeaton'), 1)) + ); + $scriptProperties['repeatdates'] = $repeatDates; + $scriptProperties['repeatenddate'] = end(explode(',', $repeatDates)); + } + + //-- Category check for required by submission and settings + if (empty($this->getProperty('categoryid'))) { + $default_cat = $this->modx->getObject('mxCalendarCategories', [ + 'isdefault' => 1 + ]); + if ($default_cat) { + if ($default_cat->get('id')) { + $scriptProperties['categoryid'] = $default_cat->get('id'); + } else { + //-- Get the first published category + $default_cat = $this->modx->getObject('mxCalendarCategories', [ + 'active' => 1 + ]); + if ($default_cat->get('id')) { + $scriptProperties['categoryid'] = $default_cat->get('id'); + } else { + return $this->modx->error->failure($this->modx->lexicon('mxcalendars.err_event_req_validcat')); + } + } + } + } + + if ($this->getProperty('source') === 'feed') { + $scriptProperties['source'] = 'feed-manual-change'; + } + + //-- Set the edited by user id based on authenticated user + if (empty($this->getProperty('editedby'))) { + $scriptProperties['editedby'] = $this->modx->getLoginUserID(); + } + + $active = $this->getProperty('active'); + if (isset($active) && ((int)$active === 1 || $active === 'on')) { + $this->setProperty('active', 1); + } else { + $this->setProperty('active', 0); + } + + //-- show error messages + if ($this->hasErrors()) { + $errors = ''; + foreach($this->modx->error->getFields() as $error) { + $errors .= $error . '
'; + } + + $this->modx->error->failure($errors); + } + + return parent::beforeSet(); + } +} +return 'EventsCreateProcessor'; diff --git a/core/components/mxcalendars/processors/mgr/events/create.php b/core/components/mxcalendars/processors/mgr/events/create.php deleted file mode 100644 index 5bdca24..0000000 --- a/core/components/mxcalendars/processors/mgr/events/create.php +++ /dev/null @@ -1,121 +0,0 @@ -user->isMember('Administrator') && empty($scriptProperties['context'])) - $modx->error->addField('context', $modx->lexicon('mxcalendars.err_event_req_context')); -if (empty($scriptProperties['title'])) - $modx->error->addField('title',$modx->lexicon('mxcalendars.err_ns_title')); -if(empty($scriptProperties['startdate_date'])) - $modx->error->addField('startdate_date', $modx->lexicon('mxcalendars.err_event_req_startdate')); -if(empty($scriptProperties['startdate_time'])) - $modx->error->addField('startdate_time', $modx->lexicon('mxcalendars.err_event_req_starttime')); -if(empty($scriptProperties['enddate_date'])) - $modx->error->addField('enddate_date', $modx->lexicon('mxcalendars.err_event_req_enddate')); -if(empty($scriptProperties['enddate_time'])) - $modx->error->addField('enddate_time', $modx->lexicon('mxcalendars.err_event_req_endtime')); - - -//-- Both date and time are always posted back -$scriptProperties['startdate'] = tstamptotime($scriptProperties['startdate_date'],$scriptProperties['startdate_time'],true); -$scriptProperties['enddate'] = tstamptotime($scriptProperties['enddate_date'],$scriptProperties['enddate_time'],true); -$scriptProperties['repeatenddate'] = !empty($scriptProperties['repeatenddate'])?tstamptotime($scriptProperties['repeatenddate'],$scriptProperties['enddate_time'],true):null; - - -if($scriptProperties['repeating']==1){ - //-- Do some error checking just for repeating dates - if( !isset($scriptProperties['repeattype']) ) - $modx->error->addField('repeattype', $modx->lexicon('mxcalendars.err_event_req_repeattype')); - else - if(empty($scriptProperties['repeaton']) && (int)$scriptProperties['repeattype'] === 1) - $modx->error->addField('repeaton', $modx->lexicon('mxcalendars.err_event_req_repeaton')); - - if(empty($scriptProperties['repeatfrequency'])) - $modx->error->addField('repeatfrequency', $modx->lexicon('mxcalendars.err_event_req_repeatfrequency')); - if(empty($scriptProperties['repeatenddate'])) - $modx->error->addField('repeatenddate', $modx->lexicon('mxcalendars.err_event_req_repeatenddate')); -} - -//-- Check if we have all the data to create the repeating field information -if($scriptProperties['repeating']==1 && isset($scriptProperties['repeattype']) && isset($scriptProperties['repeatfrequency']) && !empty($scriptProperties['repeatenddate'])){ - $repeatDates = _getRepeatDates( - $scriptProperties['repeattype'] - , $scriptProperties['repeatfrequency'] - ,365 - , $scriptProperties['startdate'] - , $scriptProperties['repeatenddate'] - , explode(',', substr($scriptProperties['repeaton'],1)) - ); - $scriptProperties['repeatdates'] = $repeatDates; - $scriptProperties['repeatenddate'] = end(explode(',', $repeatDates)); -} else { - //-- return $modx->error->failure("Repeat criteria not meet .
".$scriptProperties['repeattype']); -} - -//-- Category check for required by submission and settings -if(empty($scriptProperties['categoryid'])){ - - $default_cat = $modx->getObject('mxCalendarCategories', array( - 'isdefault' => 1 - )); - - if($default_cat){ - if($default_cat->get('id')){ - $scriptProperties['categoryid'] = $default_cat->get('id'); - } else { - //-- Get the first published category - $default_cat = $modx->getObject('mxCalendarCategories', array( - 'active' => 1 - )); - if($default_cat->get('id')){ - $scriptProperties['categoryid'] = $default_cat->get('id'); - } else { - return $modx->error->failure($modx->lexicon('mxcalendars.err_event_req_validcat')); - } - } - } -} - -//-- Set the createdby property of the current manager user -if(empty($scriptProperties['createdby'])){ - $scriptProperties['createdby'] = $modx->getLoginUserID(); -} - -//-- Set the create date with current timestamp -$scriptProperties['createdon'] = time(); - -//-- Check for any errors -if ($modx->error->hasError()) { - return $modx->error->failure($modx->lexicon('mxcalendars.err_pre_save')); - //return $modx->error->failure(); -} - - -//-- Get the mxCalendar object and set the values from form -$mxcalendar = $modx->newObject('mxCalendarEvents'); -$mxcalendar->fromArray($scriptProperties); - -//-- Try to save the new record -if ($mxcalendar->save() == false) { - return $modx->error->failure($modx->lexicon('mxcalendars.mxcalendars_err_save')); -} else { - // Check for any images that are not assigned and assign them now - $images = $modx->getCollection('mxCalendarEventImages',array('event_id'=>0)); - if($images){ - foreach($images AS $image){ - $image->set('event_id',$mxcalendar->get('id')); - $image->save(); - } - } - -} - -//-- If no errors return success -return $modx->error->success('',$mxcalendar); - -?> diff --git a/core/components/mxcalendars/processors/mgr/events/getlist.class.php b/core/components/mxcalendars/processors/mgr/events/getlist.class.php new file mode 100644 index 0000000..e74155f --- /dev/null +++ b/core/components/mxcalendars/processors/mgr/events/getlist.class.php @@ -0,0 +1,192 @@ +getProperty('limit')); + $start = $this->getProperty('start'); + $limit = $this->getProperty('limit'); + $sort = $this->getProperty('sort'); + $dir = $this->getProperty('dir'); + $query = $this->getProperty('query'); + $historical = $this->getProperty('historical'); + + //-- Restrict Access Based on User Group Access + $userWUG_arr = $this->modx->user->getUserGroupNames(); + $userContextACL_arr = array(); + $userid = $this->modx->user->get('id'); + $ug = $this->modx->newQuery('modUserGroup'); + $ug->where(array( + 'name:IN' => $userWUG_arr, + )); + $mxc_groups = $this->modx->getIterator('modUserGroup', $ug); + if (count($mxc_groups)) + { + foreach ($mxc_groups AS $mxg) + { + + $webContextAccess = $this->modx->newQuery('modAccessContext'); + $webContextAccess->where(array( + 'principal' => $mxg->get('id'), + 'AND:target:!=' => 'mgr', + )); + $mxc_cntx = $this->modx->getIterator('modAccessContext', $webContextAccess); + + if (count($mxc_cntx)) + { + foreach ($mxc_cntx AS $acl) + { + if (!in_array($acl->get('target'), $userContextACL_arr)) + $userContextACL_arr[] = $acl->get('target'); + } + } + + } + } + if ($this->modx->user->isMember('Administrator')) { + $userContextACL_arr[] = ''; + } + + + /* build query */ + //$c = $this->modx->newQuery('mxCalendarEvents'); + $c->select([ + 'mxCalendarEvents.*', + //'CategoryId.name', 'CategoryId.foregroundcss', 'CategoryId.backgroundcss', 'CategoryId.inlinecss' + ]); + //$c->innerJoin('mxCalendarCategories','CategoryId'); + //$c->innerJoin('categoryid','id','mxCalendarEvents.categoryid = CategoryId'); + if (!empty($query)) { + $c->where([ + 'title:LIKE' => '%' . $query . '%', + 'OR:description:LIKE' => '%' . $query . '%', + //'OR:CategoryId.name:LIKE'=>'%'.$query.'%', + ]); + } else { + if ($historical) { + $c->where([ + 'repeating:=' => 0 + , + 'AND:enddate:<=' => time() + , + [ + 'OR:repeating:=' => 1 + , + 'AND:repeatenddate:<=' => time() + ] + ]); + } else { + $c->where([ + 'repeating:=' => 0 + , + 'AND:enddate:>=' => time() + , + [ + 'OR:repeating:=' => 1 + , + 'AND:repeatenddate:>=' => time() + ] + ]); + } + } + if (count($userContextACL_arr)) { + $c->where(['context:IN' => $userContextACL_arr]); + } + + //$count = $this->modx->getCount('mxCalendarEvents', $c); + $c->sortby($sort, $dir); + if ($isLimit) { + $c->limit($limit, $start); + } + + return $c; + } + + + public function prepareRow(xPDOObject $object) + { + $resourceArray = $object->toArray(); + + //-- Get Settings Date and Time formats + $dateFormat = $this->modx->getOption('mxcalendars.mgr_dateformat', '', 'm/d/Y'); + $timeFormat = $this->modx->getOption('mxcalendars.mgr_timeformat', '', 'g:i a'); + + //-- Split the single unix time stamp into date and time for UI + $resourceArray['startdate_date'] = date($dateFormat, $resourceArray['startdate']); + $resourceArray['startdate_time'] = date($timeFormat, $resourceArray['startdate']); + $resourceArray['enddate_date'] = date($dateFormat, $resourceArray['enddate']); + $resourceArray['enddate_time'] = date($timeFormat, $resourceArray['enddate']); + $ed = $resourceArray['repeatenddate']; + $resourceArray['repeatenddate'] = !empty($ed) ? $resourceArray['repeatenddate'] : null; + + //-- Get the names of the Categories for friendly output + $catFriendly = []; + $curCatIds = $resourceArray['categoryid']; + if (!empty($curCatIds)) { + $cats = explode(',', $curCatIds); + if (count($cats)) { + foreach ($cats AS $cat) { + $obj = $this->modx->getObject('mxCalendarCategories', $cat); + if ($obj) { + $catFriendly[] = $obj->get('name'); + } + } + } + } + $resourceArray['catfriendly'] = implode(', ', $catFriendly); + + if (false === $resourceArray['repeating']) { + $resourceArray['repeating'] = 'ne'; + } else { + $resourceArray['repeating'] = 'ano'; + } + + return $resourceArray; + } + +} +return 'EventsGetListProcessor'; diff --git a/core/components/mxcalendars/processors/mgr/events/getlist.php b/core/components/mxcalendars/processors/mgr/events/getlist.php deleted file mode 100644 index 4bae108..0000000 --- a/core/components/mxcalendars/processors/mgr/events/getlist.php +++ /dev/null @@ -1,143 +0,0 @@ -getOption('start',$scriptProperties,0); -$limit = $modx->getOption('limit',$scriptProperties,10); -$sort = $modx->getOption('sort',$scriptProperties,'startdate'); -$dir = $modx->getOption('dir',$scriptProperties,'ASC'); -$query = $modx->getOption('query',$scriptProperties,''); -$historical = $modx->getOption('historical',$scriptProperties,0); - -/* -$c = $xpdo->newQuery('Box'); -$c->innerJoin('BoxOwner','Owner'); // arguments are: className, alias -$c->innerJoin('User','User','Owner.user = User.id'); -// note the 3rd argument that defines the relationship in the innerJoin - -$c->where(array( - 'Box.width' => 5, - 'User.user' => 2, -)); -$c->sortby('Box.name','ASC'); -$c->limit(5,5); -$boxes = $xpdo->getCollection('Box',$c); -*/ - //$user->isMember('UserGroupName') - -//-- Restrict Access Based on User Group Access -$userWUG_arr = $modx->user->getUserGroupNames(); -$userContextACL_arr = array(); -$userid = $modx->user->get('id'); -$ug = $modx->newQuery('modUserGroup'); -$ug->where(array( - 'name:IN' => $userWUG_arr, -)); -$mxc_groups = $modx->getIterator('modUserGroup', $ug); -if(count($mxc_groups)){ - foreach($mxc_groups AS $mxg){ - - $webContextAccess = $modx->newQuery('modAccessContext'); - $webContextAccess->where(array( - 'principal' => $mxg->get('id'), - 'AND:target:!=' => 'mgr', - )); - $mxc_cntx = $modx->getIterator('modAccessContext', $webContextAccess); - - if(count($mxc_cntx)){ - foreach($mxc_cntx AS $acl){ - if(!in_array($acl->get('target'), $userContextACL_arr)) - $userContextACL_arr[] = $acl->get('target'); - } - } - - } -} -if($modx->user->isMember('Administrator')) { $userContextACL_arr[] = ''; } - - -/* build query */ -$c = $modx->newQuery('mxCalendarEvents'); -$c->select(array( - 'mxCalendarEvents.*', - //'CategoryId.name', 'CategoryId.foregroundcss', 'CategoryId.backgroundcss', 'CategoryId.inlinecss' -)); -//$c->innerJoin('mxCalendarCategories','CategoryId'); -//$c->innerJoin('categoryid','id','mxCalendarEvents.categoryid = CategoryId'); -if (!empty($query)) { - $c->where(array( - 'title:LIKE' => '%'.$query.'%', - 'OR:description:LIKE' => '%'.$query.'%', - //'OR:CategoryId.name:LIKE'=>'%'.$query.'%', - )); -} else { - if($historical){ - $c->where(array( - 'repeating:=' => 0 - ,'AND:enddate:<=' => time() - ,array( - 'OR:repeating:='=>1 - ,'AND:repeatenddate:<=' => time() - ) - )); - } else { - $c->where(array( - 'repeating:=' => 0 - ,'AND:enddate:>=' => time() - ,array( - 'OR:repeating:='=>1 - ,'AND:repeatenddate:>=' => time() - ) - )); - } -} -if(count($userContextACL_arr)){ - $c->where(array('context:IN' => $userContextACL_arr)); -} - -$count = $modx->getCount('mxCalendarEvents',$c); -$c->sortby($sort,$dir); -if ($isLimit) $c->limit($limit,$start); -$mxcalendars = $modx->getIterator('mxCalendarEvents', $c); - -//-- Get Settings Date and Time formats -$dateFormat = $modx->getOption('mxcalendars.mgr_dateformat', '', 'm/d/Y'); -$timeFormat = $modx->getOption('mxcalendars.mgr_timeformat', '', 'g:i a'); - -/* iterate */ -$list = array(); -foreach ($mxcalendars as $mxc) { - $mxcArray = $mxc->toArray(); - //-- Split the single unix time stamp into date and time for UI - $mxcArray['startdate_date'] = date($dateFormat,$mxc->get('startdate')); - $mxcArray['startdate_time'] = date($timeFormat,$mxc->get('startdate')); - $mxcArray['startdate'] = $mxc->get('startdate'); - - $mxcArray['enddate_date'] = date($dateFormat,$mxc->get('enddate')); - $mxcArray['enddate_time'] = date($timeFormat,$mxc->get('enddate')); - $mxcArray['enddate'] = $mxc->get('enddate'); - - $ed = $mxc->get('repeatenddate'); - $mxcArray['repeatenddate'] = !empty($ed) ? $mxc->get('repeatenddate') : null; - - //-- Get the names of the Categories for friendly output - $catFriendly = array(); - $curCatIds = $mxc->get('categoryid'); - if(!empty($curCatIds)){ - $cats = explode(',', $curCatIds); - if(count($cats)){ - foreach($cats AS $c){ - $obj = $modx->getObject('mxCalendarCategories',$c); - if($obj){ - $catFriendly[] = $obj->get('name'); - } - } - } - } - - $mxcArray['catfriendly'] = implode(', ', $catFriendly); - - $list[]= $mxcArray; -} -return $this->outputArray($list,$count); - -?> diff --git a/core/components/mxcalendars/processors/mgr/events/remove.class.php b/core/components/mxcalendars/processors/mgr/events/remove.class.php new file mode 100644 index 0000000..96d36e0 --- /dev/null +++ b/core/components/mxcalendars/processors/mgr/events/remove.class.php @@ -0,0 +1,32 @@ +error->failure($modx->lexicon('mxcalendars.mxcalendars_err_ns')); -$mxcalendar = $modx->getObject('mxCalendarEvents',$scriptProperties['id']); -if (empty($mxcalendar)) return $modx->error->failure($modx->lexicon('mxcalendars.mxcalendars_err_nf')); - -//-- Remove the category record -if ($mxcalendar->remove() == false) { - return $modx->error->failure($modx->lexicon('mxcalendars.mxcalendars_err_remove')); -} - -//-- If no errors return success -return $modx->error->success('',$mxcalendar); - -?> diff --git a/core/components/mxcalendars/processors/mgr/events/update.class.php b/core/components/mxcalendars/processors/mgr/events/update.class.php new file mode 100644 index 0000000..99f1cf7 --- /dev/null +++ b/core/components/mxcalendars/processors/mgr/events/update.class.php @@ -0,0 +1,193 @@ +getProperty('title'); + if (empty($title)) { + $this->addFieldError('title', $this->modx->lexicon('mxcalendars.err_event_req_name')); + } + + $id = $this->getProperty('id'); + if (empty($id)) { + $this->addFieldError('id', 'ID Not found ' . $this->modx->lexicon('mxcalendars.err_nf')); + } + + //-- Now check to make sure that the calendar item exist and can be updated + $mxcalendar = $this->modx->getObject('mxCalendarEvents', $id); + if (empty($mxcalendar)) { + $this->addFieldError('id', 'ID Not found ' . $this->modx->lexicon('mxcalendars.err_nf')); + } + //-- Server Side Validation of Required Fields + if (!$this->modx->user->isMember('Administrator') && empty($this->getProperty('context'))) { + $this->addFieldError('context', $this->modx->lexicon('mxcalendars.err_event_req_context')); + } + + if (empty($this->getProperty('startdate_date'))) { + $this->addFieldError('startdate_date', $this->modx->lexicon('mxcalendars.err_event_req_startdate')); + } + if (empty($this->getProperty('startdate_time'))) { + $this->addFieldError('startdate_time', $this->modx->lexicon('mxcalendars.err_event_req_starttime')); + } + if (empty($this->getProperty('enddate_date'))) { + $this->addFieldError('enddate_date', $this->modx->lexicon('mxcalendars.err_event_req_enddate')); + } + if (empty($this->getProperty('enddate_time'))) { + $this->addFieldError('enddate_time', $this->modx->lexicon('mxcalendars.err_event_req_endtime')); + } + + //-- Both date and time are always posted back + if ($this->getProperty('updatefromgrid') !== 1) { + if (!empty($this->getProperty('startdate_date')) && !empty($this->getProperty('startdate_time'))) { + $this->setProperty('startdate', + tstamptotime($this->getProperty('startdate_date'), $this->getProperty('startdate_time'), + true)); + } + if (!empty($this->getProperty('enddate_date')) && !empty($this->getProperty('enddate_time'))) { + $this->setProperty('enddate', + tstamptotime($this->getProperty('enddate_date'), $this->getProperty('enddate_time'), + true)); + } + if (!empty($this->getProperty('repeatenddate'))) { + $this->setProperty('repeatenddate', tstamptotime($this->getProperty('repeatenddate'))); + } else { + $this->setProperty('repeatenddate', null); + } + } else { + $this->setProperty('repeatenddate', strtotime($this->getProperty('repeatenddate'))); + if (!empty($this->getProperty('startdate_date')) && !empty($this->getProperty('startdate_time'))) { + $format = 'm.d. Y'; + $dateobj = DateTime::createFromFormat($format, $this->getProperty('startdate_date')); + $startDate = strtotime($dateobj->format('Y-m-d') . 'T' . date('H:i:s', strtotime($this->getProperty('startdate_time')))); + $this->setProperty('startdate', $startDate); + } + if (!empty($this->getProperty('enddate_date')) && !empty($this->getProperty('enddate_time'))) { + $format = 'm.d. Y'; + $dateobj = DateTime::createFromFormat($format, $this->getProperty('enddate_date')); + $endDate = strtotime($dateobj->format('Y-m-d') . 'T' . date('H:i:s', strtotime($this->getProperty('enddate_time')))); + $this->setProperty('enddate', $endDate); + } + } + + if ((int)$this->getProperty('repeating') === 1) { + //-- Do some error checking just for repeating dates + if (null === $this->getProperty('repeattype')) { + $this->addFieldError('repeattype', $this->modx->lexicon('mxcalendars.err_event_req_repeattype')); + } elseif (empty($this->getProperty('repeaton')) && (int)$this->getProperty('repeattype') === 1) { + $this->addFieldError('repeaton', $this->modx->lexicon('mxcalendars.err_event_req_repeaton')); + } elseif (empty($this->getProperty('repeatfrequency')) && ((int)$this->getProperty('repeattype') === 2 || (int)$this->getProperty('repeattype') === 3)) { + $this->addFieldError('repeatfrequency', $this->modx->lexicon('mxcalendars.err_event_req_repeatfrequency')); + } + + if (empty($this->getProperty('repeatenddate'))) { + $this->addFieldError('repeatenddate', $this->modx->lexicon('mxcalendars.err_event_req_repeatenddate')); + } + } + + //-- Check if we have all the data to create the repeating field information + if ((int)$this->getProperty('repeating') === 1 && null !== $this->getProperty('repeattype') && null !== $this->getProperty('repeatfrequency') && !empty($this->getProperty('repeatenddate'))) { + $repeatDates = _getRepeatDates( + $this->getProperty('repeattype'), + $this->getProperty('repeatfrequency'), + 365, + $this->getProperty('startdate'), + $this->getProperty('repeatenddate'), + explode(',', substr($this->getProperty('repeaton'), 1)) + ); + $scriptProperties['repeatdates'] = $repeatDates; + $scriptProperties['repeatenddate'] = end(explode(',', $repeatDates)); + } + + //-- Category check for required by submission and settings + if (empty($this->getProperty('categoryid'))) { + $default_cat = $this->modx->getObject('mxCalendarCategories', [ + 'isdefault' => 1 + ]); + if ($default_cat) { + if ($default_cat->get('id')) { + $scriptProperties['categoryid'] = $default_cat->get('id'); + } else { + //-- Get the first published category + $default_cat = $this->modx->getObject('mxCalendarCategories', [ + 'active' => 1 + ]); + if ($default_cat->get('id')) { + $scriptProperties['categoryid'] = $default_cat->get('id'); + } else { + return $this->modx->error->failure($this->modx->lexicon('mxcalendars.err_event_req_validcat')); + } + } + } + } + + if ($this->getProperty('source') === 'feed') { + $scriptProperties['source'] = 'feed-manual-change'; + } + + //-- Set the edited by user id based on authenticated user + $editedBy = $this->getProperty('editedby'); + if (empty($editedBy)) { + $this->setProperty('editedby', $this->modx->getLoginUserID()); + } + + $active = $this->getProperty('active'); + if (isset($active) && ((int)$active === 1 || $active === 'on')) { + $this->setProperty('active', 1); + } else { + $this->setProperty('active', 0); + } + + //-- Set the edited date/time stamp + $this->setProperty('editedon', time()); + + //-- show error messages + if ($this->hasErrors()) { + $errors = ''; + foreach($this->modx->error->getFields() as $error) { + $errors .= $error . '
'; + } + + $this->modx->error->failure($errors); + } + + return parent::beforeSet(); + } +} +return 'EventsUpdateProcessor'; diff --git a/core/components/mxcalendars/processors/mgr/events/update.php b/core/components/mxcalendars/processors/mgr/events/update.php deleted file mode 100644 index 41bcdb4..0000000 --- a/core/components/mxcalendars/processors/mgr/events/update.php +++ /dev/null @@ -1,117 +0,0 @@ -error->failure("ID Not found ".$modx->lexicon('mxcalendars.err_ns')); -//-- Now check to make sure that the calendar item exist and can be updated -$mxcalendar = $modx->getObject('mxCalendarEvents',$scriptProperties['id']); -if (empty($mxcalendar)) - return $modx->error->failure($modx->lexicon('mxcalendars.err_nf')); -//-- Server Side Validation of Required Fields -if(!$modx->user->isMember('Administrator') && empty($scriptProperties['context'])) - $modx->error->addField('context', $modx->lexicon('mxcalendars.err_event_req_context')); -if (empty($scriptProperties['title'])) - $modx->error->addField('title',$modx->lexicon('mxcalendars.err_ns_title')); -if(empty($scriptProperties['startdate_date'])) - $modx->error->addField('startdate_date', $modx->lexicon('mxcalendars.err_event_req_startdate')); -if(empty($scriptProperties['startdate_time'])) - $modx->error->addField('startdate_time', $modx->lexicon('mxcalendars.err_event_req_starttime')); -if(empty($scriptProperties['enddate_date'])) - $modx->error->addField('enddate_date', $modx->lexicon('mxcalendars.err_event_req_enddate')); -if(empty($scriptProperties['enddate_time'])) - $modx->error->addField('enddate_time', $modx->lexicon('mxcalendars.err_event_req_endtime')); - - -//-- Both date and time are always posted back -$scriptProperties['startdate'] = tstamptotime($scriptProperties['startdate_date'],$scriptProperties['startdate_time'],true); -$scriptProperties['enddate'] = tstamptotime($scriptProperties['enddate_date'],$scriptProperties['enddate_time'],true); -$scriptProperties['repeatenddate'] = !empty($scriptProperties['repeatenddate'])?tstamptotime($scriptProperties['repeatenddate'],$scriptProperties['enddate_time'],true):null; - -if($scriptProperties['repeating']==1){ - //-- Do some error checking just for repeating dates - if( !isset($scriptProperties['repeattype']) ) - $modx->error->addField('repeattype', $modx->lexicon('mxcalendars.err_event_req_repeattype')); - else - if(empty($scriptProperties['repeaton']) && (int)$scriptProperties['repeattype'] === 1) - $modx->error->addField('repeaton', $modx->lexicon('mxcalendars.err_event_req_repeaton')); - - if(empty($scriptProperties['repeatfrequency'])) - $modx->error->addField('repeatfrequency', $modx->lexicon('mxcalendars.err_event_req_repeatfrequency')); - if(empty($scriptProperties['repeatenddate'])) - $modx->error->addField('repeatenddate', $modx->lexicon('mxcalendars.err_event_req_repeatenddate')); -} - -//-- Check if we have all the data to create the repeating field information -if($scriptProperties['repeating']==1 && isset($scriptProperties['repeattype']) && isset($scriptProperties['repeatfrequency']) && !empty($scriptProperties['repeatenddate'])){ - $repeatDates = _getRepeatDates( - $scriptProperties['repeattype'] - , $scriptProperties['repeatfrequency'] - ,365 - , $scriptProperties['startdate'] - , $scriptProperties['repeatenddate'] - , explode(',', substr($scriptProperties['repeaton'],1)) - ); - $scriptProperties['repeatdates'] = $repeatDates; - $scriptProperties['repeatenddate'] = end(explode(',', $repeatDates)); -} else { - //-- return $modx->error->failure("Repeat criteria not meet .
".$scriptProperties['repeattype']); -} - -//-- Category check for required by submission and settings -if(empty($scriptProperties['categoryid'])){ - - $default_cat = $modx->getObject('mxCalendarCategories', array( - 'isdefault' => 1 - )); - - if($default_cat){ - if($default_cat->get('id')){ - $scriptProperties['categoryid'] = $default_cat->get('id'); - } else { - //-- Get the first published category - $default_cat = $modx->getObject('mxCalendarCategories', array( - 'active' => 1 - )); - if($default_cat->get('id')){ - $scriptProperties['categoryid'] = $default_cat->get('id'); - } else { - return $modx->error->failure($modx->lexicon('mxcalendars.err_event_req_validcat')); - } - } - } -} -if($scriptProperties['source'] == 'feed'){ - $scriptProperties['source'] = 'feed-manual-change'; -} - - -//-- Set the edited by user id based on authenticated user -if(empty($scriptProperties['editedby'])){ - $scriptProperties['editedby'] = $modx->getLoginUserID(); -} - -//-- Set the edited date/time stamp -$scriptProperties['editedon'] = time(); - -if ($modx->error->hasError()) { - return $modx->error->failure($modx->lexicon('mxcalendars.err_pre_save')); -} - -//-- Set mxcalendar fields -$mxcalendar->fromArray($scriptProperties); - -//-- Try to update calendar item -if ($mxcalendar->save() == false) { - return $modx->error->failure('bb: '.$modx->lexicon('mxcalendars.err_save')); -} - -//-- Return success message if no error was found on update (save) -return $modx->error->success('',$mxcalendar); -?> diff --git a/core/components/mxcalendars/processors/mgr/events/updatefromgrid.class.php b/core/components/mxcalendars/processors/mgr/events/updatefromgrid.class.php new file mode 100644 index 0000000..e271e50 --- /dev/null +++ b/core/components/mxcalendars/processors/mgr/events/updatefromgrid.class.php @@ -0,0 +1,34 @@ +getProperty('data'); + if (empty($data)) { + return $this->modx->lexicon('invalid_data'); + } + $data = $this->modx->fromJSON($data); + //-- Both date and time are always posted back + if (empty($data)) { + return $this->modx->lexicon('invalid_data'); + } + + $data['updatefromgrid'] = 1; + + $this->setProperties($data); + $this->unsetProperty('data'); + + return parent::initialize(); + } + +} +return 'EventsUpdateFromGridProcessor'; \ No newline at end of file diff --git a/core/components/mxcalendars/processors/mgr/events/updatefromgrid.php b/core/components/mxcalendars/processors/mgr/events/updatefromgrid.php deleted file mode 100644 index e02d797..0000000 --- a/core/components/mxcalendars/processors/mgr/events/updatefromgrid.php +++ /dev/null @@ -1,105 +0,0 @@ -error->failure('Invalid data (1a).'); - $_DATA = $modx->fromJSON($_REQUEST['data']); -if (!is_array($_DATA)) return $modx->error->failure('Invalid data.'); - -/* get obj */ -if (empty($_DATA['id'])) return $modx->error->failure($modx->lexicon('mxcalendars.mxcalendars_err_ns')); -$mxcalendar = $modx->getObject('mxCalendarEvents',$_DATA['id']); -if (empty($mxcalendar)) return $modx->error->failure($modx->lexicon('mxcalendars.mxcalendars_err_nf')); - -if(!$modx->user->isMember('Administrator') && empty($_DATA['context'])) - return $modx->error->failure($modx->lexicon('mxcalendars.err_event_req_context')); - - -// Check for external source flag -if($_DATA['feeds_id'] || $_DATA['source'] != 'local' || $_DATA['feeds_id']){ - //-- Allow only the actual active flag to be updated - $mxcalendar->set('active',$_DATA['active']); - - if($_DATA['source'] == 'feed'){ - $mxcalendar->set('source','feed-manual-change'); - } - -} else { - //-- Both date and time are always posted back - $_DATA['startdate'] = tstamptotime($_DATA['startdate_date'],$_DATA['startdate_time'],true); - $_DATA['enddate'] = tstamptotime($_DATA['enddate_date'],$_DATA['enddate_time'],true); - $_DATA['repeatenddate'] = !empty($_DATA['repeatenddate'])?tstamptotime($_DATA['repeatenddate'],$_DATA['enddate_time'],true):null; - - if($_DATA['repeating']==1){ - //-- Do some error checking just for repeating dates - if(empty($_DATA['repeattype'])) - $modx->error->addField('repeattype', $modx->lexicon('mxcalendars.err_event_req_repeattype')); - else - if(empty($_DATA['repeaton'])) - $modx->error->addField('repeaton', $modx->lexicon('mxcalendars.err_event_req_repeaton')); - if(empty($_DATA['repeatfrequency'])) - $modx->error->addField('repeatfrequency', $modx->lexicon('mxcalendars.err_event_req_repeatfrequency')); - if(empty($_DATA['repeatenddate'])) - $modx->error->addField('repeatenddate', $modx->lexicon('mxcalendars.err_event_req_repeatenddate')); - } - - //-- Check if we have all the data to create the repeating field information - if($_DATA['repeating']==1 && isset($_DATA['repeattype']) && isset($_DATA['repeatfrequency']) && !empty($_DATA['repeatenddate'])){ - $repeatDates = _getRepeatDates( - $_DATA['repeattype'] - , $_DATA['repeatfrequency'] - ,365 - , $_DATA['startdate'] - , $_DATA['repeatenddate'] - , explode(',', substr($_DATA['repeaton'],1)) - ); - $_DATA['repeatdates'] = $repeatDates; - $_DATA['repeatenddate'] = end(explode(',', $repeatDates)); - } else { - //-- return $modx->error->failure("Repeat criteria not meet .
".$_DATA['repeattype']); - } - - //-- Category check for required by submission and settings - if(empty($_DATA['categoryid'])){ - - $default_cat = $modx->getObject('mxCalendarCategories', array( - 'isdefault' => 1 - )); - - if(is_object($default_cat)){ - $_DATA['categoryid'] = $default_cat->get('id'); - } else { - //-- Get the first published category - $default_cat = $modx->getObject('mxCalendarCategories', array( - 'active' => 1 - )); - if($default_cat->getOne('id')){ - $_DATA['categoryid'] = $default_cat->get('id'); - } else { - return $modx->error->failure($modx->lexicon('mxcalendars.err_event_req_validcat')); - } - } - } - //-- Create the object from the json parsed array - $mxcalendar->fromArray($_DATA); -} - -/** - * Set the new value of the full unix time stamp from both date and time fields - * we could have also set this through the $_DATA properties as well before the fromArray line - */ -//$mxcalendar->set('startdate',strtotime($datestamp) ); - -/* save */ -if ($mxcalendar->save() == false) { - return $modx->error->failure($modx->lexicon('mxcalendars.mxcalendars_err_save')); -} - -return $modx->error->success('',$mxcalendar); - -?> diff --git a/core/components/mxcalendars/processors/mgr/feed/create.class.php b/core/components/mxcalendars/processors/mgr/feed/create.class.php new file mode 100644 index 0000000..f464a0c --- /dev/null +++ b/core/components/mxcalendars/processors/mgr/feed/create.class.php @@ -0,0 +1,69 @@ +getProperty('feed'); + if (empty($title)) { + $this->addFieldError('feed', $this->modx->lexicon('mxcalendars.err_feed_req_feed')); + } + + $defaultcategoryid = $this->getProperty('defaultcategoryid'); + if (empty($defaultcategoryid)) { + $this->addFieldError('defaultcategoryid', $this->modx->lexicon('mxcalendars.err_feed_req_default_category')); + } + + $type = $this->getProperty('type'); + if (empty($type)) { + $this->addFieldError('type', $this->modx->lexicon('mxcalendars.err_feed_req_type')); + } + + $active = $this->getProperty('active'); + if (isset($active) && ((int)$active === 1 || $active === 'on')) { + $this->setProperty('active', 1); + } else { + $this->setProperty('active', 0); + } + + //-- show error messages + if ($this->hasErrors()) { + $errors = ''; + foreach($this->modx->error->getFields() as $error) { + $errors .= $error . '
'; + } + + $this->modx->error->failure($errors); + } + + return parent::beforeSet(); + } +} +return 'FeedsCreateProcessor'; diff --git a/core/components/mxcalendars/processors/mgr/feed/create.php b/core/components/mxcalendars/processors/mgr/feed/create.php deleted file mode 100644 index 6e7ef4e..0000000 --- a/core/components/mxcalendars/processors/mgr/feed/create.php +++ /dev/null @@ -1,31 +0,0 @@ -error->addField('feed',$modx->lexicon('mxcalendars.err_ns_feed')); -} else { - //-- Enforce a duplicate name check - $alreadyExists = $modx->getObject('mxCalendarFeed',array('feed' => $scriptProperties['feed'])); - if ($alreadyExists) { - $modx->error->addField('feed',$modx->lexicon('mxcalendars.err_ae')); - } -} - -//-- Check for any errors -if ($modx->error->hasError()) { return $modx->error->failure(); } - -if(isset($scriptProperties['active'])) - $scriptProperties['active']=1; - -//-- Get the mxCalendar object and set the values from form -$mxcalendar = $modx->newObject('mxCalendarFeed'); -$mxcalendar->fromArray($scriptProperties); - -//-- Try to save the new record -if ($mxcalendar->save() == false) { - return $modx->error->failure($modx->lexicon('mxcalendars.err_save')); -} - -//-- If no errors return success -return $modx->error->success('',$mxcalendar); - -?> diff --git a/core/components/mxcalendars/processors/mgr/feed/getlist.class.php b/core/components/mxcalendars/processors/mgr/feed/getlist.class.php new file mode 100644 index 0000000..28011bf --- /dev/null +++ b/core/components/mxcalendars/processors/mgr/feed/getlist.class.php @@ -0,0 +1,76 @@ +getProperty('limit')); + $start = $this->getProperty('start'); + $limit = $this->getProperty('limit'); + $sort = $this->getProperty('sort'); + $dir = $this->getProperty('dir'); + $query = $this->getProperty('query'); + + /* build query */ + $c->select([ + 'mxCalendarFeed.*', + ]); + if (!empty($query)) { + $c->where(array( + 'feed:LIKE' => '%' . $query . '%', + )); + } + + $c->sortby($sort, $dir); + if ($isLimit) { + $c->limit($limit, $start); + } + + return $c; + } +} +return 'FeedsGetListProcessor'; \ No newline at end of file diff --git a/core/components/mxcalendars/processors/mgr/feed/getlist.php b/core/components/mxcalendars/processors/mgr/feed/getlist.php deleted file mode 100644 index ef42918..0000000 --- a/core/components/mxcalendars/processors/mgr/feed/getlist.php +++ /dev/null @@ -1,31 +0,0 @@ -getOption('start',$scriptProperties,0); -$limit = $modx->getOption('limit',$scriptProperties,10); -$sort = $modx->getOption('sort',$scriptProperties,'feed'); -$dir = $modx->getOption('dir',$scriptProperties,'ASC'); -$query = $modx->getOption('query',$scriptProperties,''); - -/* build query */ -$c = $modx->newQuery('mxCalendarFeed'); -if (!empty($query)) { - $c->where(array( - 'feed:LIKE' => '%'.$query.'%', - 'OR:type:LIKE' => '%'.$query.'%', - )); -} -$count = $modx->getCount('mxCalendarFeed',$c); -$c->sortby($sort,$dir); -if ($isLimit) $c->limit($limit,$start); -$mxresult = $modx->getIterator('mxCalendarFeed', $c); - -/* iterate */ -$list = array(); -foreach ($mxresult as $mxc) { - $mxcArray = $mxc->toArray(); - $list[]= $mxcArray; -} -return $this->outputArray($list,$count); - -?> diff --git a/core/components/mxcalendars/processors/mgr/feed/remove.class.php b/core/components/mxcalendars/processors/mgr/feed/remove.class.php new file mode 100644 index 0000000..fa230ad --- /dev/null +++ b/core/components/mxcalendars/processors/mgr/feed/remove.class.php @@ -0,0 +1,32 @@ +error->failure($modx->lexicon('mxcalendars.mxcalendars_err_ns')); -$mxcalendar = $modx->getObject('mxCalendarFeed',$scriptProperties['id']); -if (empty($mxcalendar)) return $modx->error->failure($modx->lexicon('mxcalendars.mxcalendars_err_nf')); - -//-- Remove the category record -if ($mxcalendar->remove() == false) { - return $modx->error->failure($modx->lexicon('mxcalendars.mxcalendars_err_remove')); -} - -//-- If no errors return success -return $modx->error->success('',$mxcalendar); - -?> diff --git a/core/components/mxcalendars/processors/mgr/feed/update.class.php b/core/components/mxcalendars/processors/mgr/feed/update.class.php new file mode 100644 index 0000000..25d2603 --- /dev/null +++ b/core/components/mxcalendars/processors/mgr/feed/update.class.php @@ -0,0 +1,81 @@ +getProperty('id'); + if (empty($id)) { + $this->addFieldError('id', 'ID Not found ' . $this->modx->lexicon('mxcalendars.mxcalendars_err_ns')); + } + //-- Now check to make sure that the calendar item exist and can be updated + $mxcalendar = $this->modx->getObject('mxCalendarFeed', $id); + if (empty($mxcalendar)) { + $this->addFieldError('id', 'ID Not found ' . $this->modx->lexicon('mxcalendars.mxcalendars_err_nf')); + } + + $title = $this->getProperty('feed'); + if (empty($title)) { + $this->addFieldError('feed', $this->modx->lexicon('mxcalendars.err_feed_req_feed')); + } + + $defaultcategoryid = $this->getProperty('defaultcategoryid'); + if (empty($defaultcategoryid)) { + $this->addFieldError('defaultcategoryid', $this->modx->lexicon('mxcalendars.err_feed_req_default_category')); + } + + $type = $this->getProperty('type'); + if (empty($type)) { + $this->addFieldError('type', $this->modx->lexicon('mxcalendars.err_feed_req_type')); + } + + $active = $this->getProperty('active'); + if (isset($active) && ((int)$active === 1 || $active === 'on')) { + $this->setProperty('active', 1); + } else { + $this->setProperty('active', 0); + } + + //-- show error messages + if ($this->hasErrors()) { + $errors = ''; + foreach($this->modx->error->getFields() as $error) { + $errors .= $error . '
'; + } + + $this->modx->error->failure($errors); + } + + return parent::beforeSet(); + } +} +return 'FeedsUpdateProcessor'; diff --git a/core/components/mxcalendars/processors/mgr/feed/update.php b/core/components/mxcalendars/processors/mgr/feed/update.php deleted file mode 100644 index 78ca943..0000000 --- a/core/components/mxcalendars/processors/mgr/feed/update.php +++ /dev/null @@ -1,27 +0,0 @@ -error->failure($modx->lexicon('mxcalendars.mxcalendars_err_ns')); - -//-- Now check to make sure that the calendar item exist and can be updated -$mxcalendar = $modx->getObject('mxCalendarFeed',$scriptProperties['id']); -if (empty($mxcalendar)) - return $modx->error->failure($modx->lexicon('mxcalendars.mxcalendars_err_nf')); - -if(isset($scriptProperties['active'])) - $scriptProperties['active']=1; - - -//-- Set mxcalendar fields -$mxcalendar->fromArray($scriptProperties); - -//-- Try to update calendar item -if ($mxcalendar->save() == false) { - return $modx->error->failure($modx->lexicon('mxcalendars.mxcalendars_err_save')); -} - -//-- Return success message if no error was found on update (save) -return $modx->error->success('',$mxcalendar); -?> diff --git a/core/components/mxcalendars/processors/mgr/feed/updatefromgrid.class.php b/core/components/mxcalendars/processors/mgr/feed/updatefromgrid.class.php new file mode 100644 index 0000000..894fbe5 --- /dev/null +++ b/core/components/mxcalendars/processors/mgr/feed/updatefromgrid.class.php @@ -0,0 +1,34 @@ +getProperty('data'); + if (empty($data)) { + return $this->modx->lexicon('invalid_data'); + } + $data = $this->modx->fromJSON($data); + //-- Both date and time are always posted back + if (empty($data)) { + return $this->modx->lexicon('invalid_data'); + } + + $data['updatefromgrid'] = 1; + + $this->setProperties($data); + $this->unsetProperty('data'); + + return parent::initialize(); + } + +} +return 'FeedsUpdateFromGridProcessor'; \ No newline at end of file diff --git a/core/components/mxcalendars/processors/mgr/feed/updatefromgrid.php b/core/components/mxcalendars/processors/mgr/feed/updatefromgrid.php deleted file mode 100644 index 9e1dbbd..0000000 --- a/core/components/mxcalendars/processors/mgr/feed/updatefromgrid.php +++ /dev/null @@ -1,27 +0,0 @@ -error->failure('Invalid data (1a).'); - $_DATA = $modx->fromJSON($_REQUEST['data']); -if (!is_array($_DATA)) return $modx->error->failure('Invalid data (1b).'); - -//-- Check for the required category ID -if (empty($_DATA['id'])) - return $modx->error->failure($modx->lexicon('mxcalendars.err_ns')); - -//-- Now check to make sure that the category item exist and can be updated -$mxcalendar = $modx->getObject('mxCalendarFeed',$_DATA['id']); -if (empty($mxcalendar)) - return $modx->error->failure($modx->lexicon('mxcalendars.err_nf')); - -//-- Set mxcalendar fields -$mxcalendar->fromArray($_DATA); - -//-- Try to update calendar item -if ($mxcalendar->save() == false) { - return $modx->error->failure($modx->lexicon('mxcalendars.err_save')); -} - -//-- Return success message if no error was found on update (save) -return $modx->error->success('',$mxcalendar); -?> diff --git a/core/components/mxcalendars/processors/mgr/images/create.class.php b/core/components/mxcalendars/processors/mgr/images/create.class.php new file mode 100644 index 0000000..287eb5a --- /dev/null +++ b/core/components/mxcalendars/processors/mgr/images/create.class.php @@ -0,0 +1,64 @@ +getProperty('title'); + if (empty($title)) { + $this->addFieldError('title', $this->modx->lexicon('mxcalendars.err_event_image_req_name')); + } + + $filepath = $this->getProperty('filepath'); + if (empty($filepath)) { + $this->addFieldError('filepath', $this->modx->lexicon('mxcalendars.err_event_image_req_filepath')); + } + + $active = $this->getProperty('active'); + if (isset($active) && ((int)$active === 1 || $active === 'on')) { + $this->setProperty('active', 1); + } else { + $this->setProperty('active', 0); + } + + //-- show error messages + if ($this->hasErrors()) { + $errors = ''; + foreach($this->modx->error->getFields() as $error) { + $errors .= $error . '
'; + } + + $this->modx->error->failure($errors); + } + + return parent::beforeSet(); + } +} +return 'EventImagesCreateProcessor'; diff --git a/core/components/mxcalendars/processors/mgr/images/create.php b/core/components/mxcalendars/processors/mgr/images/create.php deleted file mode 100644 index b8ed813..0000000 --- a/core/components/mxcalendars/processors/mgr/images/create.php +++ /dev/null @@ -1,20 +0,0 @@ -newObject('mxCalendarEventImages'); -$mxcalendar->fromArray($scriptProperties); - -//-- Try to save the new record -if ($mxcalendar->save() == false) { - return $modx->error->failure($modx->lexicon('mxcalendars.err_save')); -} - -//-- If no errors return success -return $modx->error->success('',$mxcalendar); - -?> diff --git a/core/components/mxcalendars/processors/mgr/images/getlist.class.php b/core/components/mxcalendars/processors/mgr/images/getlist.class.php new file mode 100644 index 0000000..e1a7899 --- /dev/null +++ b/core/components/mxcalendars/processors/mgr/images/getlist.class.php @@ -0,0 +1,77 @@ +getProperty('limit')); + $start = $this->getProperty('start'); + $limit = $this->getProperty('limit'); + $sort = $this->getProperty('sort'); + $dir = $this->getProperty('dir'); + $query = $this->getProperty('query'); + + /* build query */ + $c->select([ + 'mxCalendarEventImages.*', + ]); + if (!empty($query)) { + $c->where(array( + 'title:LIKE' => '%' . $query . '%', + 'OR:description:LIKE' => '%' . $query . '%', + )); + } + + $c->sortby($sort, $dir); + if ($isLimit) { + $c->limit($limit, $start); + } + + return $c; + } +} +return 'EventImagesGetListProcessor'; \ No newline at end of file diff --git a/core/components/mxcalendars/processors/mgr/images/getlist.php b/core/components/mxcalendars/processors/mgr/images/getlist.php deleted file mode 100644 index 50bec45..0000000 --- a/core/components/mxcalendars/processors/mgr/images/getlist.php +++ /dev/null @@ -1,35 +0,0 @@ -getOption('eventid',$scriptProperties,0); -$isLimit = !empty($scriptProperties['limit']); -$start = $modx->getOption('start',$scriptProperties,0); -$limit = 3;//$modx->getOption('limit',$scriptProperties,5); -$sort = $modx->getOption('sort',$scriptProperties,'title'); -$dir = $modx->getOption('dir',$scriptProperties,'ASC'); -$query = $modx->getOption('query',$scriptProperties,''); - -/* build query */ -$c = $modx->newQuery('mxCalendarEventImages'); -$c->where(array('event_id'=>$eventId)); -if (!empty($query)) { - $c->where(array( - 'title:LIKE' => '%'.$query.'%' - ,'OR:description:LIKE' => '%'.$query.'%' - )); -} - - - -$count = $modx->getCount('mxCalendarEventImages',$c); -$c->sortby($sort,$dir); -$c->limit($limit,$start); -$mxcalendarsImages = $modx->getIterator('mxCalendarEventImages', $c); - -/* iterate */ -$list = array(); -foreach ($mxcalendarsImages as $mxc) { - $mxcArray = $mxc->toArray(); - $list[]= $mxcArray; -} -return $this->outputArray($list,$count); - -?> diff --git a/core/components/mxcalendars/processors/mgr/images/remove.class.php b/core/components/mxcalendars/processors/mgr/images/remove.class.php new file mode 100644 index 0000000..a95897d --- /dev/null +++ b/core/components/mxcalendars/processors/mgr/images/remove.class.php @@ -0,0 +1,32 @@ +error->failure($modx->lexicon('mxcalendars.mxcalendars_err_ns')); -$mxcalendar = $modx->getObject('mxCalendarEventImages',$scriptProperties['id']); -if (empty($mxcalendar)) return $modx->error->failure($modx->lexicon('mxcalendars.mxcalendars_err_nf')); - -//-- Remove the calendar record -if ($mxcalendar->remove() == false) { - return $modx->error->failure($modx->lexicon('mxcalendars.mxcalendars_err_remove')); -} - -//-- If no errors return success -return $modx->error->success('',$mxcalendar); - -?> diff --git a/core/components/mxcalendars/processors/mgr/images/update.class.php b/core/components/mxcalendars/processors/mgr/images/update.class.php new file mode 100644 index 0000000..2b79447 --- /dev/null +++ b/core/components/mxcalendars/processors/mgr/images/update.class.php @@ -0,0 +1,77 @@ +getProperty('id'); + if (empty($id)) { + $this->addFieldError('id', 'ID Not found ' . $this->modx->lexicon('mxcalendars.mxcalendars_err_ns')); + } + //-- Now check to make sure that the calendar item exist and can be updated + $mxcalendar = $this->modx->getObject('mxCalendarEventImages', $id); + if (empty($mxcalendar)) { + $this->addFieldError('id', 'ID Not found ' . $this->modx->lexicon('mxcalendars.mxcalendars_err_nf')); + } + + //-- Validation for the Name field + $name = $this->getProperty('title'); + if (!isset($name)) { + $this->addFieldError('title', $this->modx->lexicon('mxcalendars.err_event_image_req_name')); + } + + $title = $this->getProperty('filepath'); + if (empty($title)) { + $this->addFieldError('filepath', $this->modx->lexicon('mxcalendars.err_event_image_req_filepath')); + } + + $active = $this->getProperty('active'); + if (isset($active) && ((int)$active === 1 || $active === 'on')) { + $this->setProperty('active', 1); + } else { + $this->setProperty('active', 0); + } + + //-- show error messages + if ($this->hasErrors()) { + $errors = ''; + foreach($this->modx->error->getFields() as $error) { + $errors .= $error . '
'; + } + + $this->modx->error->failure($errors); + } + + return parent::beforeSet(); + } +} +return 'EventImagesUpdateProcessor'; diff --git a/core/components/mxcalendars/processors/mgr/images/update.php b/core/components/mxcalendars/processors/mgr/images/update.php deleted file mode 100644 index bd60b96..0000000 --- a/core/components/mxcalendars/processors/mgr/images/update.php +++ /dev/null @@ -1,29 +0,0 @@ -error->failure($modx->lexicon('mxcalendars.mxcalendars_err_ns')); - -//-- Now check to make sure that the calendar item exist and can be updated -$mxcalendar = $modx->getObject('mxCalendarEventImages',$scriptProperties['id']); -if (empty($mxcalendar)) - return $modx->error->failure($modx->lexicon('mxcalendars.mxcalendars_err_nf')); - -if(isset($scriptProperties['active'])) - $scriptProperties['active']=1; -else - $scriptProperties['active']=0; - - -//-- Set mxcalendar fields -$mxcalendar->fromArray($scriptProperties); - -//-- Try to update calendar item -if ($mxcalendar->save() == false) { - return $modx->error->failure($modx->lexicon('mxcalendars.mxcalendars_err_save')); -} - -//-- Return success message if no error was found on update (save) -return $modx->error->success('',$mxcalendar); -?> diff --git a/core/components/mxcalendars/processors/mgr/images/updatefromgrid.class.php b/core/components/mxcalendars/processors/mgr/images/updatefromgrid.class.php new file mode 100644 index 0000000..be0e60b --- /dev/null +++ b/core/components/mxcalendars/processors/mgr/images/updatefromgrid.class.php @@ -0,0 +1,34 @@ +getProperty('data'); + if (empty($data)) { + return $this->modx->lexicon('invalid_data'); + } + $data = $this->modx->fromJSON($data); + //-- Both date and time are always posted back + if (empty($data)) { + return $this->modx->lexicon('invalid_data'); + } + + $data['updatefromgrid'] = 1; + + $this->setProperties($data); + $this->unsetProperty('data'); + + return parent::initialize(); + } + +} +return 'EventImagesUpdateFromGridProcessor'; \ No newline at end of file diff --git a/core/components/mxcalendars/processors/mgr/images/updatefromgrid.php b/core/components/mxcalendars/processors/mgr/images/updatefromgrid.php deleted file mode 100644 index bb8fd4a..0000000 --- a/core/components/mxcalendars/processors/mgr/images/updatefromgrid.php +++ /dev/null @@ -1,29 +0,0 @@ -error->failure($modx->lexicon('mxcalendars.err_ns')); - -if(isset($_DATA['active'])) - $_DATA['active']=1; -else - $_DATA['active']=0; - -//-- Now check to make sure that the category item exist and can be updated -$mxcalendar = $modx->getObject('mxCalendarEventImages',$_DATA['id']); -if (empty($mxcalendar)) - return $modx->error->failure($modx->lexicon('mxcalendars.err_nf')); - - -//-- Set mxcalendar fields -$mxcalendar->fromArray($_DATA); - -//-- Try to update calendar item -if ($mxcalendar->save() == false) { - return $modx->error->failure($modx->lexicon('mxcalendars.err_save')); -} - -//-- Return success message if no error was found on update (save) -return $modx->error->success('',$mxcalendar); -?> diff --git a/core/components/mxcalendars/processors/mgr/mxcHelper.php b/core/components/mxcalendars/processors/mgr/mxcHelper.php index baec21c..4d51fa8 100644 --- a/core/components/mxcalendars/processors/mgr/mxcHelper.php +++ b/core/components/mxcalendars/processors/mgr/mxcHelper.php @@ -1,26 +1,58 @@ -$frequencymode, 'interval'=>$interval, 'frequency'=>$frequency, 'StartDate'=>$startDate, 'EndDate'=>$endDate, 'OnWeedkDay'=>$onwd); - if($debug){ - echo "Date repeat function paramters are:
"; - foreach($theParameter AS $key=>$val) - echo $key.'=>'.$val.'
'.PHP_EOL; + + $theParameter = [ + 'MODE' => $frequencymode, + 'interval' => $interval, + 'frequency' => $frequency, + 'StartDate' => $startDate, + 'EndDate' => $endDate, + 'OnWeedkDay' => $onwd + ]; + if ($debug) { + echo 'Date repeat function paramters are:
'; + foreach ($theParameter AS $key => $val) { + echo $key . '=>' . $val . '
' . PHP_EOL; + } } //-- Check the Date and build the repeat dates @@ -67,172 +107,239 @@ function _getRepeatDates($frequencymode=0, $interval=1, $frequency='1',$startDat if (($timestamp = $startDate) === false) { return false; } else { - SWITCH($frequencymode){ - case 0: //Daily - while (++$x){ - $occurance = mktime(date('H', $startDate), date('i', $startDate), 0, date('m', $startDate) , date('d', $startDate)+($x*$interval), date('y', $startDate)); - if($occurance <= $endDate && $x < $frequency && $startDate < $occurance){ - $ar_Recur[] = $occurance; - if($debug) echo $occurance."< -is less than (jd->".$jd."jdow->".$jdow.") -> ".$endDate.'
'; - } - else{ - if($debug) echo $occurance."||-is eq or greater (jd->".$jd."|jdow->".$jdow.") than -||".$endDate.'
'; - break; + switch ($frequencymode) { + case 0: //Daily + while (++$x) { + $occurance = mktime(date('H', $startDate), date('i', $startDate), 0, date('m', $startDate), + date('d', $startDate) + ($x * $interval), date('y', $startDate)); + if ($occurance <= $endDate && $x < $frequency && $startDate < $occurance) { + $ar_Recur[] = $occurance; + if ($debug) { + echo $occurance . '< -is less than (jd->' . $jd . 'jdow->' . $jdow . ') -> ' . $endDate . '
'; + } + } else { + if ($debug) { + echo $occurance . '||-is eq or greater (jd->' . $jd . '|jdow->' . $jdow . ') than -||' . $endDate . '
'; + } + break; + } } - } - break; - case 2: //Monthly - $occurance = $startDate; - - $modx->log(modX::LOG_LEVEL_ERROR,'[mxHelper] mxFormBuilder _getRpeatDate:[options]
'.$options); - - $options = !empty($options) ? json_decode($options, true) : ''; - while (++$x){ - - if(!empty($options)){ - - SWITCH($options['type']){ - case 'dow': - // Day of week is simply the same day of a week - $occurance = strtotime($options['week']." ".strftime('%A', $occurance)." of next month", $occurance); - $occurance = mktime(date('H', $startDate), date('i', $startDate), 0, date('m', $occurance) , date('d', $occurance), date('y', $occurance)); - break; - case 'dom': - $occurance = strtotime("next month", $occurance); - $occurance = mktime(date('H', $startDate), date('i', $startDate), 0, date('m', $occurance) , date('d', $occurance), date('y', $occurance)); - break; - default: - $occurance = mktime(date('H', $startDate), date('i', $startDate), 0, date('m', $startDate)+($x*$interval) , date('d', $startDate), date('y', $startDate)); - break; - } - - $modx->log(modX::LOG_LEVEL_ERROR, '[mxHelper] _getRpeatDate: Option['.$options['type'].'] :: Occurance['.$x.']=>'.date('Y-m-d h:i a', $occurance) ); - - } else { - $occurance = mktime(date('H', $startDate), date('i', $startDate), 0, date('m', $startDate)+($x*$interval) , date('d', $startDate), date('y', $startDate)); - } - - if($occurance <= $endDate && $x < $frequency && $startDate < $occurance){ + break; + case 2: //Monthly + $occurance = $startDate; + + $modx->log(modX::LOG_LEVEL_ERROR, '[mxHelper] mxFormBuilder _getRpeatDate:[options]
' . $options); + + $options = !empty($options) ? json_decode($options, true) : ''; + while (++$x) { + + if (!empty($options)) { + + SWITCH ($options['type']) { + case 'dow': + // Day of week is simply the same day of a week + $occurance = strtotime($options['week'] . ' ' . strftime('%A', $occurance) . ' of next month', $occurance); + $occurance = mktime( + date('H', $startDate), + date('i', $startDate), + 0, + date('m', $occurance), + date('d', $occurance), + date('y', $occurance) + ); + break; + case 'dom': + $occurance = strtotime('next month', $occurance); + $occurance = mktime( + date('H', $startDate), + date('i', $startDate), + 0, + date('m', $occurance), + date('d', $occurance), + date('y', $occurance) + ); + break; + default: + $occurance = mktime( + date('H', $startDate), + date('i', $startDate), + 0, + date('m', $startDate) + ($x * $interval), + date('d', $startDate), + date('y', $startDate)); + break; + } + + $modx->log(modX::LOG_LEVEL_ERROR, + '[mxHelper] _getRpeatDate: Option[' . $options['type'] . '] :: Occurance[' . $x . ']=>' . date('Y-m-d h:i a', + $occurance)); + + } else { + $occurance = mktime( + date('H', $startDate), + date('i', $startDate), + 0, + date('m', $startDate) + ($x * $interval), + date('d', $startDate), + date('y', $startDate) + ); + } + + $ar_Recur[] = $occurance; - if($debug) echo $occurance."< -is less than -> ".$endDate.'
'; - } - else{ - if($debug) echo $occurance."||-is eq or greater than -||".$endDate.'
'; + if ($occurance <= $endDate && $x < $frequency && $startDate < $occurance) { + $ar_Recur[] = $occurance; + if ($debug) { + echo $occurance . '< -is less than -> ' . $endDate . '
'; + } + } else { + if ($debug) { + echo $occurance . '||-is eq or greater than -||' . $endDate . '
'; + } break; + } + } + break; + case 1: //Weekly + $valid = true; + + //-- Set new weekday values to fix mismatch in numbering of weekdays #108 #111 #116 + if (is_array($onwd)) { + $adjOnWd = []; + foreach (array_filter($onwd) as $dof) { + $adjOnWd[] = $dof + 1; + } + $onwd = $adjOnWd; } - } - break; - case 1: //Weekly - $valid = true; - - - //-- Set new weekday values to fix mismatch in numbering of weekdays #108 #111 #116 - if(is_array($onwd)){ - $adjOnWd = array(); - foreach(array_filter($onwd) as $dof){ - $adjOnWd[] = $dof + 1; + + //-- Get the first repeat Day of Week if the same as start date's Day of Week + $curWeek = $startWeek = strftime('%W', $startDate); + $occurance = strftime('%Y-%m-%d %H:%M:%S', $startDate); + $originalTime = strftime(' %H:%M:%S', $startDate); + $nextWeek = strftime('%Y-%m-%d %H:%M:%S', strtotime('next week', $startDate)); + if ($debug) { + echo 'Current Week of the Start Date: ' . $curWeek . '
'; } - $onwd = $adjOnWd; - } - - - //-- Get the first repeat Day of Week if the same as start date's Day of Week - $curWeek = $startWeek = strftime('%W',$startDate); - $occurance = strftime('%Y-%m-%d %H:%M:%S',$startDate); - $originalTime = strftime(' %H:%M:%S', $startDate); - $nextWeek = strftime('%Y-%m-%d %H:%M:%S', strtotime('next week', $startDate)); - if($debug) echo 'Current Week of the Start Date: '.$curWeek.'
'; - //-- Loop through days until the end of current week - while($curWeek == $startWeek){ - $occurance = strftime('%Y-%m-%d %H:%M:%S',strtotime('next day', strtotime($occurance))); - $curWeek= strftime('%W',strtotime($occurance)); + //-- Loop through days until the end of current week + while ($curWeek == $startWeek) { + $occurance = strftime('%Y-%m-%d %H:%M:%S', strtotime('next day', strtotime($occurance))); + $curWeek = strftime('%W', strtotime($occurance)); //-- Get occurance day of week int - $thisDOW = strftime('%w',strtotime("next day",strtotime($occurance))); + $thisDOW = strftime('%w', strtotime('next day', strtotime($occurance))); //-- Get the valid date formated of occurance - $occDate = strftime('%Y-%m-%d', strtotime("next day",strtotime($occurance))).$originalTime; + $occDate = strftime('%Y-%m-%d', strtotime('next day', strtotime($occurance))) . $originalTime; //-- Check if the date is one of the assigned and less than the end date - if(in_array($thisDOW, $onwd) && $curWeek == $startWeek && strtotime($occDate) < strtotime($nextWeek) && strtotime($occDate) > strtotime($startDate)){ - if($debug) echo $occDate." MATCH on $thisDOW (start week) :: CurWk=$curWeek :: StartWk=$startWeek :: NextWk=$nextWeek
"; - $ar_Recur[] = ($occType == 'UNIX' ? strtotime($occDate) : $occDate); + if (in_array($thisDOW, $onwd) && + $curWeek == $startWeek && + strtotime($occDate) < strtotime($nextWeek) && + strtotime($occDate) > strtotime($startDate) + ) { + if ($debug) { + echo $occDate . ' MATCH on $thisDOW (start week) :: CurWk=$curWeek :: StartWk=$startWeek :: NextWk=$nextWeek
'; + } + $ar_Recur[] = ($occType == 'UNIX' ? strtotime($occDate) : $occDate); } else { - if($debug && $curWeek == $startWeek && strtotime($occDate) < strtotime($nextWeek)) - echo $occDate." (start week)
"; + if ($debug && $curWeek == $startWeek && strtotime($occDate) < strtotime($nextWeek)) { + echo $occDate . ' (start week)
'; + } } - } - - $startDate = date('Y-m-d H:i:s', strtotime(' last mon ',strtotime($occurance))); - if($debug) echo 'Start date MONDAY of that week: : '.$startDate.'
'; - $startDate = date('Y-m-d H:i:s', strtotime(' + '.($interval).' week',strtotime($startDate))); - if($debug) - echo 'Next Valid Repeat Week Start Date: : '.$startDate.'
'. - 'Modified start: '.$startDate.' with adjusted interval: '.($interval).'
'. - 'Frequency: '.$frequency.' with the max repeat of: '.($frequency*7).'
'; - - //-- Created a new loop to limit the possibility of almost endless loop - $newDate = strtotime($startDate); - $x=1; - while($newDate <= $endDate){ - if($debug) echo "x={$x}
"; - $occurance = $newDate; //date('Y-m-d H:i:s', c); - - $lastweek=sprintf("%02d", (strftime('%W',$newDate) )); - if($debug) echo 'Week of: '.$lastweek."
"; - $year = strftime('%Y',$occurance); - for ($i=0;$i<=6;$i++){ + } - //-- Get occurance day of week int - $thisDOW = strftime('%w',strtotime("+{$i} day",$occurance)); + $startDate = date('Y-m-d H:i:s', strtotime(' last mon ', strtotime($occurance))); + if ($debug) { + echo 'Start date MONDAY of that week: : ' . $startDate . '
'; + } + $startDate = date('Y-m-d H:i:s', strtotime(' + ' . ($interval) . ' week', strtotime($startDate))); + if ($debug) { + echo 'Next Valid Repeat Week Start Date: : ' . $startDate . '
' . + 'Modified start: ' . $startDate . ' with adjusted interval: ' . ($interval) . '
' . + 'Frequency: ' . $frequency . ' with the max repeat of: ' . ($frequency * 7) . '
'; + } - //-- Get the valid date formated of occurance - $occDate = strftime('%Y-%m-%d', strtotime("+{$i} day",$occurance)).$originalTime; + //-- Created a new loop to limit the possibility of almost endless loop + $newDate = strtotime($startDate); + $x = 1; + while ($newDate <= $endDate) { + if ($debug) { + echo "x={$x}
"; + } + $occurance = $newDate; //date('Y-m-d H:i:s', c); - //-- Check if the date is one of the assigned and less than the end date - if(in_array($thisDOW, $onwd) && strtotime($occDate) <= $endDate){ - if($debug) echo $occDate." MATCH on $thisDOW
"; - $ar_Recur[] = ($occType == 'UNIX' ? strtotime($occDate) : $occDate); - } else { - if($debug) echo $occDate."
"; + $lastweek = sprintf('%02d', (strftime('%W', $newDate))); + if ($debug) { + echo 'Week of: ' . $lastweek . '
'; } + $year = strftime('%Y', $occurance); + for ($i = 0; $i <= 6; $i++) { + + //-- Get occurance day of week int + $thisDOW = strftime('%w', strtotime("+{$i} day", $occurance)); + + //-- Get the valid date formated of occurance + $occDate = strftime('%Y-%m-%d', strtotime("+{$i} day", $occurance)) . $originalTime; - //-- If the date is past the end date end the loop - if(strtotime($occDate) >= $endDate){ - if($debug) echo "\t".strtotime($occDate) .' is greater than '. $endDate."
"; - $valid = false; //-- End the loop + //-- Check if the date is one of the assigned and less than the end date + if (in_array($thisDOW, $onwd) && strtotime($occDate) <= $endDate) { + if ($debug) { + echo $occDate . " MATCH on $thisDOW
"; + } + $ar_Recur[] = ($occType == 'UNIX' ? strtotime($occDate) : $occDate); + } else { + if ($debug) { + echo $occDate . '
'; + } + } + + //-- If the date is past the end date end the loop + if (strtotime($occDate) >= $endDate) { + if ($debug) { + echo '\t' . strtotime($occDate) . ' is greater than ' . $endDate . '
'; + } + $valid = false; //-- End the loop + break; + } + //-- Reset the date for while loop validation + $newDate = strtotime(' + ' . $interval . ' weeks', $occurance); + } + $x++; + if (!$valid || $x > $frequency) { break; } - //-- Reset the date for while loop validation - $newDate = strtotime(' + '.$interval.' weeks',$occurance); } - $x++; - if(!$valid || $x > $frequency) break; - } - if($debug) echo ''.count($ar_Recur).' total matches dates added.'; - break; - case 3: //Yearly - while (++$x){ - $occurance = mktime(date('H', $startDate), date('i', $startDate), 0, date('m', $startDate) , date('d', $startDate), date('y', $startDate)+($x*$interval)); - if($occurance <= $endDate && $x < $frequency && $startDate < $occurance){ - $ar_Recur[] = $occurance; - if($debug) echo $occurance."< -is less than -> ".$endDate.'
'; + if ($debug) { + echo '' . count($ar_Recur) . ' total matches dates added.'; } - else{ - if($debug) echo $occurance."||-is eq or greater than -||".$endDate.'
'; - break; + break; + case 3: //Yearly + while (++$x) { + $occurance = mktime(date('H', $startDate), date('i', $startDate), 0, date('m', $startDate), + date('d', $startDate), date('y', $startDate) + ($x * $interval)); + if ($occurance <= $endDate && $x < $frequency && $startDate < $occurance) { + $ar_Recur[] = $occurance; + if ($debug) { + echo $occurance . '< -is less than -> ' . $endDate . '
'; + } + } else { + if ($debug) { + echo $occurance . '||-is eq or greater than -||' . $endDate . '
'; + } + break; + } } - } - break; + break; } //-- Display the results to validate - if($debug){ - echo "THE OCC DATES:
"; + if ($debug) { + echo 'THE OCC DATES:
'; print_r($ar_Recur); } - if(isset($curTZ)) date_default_timezone_set($curTZ); + if (isset($curTZ)) { + date_default_timezone_set($curTZ); + } + return implode(',', $ar_Recur); } -} - -?> \ No newline at end of file +} \ No newline at end of file diff --git a/core/components/mxcalendars/processors/mgr/videos/create.class.php b/core/components/mxcalendars/processors/mgr/videos/create.class.php new file mode 100644 index 0000000..92846f0 --- /dev/null +++ b/core/components/mxcalendars/processors/mgr/videos/create.class.php @@ -0,0 +1,64 @@ +getProperty('title'); + if (empty($title)) { + $this->addFieldError('title', $this->modx->lexicon('mxcalendars.err_event_video_req_name')); + } + + $video = $this->getProperty('video'); + if (empty($video)) { + $this->addFieldError('video', $this->modx->lexicon('mxcalendars.err_event_video_req_filepath')); + } + + $active = $this->getProperty('active'); + if (isset($active) && ((int)$active === 1 || $active === 'on')) { + $this->setProperty('active', 1); + } else { + $this->setProperty('active', 0); + } + + //-- show error messages + if ($this->hasErrors()) { + $errors = ''; + foreach($this->modx->error->getFields() as $error) { + $errors .= $error . '
'; + } + + $this->modx->error->failure($errors); + } + + return parent::beforeSet(); + } +} +return 'EventVideosCreateProcessor'; diff --git a/core/components/mxcalendars/processors/mgr/videos/create.php b/core/components/mxcalendars/processors/mgr/videos/create.php deleted file mode 100644 index 38802eb..0000000 --- a/core/components/mxcalendars/processors/mgr/videos/create.php +++ /dev/null @@ -1,20 +0,0 @@ -newObject('mxCalendarEventVideos'); -$mxcalendar->fromArray($scriptProperties); - -//-- Try to save the new record -if ($mxcalendar->save() == false) { - return $modx->error->failure($modx->lexicon('mxcalendars.err_save')); -} - -//-- If no errors return success -return $modx->error->success('',$mxcalendar); - -?> diff --git a/core/components/mxcalendars/processors/mgr/videos/getlist.class.php b/core/components/mxcalendars/processors/mgr/videos/getlist.class.php new file mode 100644 index 0000000..54275dd --- /dev/null +++ b/core/components/mxcalendars/processors/mgr/videos/getlist.class.php @@ -0,0 +1,77 @@ +getProperty('limit')); + $start = $this->getProperty('start'); + $limit = $this->getProperty('limit'); + $sort = $this->getProperty('sort'); + $dir = $this->getProperty('dir'); + $query = $this->getProperty('query'); + + /* build query */ + $c->select([ + 'mxCalendarEventVideos.*', + ]); + if (!empty($query)) { + $c->where(array( + 'title:LIKE' => '%' . $query . '%', + 'OR:description:LIKE' => '%' . $query . '%', + )); + } + + $c->sortby($sort, $dir); + if ($isLimit) { + $c->limit($limit, $start); + } + + return $c; + } +} +return 'EventVideosGetListProcessor'; \ No newline at end of file diff --git a/core/components/mxcalendars/processors/mgr/videos/getlist.php b/core/components/mxcalendars/processors/mgr/videos/getlist.php deleted file mode 100644 index 24e6de0..0000000 --- a/core/components/mxcalendars/processors/mgr/videos/getlist.php +++ /dev/null @@ -1,35 +0,0 @@ -getOption('eventid',$scriptProperties,0); -$isLimit = !empty($scriptProperties['limit']); -$start = $modx->getOption('start',$scriptProperties,0); -$limit = 3;//$modx->getOption('limit',$scriptProperties,5); -$sort = $modx->getOption('sort',$scriptProperties,'title'); -$dir = $modx->getOption('dir',$scriptProperties,'ASC'); -$query = $modx->getOption('query',$scriptProperties,''); - -/* build query */ -$c = $modx->newQuery('mxCalendarEventVideos'); -$c->where(array('event_id'=>$eventId)); -if (!empty($query)) { - $c->where(array( - 'title:LIKE' => '%'.$query.'%' - ,'OR:description:LIKE' => '%'.$query.'%' - )); -} - - - -$count = $modx->getCount('mxCalendarEventVideos',$c); -$c->sortby($sort,$dir); -$c->limit($limit,$start); -$mxcalendarsVideos = $modx->getIterator('mxCalendarEventVideos', $c); - -/* iterate */ -$list = array(); -foreach ($mxcalendarsVideos as $mxc) { - $mxcArray = $mxc->toArray(); - $list[]= $mxcArray; -} -return $this->outputArray($list,$count); - -?> diff --git a/core/components/mxcalendars/processors/mgr/videos/remove.class.php b/core/components/mxcalendars/processors/mgr/videos/remove.class.php new file mode 100644 index 0000000..99ad1a3 --- /dev/null +++ b/core/components/mxcalendars/processors/mgr/videos/remove.class.php @@ -0,0 +1,32 @@ +error->failure($modx->lexicon('mxcalendars.mxcalendars_err_ns')); -$mxcalendar = $modx->getObject('mxCalendarEventVideos',$scriptProperties['id']); -if (empty($mxcalendar)) return $modx->error->failure($modx->lexicon('mxcalendars.mxcalendars_err_nf')); - -//-- Remove the calendar record -if ($mxcalendar->remove() == false) { - return $modx->error->failure($modx->lexicon('mxcalendars.mxcalendars_err_remove')); -} - -//-- If no errors return success -return $modx->error->success('',$mxcalendar); - -?> diff --git a/core/components/mxcalendars/processors/mgr/videos/update.class.php b/core/components/mxcalendars/processors/mgr/videos/update.class.php new file mode 100644 index 0000000..3306009 --- /dev/null +++ b/core/components/mxcalendars/processors/mgr/videos/update.class.php @@ -0,0 +1,77 @@ +getProperty('id'); + if (empty($id)) { + $this->addFieldError('id', 'ID Not found ' . $this->modx->lexicon('mxcalendars.mxcalendars_err_ns')); + } + //-- Now check to make sure that the calendar item exist and can be updated + $mxcalendar = $this->modx->getObject('mxCalendarEventVideos', $id); + if (empty($mxcalendar)) { + $this->addFieldError('id', 'ID Not found ' . $this->modx->lexicon('mxcalendars.mxcalendars_err_nf')); + } + + //-- Validation for the Name field + $name = $this->getProperty('title'); + if (!isset($name)) { + $this->addFieldError('title', $this->modx->lexicon('mxcalendars.err_event_video_req_name')); + } + + $title = $this->getProperty('video'); + if (empty($title)) { + $this->addFieldError('video', $this->modx->lexicon('mxcalendars.err_event_video_req_video')); + } + + $active = $this->getProperty('active'); + if (isset($active) && ((int)$active === 1 || $active === 'on')) { + $this->setProperty('active', 1); + } else { + $this->setProperty('active', 0); + } + + //-- show error messages + if ($this->hasErrors()) { + $errors = ''; + foreach($this->modx->error->getFields() as $error) { + $errors .= $error . '
'; + } + + $this->modx->error->failure($errors); + } + + return parent::beforeSet(); + } +} +return 'EventVideosUpdateProcessor'; diff --git a/core/components/mxcalendars/processors/mgr/videos/update.php b/core/components/mxcalendars/processors/mgr/videos/update.php deleted file mode 100644 index f31559c..0000000 --- a/core/components/mxcalendars/processors/mgr/videos/update.php +++ /dev/null @@ -1,29 +0,0 @@ -error->failure($modx->lexicon('mxcalendars.mxcalendars_err_ns')); - -//-- Now check to make sure that the calendar item exist and can be updated -$mxcalendar = $modx->getObject('mxCalendarEventVideos',$scriptProperties['id']); -if (empty($mxcalendar)) - return $modx->error->failure($modx->lexicon('mxcalendars.mxcalendars_err_nf')); - -if(isset($scriptProperties['active'])) - $scriptProperties['active']=1; -else - $scriptProperties['active']=0; - - -//-- Set mxcalendar fields -$mxcalendar->fromArray($scriptProperties); - -//-- Try to update calendar item -if ($mxcalendar->save() == false) { - return $modx->error->failure($modx->lexicon('mxcalendars.mxcalendars_err_save')); -} - -//-- Return success message if no error was found on update (save) -return $modx->error->success('',$mxcalendar); -?> diff --git a/core/components/mxcalendars/processors/mgr/videos/updatefromgrid.class.php b/core/components/mxcalendars/processors/mgr/videos/updatefromgrid.class.php new file mode 100644 index 0000000..0d14bc6 --- /dev/null +++ b/core/components/mxcalendars/processors/mgr/videos/updatefromgrid.class.php @@ -0,0 +1,34 @@ +getProperty('data'); + if (empty($data)) { + return $this->modx->lexicon('invalid_data'); + } + $data = $this->modx->fromJSON($data); + //-- Both date and time are always posted back + if (empty($data)) { + return $this->modx->lexicon('invalid_data'); + } + + $data['updatefromgrid'] = 1; + + $this->setProperties($data); + $this->unsetProperty('data'); + + return parent::initialize(); + } + +} +return 'EventVideosUpdateFromGridProcessor'; \ No newline at end of file diff --git a/core/components/mxcalendars/processors/mgr/videos/updatefromgrid.php b/core/components/mxcalendars/processors/mgr/videos/updatefromgrid.php deleted file mode 100644 index 62029ba..0000000 --- a/core/components/mxcalendars/processors/mgr/videos/updatefromgrid.php +++ /dev/null @@ -1,29 +0,0 @@ -error->failure($modx->lexicon('mxcalendars.err_ns')); - -if(isset($_DATA['active'])) - $_DATA['active']=1; -else - $_DATA['active']=0; - -//-- Now check to make sure that the category item exist and can be updated -$mxcalendar = $modx->getObject('mxCalendarEventVideos',$_DATA['id']); -if (empty($mxcalendar)) - return $modx->error->failure($modx->lexicon('mxcalendars.err_nf')); - - -//-- Set mxcalendar fields -$mxcalendar->fromArray($_DATA); - -//-- Try to update calendar item -if ($mxcalendar->save() == false) { - return $modx->error->failure($modx->lexicon('mxcalendars.err_save')); -} - -//-- Return success message if no error was found on update (save) -return $modx->error->success('',$mxcalendar); -?> diff --git a/core/components/mxcalendars/templates/home.tpl b/core/components/mxcalendars/templates/home.tpl new file mode 100644 index 0000000..ef0d68e --- /dev/null +++ b/core/components/mxcalendars/templates/home.tpl @@ -0,0 +1 @@ +
{$onRichTextEditorInit} \ No newline at end of file