diff --git a/js/app/views/CatalogUI.js b/js/app/views/CatalogUI.js index 5e4bd2e..a22d18a 100644 --- a/js/app/views/CatalogUI.js +++ b/js/app/views/CatalogUI.js @@ -195,11 +195,11 @@ Ext.define('amdaUI.CatalogUI', { this.status = null; if (this.object.get('fromPlugin')) - { + { if (this.object.get('objFormat') && this.object.get('objFormat') != '') { //From uploaded file - //AmdaAction.initTTCacheFromUploadedFile(this.object.get('objName'), this.object.get('objFormat'), this.onAfterInit, this); + AmdaAction.initTTCacheFromUploadedFile(this.object.get('objName'), this.object.get('objFormat'), this.isCatalog, this.onAfterInit, this); } else { diff --git a/js/app/views/TimeTableUI.js b/js/app/views/TimeTableUI.js index 419c335..08009c2 100755 --- a/js/app/views/TimeTableUI.js +++ b/js/app/views/TimeTableUI.js @@ -47,7 +47,8 @@ Ext.define('amdaUI.TimeTableUI', { this.loadObject(); // show the default duration column - this.TTGrid.headerCt.getGridColumns() + this.TTGrid.headerCt.getGridColumns(); + Ext.Array.each(this.TTGrid.headerCt.getGridColumns(), function(item,index,all){ // if item is the default duration column if ( item.id == amdaUI.TimeTableUI.COL_TO_HIDE+'2' ) { diff --git a/js/app/views/UploadPanelUI.js b/js/app/views/UploadPanelUI.js index a3167b2..a15662f 100644 --- a/js/app/views/UploadPanelUI.js +++ b/js/app/views/UploadPanelUI.js @@ -2,527 +2,594 @@ * Project : AMDA-NG * Name : UploadUI.js * @class amdaUI.UploadUI - * @extends Ext.panel.Panel + * @extends Ext.form.Panel * @brief Upload Panel UI definition (View) * @author Elena * @version $Id: UploadPanelUI.js 2831 2015-03-26 10:33:42Z elena $ */ Ext.define('amdaUI.UploadPanelUI', { - extend: 'Ext.form.Panel', - alias: 'widget.panelUpload', - - requires : [ - 'amdaUI.RemoteSearchPlugin' - ], + extend: 'Ext.form.Panel', + alias: 'widget.panelUpload', + + requires : [ + 'amdaUI.RemoteSearchPlugin' + ], - isFile : true, - tmpNode : null, - - constructor: function(config) { - this.init(config); - this.callParent(arguments); - }, + isFile : true, + isTimeTable : false, + tmpNode : null, + + constructor: function(config) + { + this.init(config); + this.callParent(arguments); + }, - /* - * create MyData linked node and edit in module MyData - * update myDataParams info if needed - */ - getObjectCallback : function(result,remoteEvent) - { - var t = remoteEvent.getTransaction(); - if (result && !result.error) { - // set parameter into node - var me = this; - myDesktopApp.getLoadedModule(this.tmpNode.get('moduleId'), true, function (module) { - // myData - if (me.tmpNode.get('nodeType') == amdaModel.MyDataParamNode.nodeType) { - var linkedFile = Ext.create('amdaModel.MyDataNode', {leaf : true, text : me.tmpNode.get('text')}); - - linkedFile.create(result.mask, result.description, result.maskDesc); - linkedFile.updateMyDataParam(result.mask,result.maskDesc); - - if (!linkedFile.get('id')) - linkedFile.set('id',me.tmpNode.get('text')); - - var paramObj = Ext.create(linkedFile.get('objectDataModel'), result); - linkedFile.set('object',paramObj); - me.tmpNode.set('fileObject',paramObj); - } - else { - // Time Table - var paramObj = Ext.create(me.tmpNode.get('objectDataModel'), result); - - paramObj.set('fromPlugin',true); - if (result.intervals) { - paramObj.set('intervals',result.intervals); - paramObj.set('nbIntervals',result.intervals.length); - } - me.tmpNode.set('object',paramObj); - } - if (module) - { - module.setLinkedNode(me.tmpNode); - module.linkedNode.editInModule(); - } - }); - } - else { - // EXCEPTION : parameter not found ! - myDesktopApp.errorMsg(t.action + "." + t.method + " : No parameter '" - +this.tmpNode.get('text')+"' found!"); - } - loadMask.hide(); - }, + /* + * create MyData linked node and edit in module MyData + * update myDataParams info if needed + */ + getObjectCallback : function(result,remoteEvent) + { + var t = remoteEvent.getTransaction(); + if (result && !result.error) + { + // set parameter into node + var me = this; + myDesktopApp.getLoadedModule(this.tmpNode.get('moduleId'), true, function (module){ + // myData + if (me.tmpNode.get('nodeType') == amdaModel.MyDataParamNode.nodeType) + { + var linkedFile = Ext.create('amdaModel.MyDataNode', {leaf : true, text : me.tmpNode.get('text')}); + + linkedFile.create(result.mask, result.description, result.maskDesc); + linkedFile.updateMyDataParam(result.mask,result.maskDesc); + + if (!linkedFile.get('id')) + linkedFile.set('id',me.tmpNode.get('text')); + + var paramObj = Ext.create(linkedFile.get('objectDataModel'), result); + linkedFile.set('object',paramObj); + me.tmpNode.set('fileObject',paramObj); + } + else + { + // Time Table or Catalog + var paramObj = Ext.create(me.tmpNode.get('objectDataModel'), result); + + paramObj.set('fromPlugin',true); + if (result.intervals) + { + paramObj.set('intervals',result.intervals); + paramObj.set('nbIntervals',result.intervals.length); + } + me.tmpNode.set('object',paramObj); + } + if (module) + { + module.setLinkedNode(me.tmpNode); + module.linkedNode.editInModule(); + } + }); + } + else + { + // EXCEPTION : parameter not found ! + myDesktopApp.errorMsg(t.action + "." + t.method + " : No parameter '"+this.tmpNode.get('text')+"' found!"); + } + loadMask.hide(); + }, - /* - * form validation - * TODO markInvalid()? - */ - validate : function() - { - var values = this.getForm().getValues(); +/* +* form validation +* TODO markInvalid()? +*/ + validate : function() + { + var values = this.getForm().getValues(); - if (values['filesrc'] == 'LOCAL') { - var locFile = this.isFile ? this.getForm().findField('localFileName').getValue() : - this.getForm().findField('localTTName').getValue(); - - if (!locFile) { - myDesktopApp.warningMsg("Select File to Upload"); - return false; - } - } - else { - if (!values['remoteFile'] && !values['remoteTT']) { - myDesktopApp.warningMsg("Select File to Upload"); - return false; - } - } - return true; - }, + if (values['filesrc'] == 'LOCAL') + { + if (this.isFile) var locFile = this.getForm().findField('localFileName').getValue(); + else if (this.isTimeTable) var locFile = this.getForm().findField('localTTName').getValue(); + else var locFile = this.getForm().findField('localCatName').getValue(); + + if (!locFile) + { + myDesktopApp.warningMsg("Select File to Upload"); + return false; + } + } + else + { + if (!values['remoteFile'] && !values['remoteTT'] && !values['remoteCat']) + { + myDesktopApp.warningMsg("Select File to Upload"); + return false; + } + } + return true; + }, - //TODO proper parsing - updateFormat: function(value) - { - var arrayOfStr = value.split('.'); - //TODO use down method? - if (this.isFile) { - var radios = Ext.getCmp('filefrmt'); - var user_format_obj = radios.getValue(); - var user_format = user_format_obj.filefrmt; - } - else { - var radios = Ext.getCmp('ttfrmt'); - var user_format_obj = radios.getValue(); - var user_format = user_format_obj.ttfrmt; - } - - var auto_format = user_format; - - // auto define format in some special cases - //TODO name without extention => ASCII? - if (arrayOfStr.length == 1) auto_format = 'ASCII'; - else { - var suffix = arrayOfStr[arrayOfStr.length - 1].toLowerCase(); - if (suffix == 'gz') - suffix = arrayOfStr[arrayOfStr.length - 2].toLowerCase() + '.gz'; + //TODO proper parsing + updateFormat: function(value) + { + var arrayOfStr = value.split('.'); + //TODO use down method? + if (this.isFile) + { + var radios = Ext.getCmp('filefrmt'); + var user_format_obj = radios.getValue(); + var user_format = user_format_obj.filefrmt; + } + else if (this.TimeTable) + { + var radios = Ext.getCmp('ttfrmt'); + var user_format_obj = radios.getValue(); + var user_format = user_format_obj.ttfrmt; + } + else + { + var radios = Ext.getCmp('catfrmt'); + var user_format_obj = radios.getValue(); + var user_format = user_format_obj.catfrmt; + } + + var auto_format = user_format; + + // auto define format in some special cases + //TODO name without extention => ASCII? + if (arrayOfStr.length == 1) auto_format = 'ASCII'; + else + { + var suffix = arrayOfStr[arrayOfStr.length - 1].toLowerCase(); + if (suffix == 'gz') + suffix = arrayOfStr[arrayOfStr.length - 2].toLowerCase() + '.gz'; - switch (suffix) - { - case 'cdf' : auto_format = 'CDF'; break; - case 'cef.gz' : - case 'cef' : auto_format = 'CEF'; break; - case 'xml' : auto_format = 'VOT'; - case 'vot' : auto_format = 'VOT'; break; - case 'nc' : auto_format = 'NC'; break; - case 'asc' : - case 'txt' : - default : auto_format = 'ASCII'; - } - } + switch (suffix) + { + case 'cdf' : auto_format = 'CDF'; break; + case 'cef.gz' : + case 'cef' : auto_format = 'CEF'; break; + case 'xml' : auto_format = 'VOT'; + case 'vot' : auto_format = 'VOT'; break; + case 'nc' : auto_format = 'NC'; break; + case 'asc' : + case 'txt' : + default : auto_format = 'ASCII'; + } + } + // set auto format : case when format was not set by user before + if (this.isFile && user_format !== auto_format) { + user_format_obj.filefrmt = auto_format; + } else if (this.isTimeTable && user_format !== auto_format) { + user_format_obj.ttfrmt = auto_format; + } else if (!this.File && !this.TimeTable && user_format !== auto_format) { + user_format_obj.catfrmt = auto_format; + } + + radios.setValue(user_format_obj); + }, - // set auto format : case when format was not set by user before - if (this.isFile && user_format !== auto_format) { - user_format_obj.filefrmt = auto_format; - } else if (!this.isFile && user_format !== auto_format) { - user_format_obj.ttfrmt = auto_format; - } - radios.setValue(user_format_obj); - }, - - /* - * - */ - forceUpload : function (url,format) - { - this.getForm().findField('filesrc').setValue('URL'); - - switch (format) - { - case 'votable' : - this.getForm().findField('filefrmt').setValue('VOT'); - break; - case 'cdf' : - this.getForm().findField('filefrmt').setValue('CDF'); - break; - default : - //ToDo Error - unknown format - return; - } - this.getForm().findField('remoteFile').setValue(url); - - this.postUpload(); - }, + /* + * + */ + forceUpload : function (url,format) + { + this.getForm().findField('filesrc').setValue('URL'); + + switch (format) + { + case 'votable' : + this.getForm().findField('filefrmt').setValue('VOT'); + break; + case 'cdf' : + this.getForm().findField('filefrmt').setValue('CDF'); + break; + default : + //ToDo Error - unknown format + return; + } + this.getForm().findField('remoteFile').setValue(url); + + this.postUpload(); + }, - /* - * - */ - postUpload : function() - { - // 'global' form containing 'partial' forms - var form = this.getForm(); - - // special validation - if(this.validate()){ - form.submit({ - scope: this, - url: 'php/uploadFile.php', - waitMsg: 'Uploading your file...', - success: function(form, o){ - this.tmpNode = Ext.create(this.nodeType,{leaf : true, text : o.result.file}); - loadMask.show(); - AmdaAction.getUploadedObject(o.result.file, o.result.format, this.tmpNode.get('nodeType'), this.getObjectCallback, this); - }, - failure: function(form, o) { - loadMask.hide(); - myDesktopApp.errorMsg('Error '+o.result.error); - } - }); - } - }, + /* + * + */ + postUpload : function() + { + // 'global' form containing 'partial' forms + var form = this.getForm(); + + // special validation + if(this.validate()) + { + form.submit({ + scope: this, + url: 'php/uploadFile.php', + waitMsg: 'Uploading your file...', + success: function(form, o) + { + this.tmpNode = Ext.create(this.nodeType,{leaf : true, text : o.result.file}); + loadMask.show(); + AmdaAction.getUploadedObject(o.result.file, o.result.format, this.tmpNode.get('nodeType'), this.getObjectCallback, this); + }, + failure: function(form, o) + { + loadMask.hide(); + myDesktopApp.errorMsg('Error '+o.result.error); + } + }); + } + }, - /* - * panel config - */ - init : function(config) - { - this.isFile = config.panelType == 'file'? true : false; - - // file/time table settings - if (this.isFile) { - var title = 'Upload File'; - var items = [ - { boxLabel: 'ASCII', name: 'filefrmt', inputValue: 'ASCII', checked: true, - listeners: { - change: function (cb, nv, ov) { - if (nv) Ext.getCmp('tf').show(); - else Ext.getCmp('tf').hide(); - } - } - }, - { boxLabel: 'netCDF <img amda_clicktip="ncTimeFormat" style="vertical-align:bottom" src="js/resources/images/16x16/info_mini.png"', name: 'filefrmt', inputValue: 'NC' }, - { boxLabel: 'CDF <img amda_clicktip="cdfTimeFormat" style="vertical-align:bottom" src="js/resources/images/16x16/info_mini.png"', name: 'filefrmt', inputValue: 'CDF' }, - // { boxLabel: 'CEF[GZ]', name: 'filefrmt', inputValue: 'CEF' }, - { boxLabel: 'VOTable', name: 'filefrmt', inputValue: 'VOT' } - ]; - var timeFormatId = 'tf'; - this.formatId = 'nsf'; - this.localUploadId = 'form-uploadfile'; - var localUploadName ='localFileName'; - var remoteUploadName ='remoteFile'; - this.remoteUploadId = 'form-uploadurl'; - this.nodeType = 'amdaModel.MyDataParamNode'; - //TODO load XML - var store = Ext.create('Ext.data.Store', { - fields: ['value', 'name'], - data : [ - {"value":"ftp://cdaweb.gsfc.nasa.gov/pub/data/", "name":"CDAWEB/FTP"}, - {"value":"ftp://ftp.ngdc.noaa.gov/STP/SOLAR_DATA/", "name":"Solar Data"} - ] - }); - } - else { - - var title = 'Upload Time Table'; - var items = [ - {boxLabel: 'ASCII', name: 'ttfrmt', inputValue: 'ASCII', checked: true, - listeners: { - change: function (cb, nv, ov) { - if (nv) Ext.getCmp('tf_tt').show(); - else Ext.getCmp('tf_tt').hide(); - } - } - }, - {boxLabel: 'VOTable', name: 'ttfrmt', inputValue: 'VOT'} - ]; - - var timeFormatId = 'tf_tt'; - this.formatId = 'nsf_tt'; - this.localUploadId = 'form-uploadtt'; - var localUploadName ='localTTName'; - var remoteUploadName ='remoteTT'; - this.remoteUploadId = 'form-uploadtturl'; - this.nodeType = 'amdaModel.TimeTableNode'; - //TODO load XML - var store = Ext.create('Ext.data.Store', { - fields: ['value', 'name'], - data : [] - }); - } - - var combo = Ext.create('Ext.form.ComboBox', { - flex : 4, - store: store, - emptyText: 'Enter Remote Site URL (ftp)', - queryMode: 'local', - displayField: 'name', - valueField: 'value' - }); + /* + * panel config + */ + init : function(config) + { + this.isFile = config.panelType == 'file'? true : false; + this.isTimeTable = config.panelType == 'timetable'? true : false; + + // file / time table / catalog settings + if (this.isFile) + { + var title = 'File'; + var items = [ + { boxLabel: 'ASCII', name: 'filefrmt', inputValue: 'ASCII', checked: true, + listeners: + { + change: function (cb, nv, ov) { + if (nv) Ext.getCmp('tf').show(); + else Ext.getCmp('tf').hide(); + } + } + }, + // { boxLabel: 'netCDF <img amda_clicktip="ncTimeFormat" style="vertical-align:bottom" src="js/resources/images/16x16/info_mini.png"', name: 'filefrmt', inputValue: 'NC' }, + { boxLabel: 'CDF <img amda_clicktip="cdfTimeFormat" style="vertical-align:bottom" src="js/resources/images/16x16/info_mini.png"', name: 'filefrmt', inputValue: 'CDF' }, + // { boxLabel: 'CEF[GZ]', name: 'filefrmt', inputValue: 'CEF' }, + { boxLabel: 'VOTable', name: 'filefrmt', inputValue: 'VOT' }]; + var timeFormatId = 'tf'; + this.formatId = 'nsf'; + this.localUploadId = 'form-uploadfile'; + var localUploadName ='localFileName'; + var remoteUploadName ='remoteFile'; + this.remoteUploadId = 'form-uploadurl'; + this.nodeType = 'amdaModel.MyDataParamNode'; + //TODO load XML + var store = Ext.create('Ext.data.Store', { + fields: ['value', 'name'], + data : [ + {"value":"ftp://cdaweb.gsfc.nasa.gov/pub/data/", "name":"CDAWEB/FTP"}/*, + {"value":"ftp://ftp.ngdc.noaa.gov/STP/SOLAR_DATA/", "name":"Solar Data"}*/] + }); + } + else if (this.isTimeTable) + { + var title = 'Time Table'; + var items = [ + { boxLabel: 'ASCII', name: 'ttfrmt', inputValue: 'ASCII', checked: true, + listeners: { + change: function (cb, nv, ov) { + if (nv) Ext.getCmp('tf_tt').show(); + else Ext.getCmp('tf_tt').hide(); + } + } + }, + { boxLabel: 'VOTable', name: 'ttfrmt', inputValue: 'VOT'}]; + + var timeFormatId = 'tf_tt'; + this.formatId = 'nsf_tt'; + this.localUploadId = 'form-uploadtt'; + var localUploadName ='localTTName'; + var remoteUploadName ='remoteTT'; + this.remoteUploadId = 'form-uploadtturl'; + this.nodeType = 'amdaModel.TimeTableNode'; + //TODO load XML + var store = Ext.create('Ext.data.Store', { + fields: ['value', 'name'], + data : [] + }); + } + else + { + var title = 'Catalog'; + var items = [ + { boxLabel: 'VOTable', name: 'catfrmt', inputValue: 'VOT', checked: true }]; + + var timeFormatId = 'tf_cat'; + this.formatId = 'nsf_cat'; + this.localUploadId = 'form-uploadcat'; + var localUploadName ='localCatName'; + var remoteUploadName ='remoteCat'; + + this.remoteUploadId = 'form-uploadcaturl'; + this.nodeType = 'amdaModel.CatalogNode'; + //TODO load XML + var store = Ext.create('Ext.data.Store', { + fields: ['value', 'name'], + data : [] + }); + } + + var combo = Ext.create('Ext.form.ComboBox', { + flex : 4, + store: store, + emptyText: 'Enter Remote Site URL (ftp)', + queryMode: 'local', + displayField: 'name', + valueField: 'value' + }); - var fieldcontainer = { xtype: 'fieldcontainer', - fieldLabel: ' ', labelWidth: 0, labelSeparator : '', labelPad : 0, - layout: 'hbox', - items: [ - combo, - { - xtype : 'button', - flex : 1, - text: 'Browse It', - handler: function(){ - var form = this.up('form').getForm(); - var site = form.getFields().getAt(0).getValue(); - if (site) - this.up('form').ownerCt.fireEvent('open', site); - else - myDesktopApp.warningMsg("Please Enter Remote Site URL"); - } - } - ] - }; - var radioId = this.isFile ? 'filefrmt' : 'ttfrmt'; - var fileFormat = Ext.create('Ext.form.FieldSet', { - title: 'File Format', - items : [ { - xtype: 'radiogroup', - id : radioId, - columns: 3, - cls: 'x-check-group-alt', - items: items - } - ] - }); + var fieldcontainer = + { + xtype: 'fieldcontainer', + fieldLabel: ' ', labelWidth: 0, labelSeparator : '', labelPad : 0, + layout: 'hbox', + items: [ + combo, + { + xtype : 'button', + flex : 1, + text: 'Browse It', + handler: function() + { + var form = this.up('form').getForm(); + var site = form.getFields().getAt(0).getValue(); + if (site) + this.up('form').ownerCt.fireEvent('open', site); + else + myDesktopApp.warningMsg("Please Enter Remote Site URL"); + } + }] + }; + + if (this.isFile) var radioId = 'filefrmt'; + else if (this.isTimeTable) var radioId = 'ttfrmt'; + else var radioId = 'catfrmt'; + + var fileFormat = Ext.create('Ext.form.FieldSet', { + title: 'File Format', + items : [{ + xtype: 'radiogroup', + id : radioId, + columns: 3, + cls: 'x-check-group-alt', + items: items + }] + }); - var Sampling = { xtype: 'radiogroup', - fieldLabel: 'Time Sampling', - labelWidth: 90, - cls: 'x-check-group-alt', - hidden : !this.isFile, - defaults : {name : 'timesmpl'}, - items: [ - {boxLabel: 'constant', inputValue: 'constant', checked: true}, - {boxLabel: 'variable <img amda_clicktip="variableSampling" style="vertical-align:bottom" src="js/resources/images/16x16/info_mini.png"', inputValue: 'variable'} - ] - }; + var Sampling = + { + xtype: 'radiogroup', + fieldLabel: 'Time Sampling', + labelWidth: 90, + cls: 'x-check-group-alt', + hidden : !this.isFile, + defaults : {name : 'timesmpl'}, + items: [ + {boxLabel: 'constant', inputValue: 'constant', checked: true}, + {boxLabel: 'variable <img amda_clicktip="variableSampling" style="vertical-align:bottom" src="js/resources/images/16x16/info_mini.png"', inputValue: 'variable'} + ] + }; - var dayStart = { xtype: 'checkbox', - name : 'doy', - hidden : true, - fieldLabel: 'DOY starts from 1', - inputValue: '1' - }; - - var nonStandardFormat = - { - xtype: 'fieldcontainer', - defaultType: 'textfield', - layout: 'anchor', - defaults: { - layout: '100%', - labelWidth : 150 - }, - id : this.formatId, - hidden : true, - items: [ - { - fieldLabel : 'define time format', - name : 'nonstd', - value: 'Y-m-d H:i:s', - enableKeyEvents: true, - listeners : { - keyUp : function() { - if (this.getValue().indexOf('z') > 0) { - this.nextSibling().show(); - } - if (this.getValue().indexOf('d') > 0) { - this.nextSibling().hide(); - } - } - } - }, - dayStart, - { - fieldLabel : 'define max time length', - name : 'timelength', - value: 'auto' - } - ], - listeners : { - hide : function() { - this.items.getAt(1).hide(); - } - } - }; + var dayStart = + { + xtype: 'checkbox', + name : 'doy', + hidden : true, + fieldLabel: 'DOY starts from 1', + inputValue: '1' + }; + + var nonStandardFormat = + { + xtype: 'fieldcontainer', + defaultType: 'textfield', + layout: 'anchor', + defaults: + { + layout: '100%', + labelWidth : 150 + }, + id : this.formatId, + hidden : true, + items: [ + { + fieldLabel : 'define time format', + name : 'nonstd', + value: 'Y-m-d H:i:s', + enableKeyEvents: true, + listeners : + { + keyUp : function() { + if (this.getValue().indexOf('z') > 0) { + this.nextSibling().show(); + } + if (this.getValue().indexOf('d') > 0) { + this.nextSibling().hide(); + } + } + } + }, + dayStart, + { + fieldLabel : 'define max time length', + name : 'timelength', + value: 'auto' + }], + listeners : + { + hide : function() { + this.items.getAt(1).hide(); + } + } + }; + var isCatalog = !(this.isFile || this.isTimeTable); - var timeFormat = Ext.create('Ext.form.FieldSet', { - id: timeFormatId, - title: 'Time Settings', - items : [{ - xtype: 'radiogroup', - fieldLabel: 'Time Format', - labelWidth: 90, - cls: 'x-check-group-alt', - defaults : { name : 'timefrmt'}, - items: [ - {boxLabel: 'standard <img amda_clicktip="standardTimeFormat" style="vertical-align:bottom" src="js/resources/images/16x16/info_mini.png"', inputValue: 'standard', checked: true}, - {boxLabel: 'no <img amda_clicktip="userTimeFormat" style="vertical-align:bottom" src="js/resources/images/16x16/info_mini.png"', inputValue: 'user', - listeners: { - scope : this, - change: function (cb, nv, ov) { - if (nv) - Ext.getCmp(this.formatId).show(); - else - Ext.getCmp(this.formatId).hide(); - } - } - } - ] - }, - nonStandardFormat, - Sampling - ] - }); - - var localFile = Ext.create('Ext.form.Panel', { - id: this.localUploadId, - fileUpload: true, - hideLabels: true, - frame: true, - items: [{ - xtype: 'fileuploadfield', - emptyText: 'Select Your File', - width: 300, - name: localUploadName, - buttonText: 'Browse', - listeners: { - scope : this, - change: function (field, value, e) { - this.updateFormat(value); - } - } - }, - { - // it is common setting for Local and Remote files - xtype : 'hiddenfield', - name: 'MAX_FILE_SIZE', - value: myDesktopApp.MAX_UPLOADED_FILE_SIZE // 30MB - } - ] - }); - - var remoteFile = Ext.create('Ext.form.Panel', { - id: this.remoteUploadId, - hideLabels: true, - autoHeight: true, - frame: true, - hidden : true, - items: [ fieldcontainer, - { xtype : 'textfield', - name : remoteUploadName, - emptyText: 'Enter Remote File URL (http or ftp)', - width: 310, - listeners: { - scope : this, - change: function (field, value, e) { - this.updateFormat(value); - } - } - } - ] - }); + var timeFormat = Ext.create('Ext.form.FieldSet', { + id: timeFormatId, + title: 'Time Settings', + hidden : isCatalog, + items : [ + { + xtype: 'radiogroup', + fieldLabel: 'Time Format', + labelWidth: 90, + cls: 'x-check-group-alt', + defaults : { name : 'timefrmt'}, + items: [ + { boxLabel: 'standard <img amda_clicktip="standardTimeFormat" style="vertical-align:bottom" src="js/resources/images/16x16/info_mini.png"', inputValue: 'standard', checked: true}, + { boxLabel: 'no <img amda_clicktip="userTimeFormat" style="vertical-align:bottom" src="js/resources/images/16x16/info_mini.png"', inputValue: 'user', + listeners: + { + scope : this, + change: function (cb, nv, ov) { + if (nv) + Ext.getCmp(this.formatId).show(); + else + Ext.getCmp(this.formatId).hide(); + } + } + }] + }, + nonStandardFormat, + Sampling ] + }); + + var localFile = Ext.create('Ext.form.Panel', { + id: this.localUploadId, + fileUpload: true, + hideLabels: true, + frame: true, + items: [ + { + xtype: 'fileuploadfield', + emptyText: 'Select Your File', + width: 300, + name: localUploadName, + buttonText: 'Browse', + listeners: + { + scope : this, + change: function (field, value, e) { + this.updateFormat(value); + } + } + }, + { + // it is common setting for Local and Remote files + xtype : 'hiddenfield', + name: 'MAX_FILE_SIZE', + value: myDesktopApp.MAX_UPLOADED_FILE_SIZE // 30MB + }] + }); + + var remoteFile = Ext.create('Ext.form.Panel', { + id: this.remoteUploadId, + hideLabels: true, + autoHeight: true, + frame: true, + hidden : true, + items: [ + fieldcontainer, + { + xtype : 'textfield', + name : remoteUploadName, + emptyText: 'Enter Remote File URL (http or ftp)', + width: 310, + listeners: + { + scope : this, + change: function (field, value, e) { + this.updateFormat(value); + } + } + }] + }); - var uploadForm = Ext.create('Ext.form.FieldSet',{ - title: 'File Source', - items : [{ xtype: 'radiogroup', - cls: 'x-check-group-alt', - items: [ - {boxLabel: 'Local', name: 'filesrc', inputValue: 'LOCAL', checked: true, - listeners: { - scope : this, - change: function (cb, nv, ov) { - if (nv == ov) return; - var local = Ext.getCmp(this.localUploadId); - var remote = Ext.getCmp(this.remoteUploadId); - if (nv) { - remote.hide(); - local.show(); - } - else { - local.hide(); - remote.show(); - } - } - } - }, - {boxLabel: 'URL', name: 'filesrc', inputValue: 'URL'}, - ]}] - }); - - var myConf = { - title : title, - layout: {type: 'vbox', align: 'stretch'}, - bodyStyle: { background : '#dfe8f6'}, - items : [ - uploadForm, - localFile, - remoteFile, - fileFormat, - timeFormat - ], - buttons: [ - { - text: 'Upload', - handler: function() - { - this.postUpload(); - }, - scope : this - }, - { - text: 'Reset', - handler: function(){ - this.up('form').getForm().reset(); - } - } - ], - plugins: [{ptype: 'remoteSearchPlugin'}], - listeners: { - click: { - element: 'el', - fn: function(e,t) { - var me = t, - text = me.getAttribute('amda_clicktip'); - if (text) { - e.preventDefault(); - AmdaAction.getInfo({name : text}, function(res,e) { - if (res.success) myDesktopApp.infoMsg(res.result); - }); - } - } - } - } - }; - - Ext.apply (this, Ext.apply(arguments, myConf)); - } + var uploadForm = Ext.create('Ext.form.FieldSet',{ + title: 'File Source', + items : [ + { + xtype: 'radiogroup', + cls: 'x-check-group-alt', + items: [ + { boxLabel: 'Local', name: 'filesrc', inputValue: 'LOCAL', checked: true, + listeners: + { + scope : this, + change: function (cb, nv, ov) { + if (nv == ov) return; + var local = Ext.getCmp(this.localUploadId); + var remote = Ext.getCmp(this.remoteUploadId); + if (nv) { + remote.hide(); + local.show(); + } + else { + local.hide(); + remote.show(); + } + } + } + }, + { boxLabel: 'URL', name: 'filesrc', inputValue: 'URL'} ] + }] + }); + + var myConf = + { + title : title, + layout: {type: 'vbox', align: 'stretch'}, + bodyStyle: { background : '#dfe8f6'}, + items : [ + uploadForm, + localFile, + remoteFile, + fileFormat, + timeFormat + ], + buttons: [ + { + text: 'Upload', + handler: function() + { + this.postUpload(); + }, + scope : this + }, + { + text: 'Reset', + handler: function(){ + this.up('form').getForm().reset(); + } + }], + plugins: [{ptype: 'remoteSearchPlugin'}], + listeners: + { + click: + { + element: 'el', + fn: function(e,t) { + var me = t, + text = me.getAttribute('amda_clicktip'); + if (text) + { + e.preventDefault(); + AmdaAction.getInfo({name : text}, function(res,e) { + if (res.success) myDesktopApp.infoMsg(res.result); + }); + } + } + } + } + }; + + Ext.apply (this, Ext.apply(arguments, myConf)); + } }); diff --git a/js/app/views/UploadUI.js b/js/app/views/UploadUI.js index 6dd49a5..165d64a 100644 --- a/js/app/views/UploadUI.js +++ b/js/app/views/UploadUI.js @@ -14,7 +14,7 @@ Ext.define('amdaUI.UploadUI', { alias: 'widget.panelTabUpload', requires: [ - 'amdaUI.UploadPanelUI' + 'amdaUI.UploadPanelUI' ], constructor: function(config) { @@ -22,43 +22,43 @@ Ext.define('amdaUI.UploadUI', { this.callParent(arguments); }, - init : function(config) { - - var myConf = { - layout: 'border', - items: [ { - xtype: 'tabpanel', - region: 'center', - activeTab : 0, - items : - [ - { xtype: 'panelUpload', panelType : 'file'}, - { xtype: 'panelUpload', panelType : 'timetable'} - ] - }, - { - xtype: 'panel', - region: 'south', - title: 'Information', - collapsible: true, - height: 100, - autoHide: false, - iconCls: 'icon-information', - html: 'Select local or remote file (time table) to upload<br/>File size is limited to <b><i>' - + myDesktopApp.MAX_UPLOADED_FILE_SIZE/1000000+'MB</i></b><br/>Milliseconds are ignored for the moment', - autoScroll : true, - loader: {} - } - ] - }; + init : function(config) + { + var myConf = + { + layout: 'border', + items: [ + { + xtype: 'tabpanel', + region: 'center', + activeTab : 0, + items : [ + { xtype: 'panelUpload', panelType : 'file'}, + { xtype: 'panelUpload', panelType : 'timetable'}, + { xtype: 'panelUpload', panelType : 'catalog'}] + }, + { + xtype: 'panel', + region: 'south', + title: 'Information', + collapsible: true, + height: 100, + autoHide: false, + iconCls: 'icon-information', + html: 'Select local or remote file (time table, catalog) to upload<br/>File size is limited to <b><i>' + + myDesktopApp.MAX_UPLOADED_FILE_SIZE/1000000+'MB</i></b><br/>Milliseconds are ignored for the moment', + autoScroll : true, + loader: {} + }] + }; - Ext.apply (this, Ext.apply(arguments, myConf)); - }, + Ext.apply (this, Ext.apply(arguments, myConf)); + }, - forceUpload : function(url,format) { - //this.setDisabled(true); - this.items.items[0].items.items[0].forceUpload(url,format); - //this.setDisabled(false); - } - + forceUpload : function(url,format) + { + //this.setDisabled(true); + this.items.items[0].items.items[0].forceUpload(url,format); + //this.setDisabled(false); + } }); diff --git a/php/classes/AmdaAction.php b/php/classes/AmdaAction.php index 3e91373..9ad7d0d 100644 --- a/php/classes/AmdaAction.php +++ b/php/classes/AmdaAction.php @@ -602,9 +602,13 @@ class AmdaAction case 'myDataParam' : $objectMgr = new FilesMgr(); break; + case 'catalog' : + $objectMgr = new CatalogMgr(); + break; default: return array("error" => $nodeType." NOT_IMPLEMENTED_YET"); } + return $objectMgr->getUploadedObject($name, $format, true); } @@ -1017,16 +1021,17 @@ class AmdaAction public function initTTCacheFromTmpObject($folderId, $name, $isCatalog = false) { - if (!$isCatalog) $cacheMgr = new TimeTableCacheMgr(); - + if (!$isCatalog) $cacheMgr = new TimeTableCacheMgr(); else $cacheMgr = new CatalogCacheMgr(); return $cacheMgr->initFromTmpObject($folderId, $name); } - public function initTTCacheFromUploadedFile($name, $format) + public function initTTCacheFromUploadedFile($name, $format, $isCatalog = false) { - $cacheMgr = new TimeTableCacheMgr(); + if (!$isCatalog) $cacheMgr = new TimeTableCacheMgr(); + else $cacheMgr = new CatalogCacheMgr(); + return $cacheMgr->initFromUploadedFile($name, $format); } diff --git a/php/classes/CatalogCacheMgr.php b/php/classes/CatalogCacheMgr.php index d482cbb..1342885 100644 --- a/php/classes/CatalogCacheMgr.php +++ b/php/classes/CatalogCacheMgr.php @@ -45,7 +45,7 @@ class CatIntervalCacheObject extends IntervalCacheObject { fwrite($handle,pack('L6',$this->id,$this->index,$this->start,$this->stop,$this->isNew,$this->isModified)); for ($i = 0; $i < $paramsNumber; $i++) { - $paramString = $this->params[$i]; + $paramString = $this->params[$i]; $paramArray = explode(',',$this->params[$i]); for ($j = 0; $j < $paramsSizes[$i]; $j++) fwrite($handle,pack('d', $paramArray[$j])); } @@ -63,11 +63,12 @@ class CatIntervalCacheObject extends IntervalCacheObject for ($i = 0; $i < $paramsNumber; $i++) { $this->params[$i] = null; - for ($j = 0; $j < $paramsSizes[$i]; $j++) { - $val = unpack('dval',fread($handle,8)); - $this->params[$i] .= $val['val']; - if ($j != $paramsSizes[$i] - 1) $this->params[$i] .= ','; - } + for ($j = 0; $j < $paramsSizes[$i]; $j++) + { + $val = unpack('dval',fread($handle,8)); + $this->params[$i] .= $val['val']; + if ($j != $paramsSizes[$i] - 1) $this->params[$i] .= ','; + } } } @@ -306,8 +307,44 @@ class CatalogCacheMgr extends TimeTableCacheMgr $this->cache->updateIndexes(); //Save cache file - return array('success' => $this->saveToFile(), 'token' => $this->cache->getToken(), - 'status' => $this->cache->getStatus(), 'parameters' => $paramHeaders); + return array('success'=>$this->saveToFile(), 'token'=>$this->cache->getToken(), + 'status'=>$this->cache->getStatus(), 'parameters'=>$paramHeaders); + } + + public function initFromUploadedFile($name, $format) + { + //Create new cache + $this->cache = new CatalogCacheObject(); + + //Load intervals from uploaded file + $intervals_res = $this->ttMgr->getUploadedObject($name, $format); + + if (!isset($intervals_res)) + return array('success' => false, 'message' => 'Cannot get Uploaded Object'); + + if (array_key_exists('intervals', $intervals_res)) + { + foreach ($intervals_res['intervals'] as $interval) + { + //Add interval + $this->cache->addInterval($interval['start'], $interval['stop'], $interval['paramTable']); + } + } + + $this->cache->setIsModified(true); + $paramHeaders = $intervals_res['parameters']; + + $this->cache->setParamsNumber(count($paramHeaders)); + $this->cache->setParamsSizes($paramHeaders); + + unset($intervals_res); + + //Update cache + $this->cache->updateIndexes(); + + //Save cache file + return array('success'=>$this->saveToFile(), 'token'=>$this->cache->getToken(), + 'status'=>$this->cache->getStatus(), 'parameters'=>$paramHeaders); } public function initFromTT($id, $typeTT) diff --git a/php/classes/CatalogMgr.php b/php/classes/CatalogMgr.php index f985bcc..14846ab 100644 --- a/php/classes/CatalogMgr.php +++ b/php/classes/CatalogMgr.php @@ -4,8 +4,8 @@ * @class CatalogMgr */ -class CatalogMgr extends TimeTableMgr { - +class CatalogMgr extends TimeTableMgr +{ function __construct($sharedObject = FALSE) { parent::__construct('Tt.xml', $sharedObject); $this->contentRootId = 'catalog-treeRootNode'; @@ -20,9 +20,21 @@ class CatalogMgr extends TimeTableMgr { $this->xp = new domxpath($this->contentDom); } } - - public function getTmpObject($folderId, $name, $onlyDescription = false) { + public function getUploadedObject($name, $format, $onlyDescription = false) + { + if ($format == 'VOT') + { + $attributesToReturn = $this->vot2amda(USERTEMPDIR.$name, $onlyDescription); + } + $attributesToReturn['objName'] = $name; + $attributesToReturn['objFormat'] = $format; + + return $attributesToReturn; + } + + public function getTmpObject($folderId, $name, $onlyDescription = false) + { $filePath = USERWORKINGDIR.$folderId.'/'.$name.'.xml'; if (!file_exists($filePath)) @@ -415,5 +427,78 @@ class CatalogMgr extends TimeTableMgr { // return array ('error' => $e->getMessage()); // } // } + +/* +* Uploaded vot catalog => convert to AMDA tmp +*/ + protected function vot2amda($tmp_file, $onlyDescription = false) + { + // Load Catalog + $this->objectDom->load($tmp_file); + $objToGet = $this->objectDom->getElementsByTagName('TABLEDATA')->item(0); + + $attributes = $objToGet->childNodes; + $paramsNodes = $this->objectDom->getElementsByTagName('FIELD'); + $paramsNumber = $paramsNodes->length; + + foreach($attributes as $attribute) + { + if ($attribute->tagName == 'TR') + { + $start = $attribute->getElementsByTagName('TD')->item(0)->nodeValue; + $stop = $attribute->getElementsByTagName('TD')->item(1)->nodeValue; + $params = array(); + + for ($i = 2; $i < $paramsNumber; $i++) + { + $param = $attribute->getElementsByTagName('TD')->item($i)->nodeValue; + + if ($paramsNodes->item($i)->hasAttribute('arraysize')) + { + $param = join(",",explode(" ",trim($param))); + } + $params[] = $param; + } + if (!$onlyDescription) + $attributesToReturn['intervals'][] = array('start' => $start, 'stop' => $stop, 'paramTable' => $params); + } + } + + if ($paramsNumber > 2) + { + $paramsArray = array(); + for ($i = 2; $i < $paramsNumber; $i++) + { + $oneParam = array(); + $paramNode = $paramsNodes->item($i); + + if ($paramNode->hasAttribute('arraysize')) + { + $oneParam['size'] = $paramNode->getAttribute('arraysize'); + } + else + { + $oneParam['size'] = 1; + } + foreach ($paramNode->attributes as $attr) + { + if ($attr->nodeName == 'datatype') + $oneParam['type'] = $attr->nodeValue;//'Double'; + else if ($attr->nodeName != 'arraysize') + $oneParam[$attr->nodeName] = $attr->nodeValue; + } + $paramsArray[] = $oneParam; + } + $attributesToReturn['success'] = true; + $attributesToReturn['parameters'] = $paramsArray; + } + + $suffix = explode('.', basename($tmp_file)); + $attributesToReturn['name'] = basename($tmp_file, '.'.$suffix[1]); + $attributesToReturn['created'] = date('Y-m-d')."T".date('H:i:s'); + $attributesToReturn['description'] = htmlspecialchars($this->objectDom->getElementsByTagName('DESCRIPTION')->item(0)->nodeValue); + + return($attributesToReturn); + } } ?> diff --git a/php/config.php b/php/config.php index 5112ccc..1e7acbd 100644 --- a/php/config.php +++ b/php/config.php @@ -170,7 +170,7 @@ $API = array( 'initTTCacheFromTT'=>array('len'=>2), 'initForChart'=>array('len'=>4), 'initTTCacheFromTmpObject'=>array('len'=>3), - 'initTTCacheFromUploadedFile'=>array('len'=>2), + 'initTTCacheFromUploadedFile'=>array('len'=>3), 'readTTCacheIntervals'=>array('len'=>1), 'readIntervalsForChart'=>array('len'=>1), 'addTTCacheInterval'=>array('len'=>1), diff --git a/php/uploadFile.php b/php/uploadFile.php index 452a915..858f99d 100644 --- a/php/uploadFile.php +++ b/php/uploadFile.php @@ -7,296 +7,300 @@ * */ - function file_upload_error_message($error_code) { - - switch ($error_code) { - case UPLOAD_ERR_INI_SIZE: - return 'The uploaded file exceeds the upload_max_filesize directive in php.ini'; - case UPLOAD_ERR_FORM_SIZE: - return 'The uploaded file exceeds max file size of '.maxSize; - case UPLOAD_ERR_PARTIAL: - return 'The uploaded file was only partially uploaded'; - case UPLOAD_ERR_NO_FILE: - return 'No file was uploaded'; - case UPLOAD_ERR_NO_TMP_DIR: - return 'Missing a temporary folder'; - case UPLOAD_ERR_CANT_WRITE: - return 'Failed to write file to disk'; - case UPLOAD_ERR_EXTENSION: - return 'File upload stopped by extension'; - case UPLOAD_ERR_EMPTY: - return 'File is empty'; - default: - return 'Unknown upload error'; - } - } - - function getUrlFileSize($URL) { - $ch = curl_init($URL); - curl_setopt($ch, CURLOPT_NOBODY, true); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_HEADER, true); - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); - $data = curl_exec($ch); - curl_close($ch); + function file_upload_error_message($error_code) + { + switch ($error_code) + { + case UPLOAD_ERR_INI_SIZE: + return 'The uploaded file exceeds the upload_max_filesize directive in php.ini'; + case UPLOAD_ERR_FORM_SIZE: + return 'The uploaded file exceeds max file size of '.maxSize; + case UPLOAD_ERR_PARTIAL: + return 'The uploaded file was only partially uploaded'; + case UPLOAD_ERR_NO_FILE: + return 'No file was uploaded'; + case UPLOAD_ERR_NO_TMP_DIR: + return 'Missing a temporary folder'; + case UPLOAD_ERR_CANT_WRITE: + return 'Failed to write file to disk'; + case UPLOAD_ERR_EXTENSION: + return 'File upload stopped by extension'; + case UPLOAD_ERR_EMPTY: + return 'File is empty'; + default: + return 'Unknown upload error'; + } + } - $ContentLength = 1000000000000000000; - if (preg_match('/Content-Length: (\d+)/', $data, $matches)) { - $ContentLength = (int)$matches[1]; - } - return $ContentLength; - } + function getUrlFileSize($URL) + { + $ch = curl_init($URL); + curl_setopt($ch, CURLOPT_NOBODY, true); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_HEADER, true); + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); + $data = curl_exec($ch); + curl_close($ch); - /** - * Main - */ - define("UPLOAD_ERR_EMPTY",5); + $ContentLength = 1000000000000000000; + if (preg_match('/Content-Length: (\d+)/', $data, $matches)) { + $ContentLength = (int)$matches[1]; + } + + return $ContentLength; + } - require_once 'config.php'; + /** + * Main + */ + define("UPLOAD_ERR_EMPTY",5); - // error_reporting(E_ERROR | E_WARNING | E_PARSE); + require_once 'config.php'; - if (!isset($_POST['sessionID'])) - { - $response = array( 'success' => false, 'error' => ': Check that uploaded file size is less than '.ini_get('upload_max_filesize')); - die(json_encode($response)); - } + // error_reporting(E_ERROR | E_WARNING | E_PARSE); - define('USERDATADIR', USERPATH."/".$_POST['sessionID']."/DATA/"); - define('USERTEMPDIR', USERPATH."/".$_POST['sessionID']."/TEMP/"); - define('USERWSDIR', USERPATH."/".$_POST['sessionID']."/WS/"); - define('USERWORKINGDIR', USERPATH."/".$_POST['sessionID']."/RES/"); - define('ATTACHMENTDIR', DATAPATH."/Feedback/Attach/"); - define('maxSize',$_POST['MAX_FILE_SIZE'] < ini_get('upload_max_filesize')); + if (!isset($_POST['sessionID'])) + { + $response = array( 'success' => false, 'error' => ': Check that uploaded file size is less than '.ini_get('upload_max_filesize')); + die(json_encode($response)); + } - if (!is_dir(USERTEMPDIR)) mkdir(USERTEMPDIR.'/', 0755, true); - if (!is_dir(ATTACHMENTDIR)) mkdir(ATTACHMENTDIR.'/', 0755, true); + define('USERDATADIR', USERPATH."/".$_POST['sessionID']."/DATA/"); + define('USERTEMPDIR', USERPATH."/".$_POST['sessionID']."/TEMP/"); + define('USERWSDIR', USERPATH."/".$_POST['sessionID']."/WS/"); + define('USERWORKINGDIR', USERPATH."/".$_POST['sessionID']."/RES/"); + define('ATTACHMENTDIR', DATAPATH."/Feedback/Attach/"); + define('maxSize',$_POST['MAX_FILE_SIZE'] < ini_get('upload_max_filesize')); - if (!$_FILES['attachment'] && !$_FILES['localFileName'] && !$_FILES['localTTName'] && - !$_POST['remoteFile'] && !$_POST['remoteTT']) - { - $response = array( 'success' => false, 'error' => 'UNDEFINED ACTION'); - die(json_encode($response)); - } - - $fileFrmt = $_POST['filefrmt']; - $timeFrmt = $_POST['timefrmt'] ? $_POST['timefrmt'] : null; - $timeSmplg = $_POST['timesmpl'] ? $_POST['timesmpl'] : null; - $nonStd = $_POST['nonstd'] ? $_POST['nonstd'] : null; - $timeLength = $_POST['timelength'] ? $_POST['timelength'] : null; - $doy = $_POST['doy'] ? $_POST['doy'] : null; + if (!is_dir(USERTEMPDIR)) mkdir(USERTEMPDIR.'/', 0755, true); + if (!is_dir(ATTACHMENTDIR)) mkdir(ATTACHMENTDIR.'/', 0755, true); - $allFormats = array('fileFormat' => $fileFrmt, 'timeFormat' => $timeFrmt, 'doy' => $doy, - 'timeSampling' => $timeSmplg, 'nonStandard' => $nonStd, 'timeLength' => $timeLength); + if (!$_FILES['attachment'] && !$_FILES['localFileName'] && !$_FILES['localTTName'] && !$_FILES['localCatName'] && + !$_POST['remoteFile'] && !$_POST['remoteTT'] && !$_POST['remoteCat']) + { + $response = array( 'success' => false, 'error' => 'UNDEFINED ACTION'); + die(json_encode($response)); + } - if ($_POST['filesrc'] == 'URL') - $fromURL = true; - else - $fromURL = false; - // to check ws sizw - $wsMgr = new UserMgr(); + $fileFrmt = $_POST['filefrmt']; + $timeFrmt = $_POST['timefrmt'] ? $_POST['timefrmt'] : null; + $timeSmplg = $_POST['timesmpl'] ? $_POST['timesmpl'] : null; + $nonStd = $_POST['nonstd'] ? $_POST['nonstd'] : null; + $timeLength = $_POST['timelength'] ? $_POST['timelength'] : null; + $doy = $_POST['doy'] ? $_POST['doy'] : null; + + $allFormats = array('fileFormat' => $fileFrmt, 'timeFormat' => $timeFrmt, 'doy' => $doy, + 'timeSampling' => $timeSmplg, 'nonStandard' => $nonStd, 'timeLength' => $timeLength); - if ($fromURL) - { - // url files check - if ($_POST['remoteFile']) - { - $remoteName = $_POST['remoteFile']; - $fileName = substr(strrchr($remoteName,"/"),1); - $localName = USERDATADIR.$fileName; - $isFile = true; - } - else - { - $remoteName = $_POST['remoteTT']; - $fileName = substr(strrchr($remoteName,"/"),1); - $localName = USERTEMPDIR.$fileName; - $isFile = false; - } + if ($_POST['filesrc'] == 'URL') $fromURL = true; + else $fromURL = false; + + // to check ws sizw + $wsMgr = new UserMgr(); + + if ($fromURL) + { + // url files check + if ($_POST['remoteFile']) + { + $remoteName = $_POST['remoteFile']; + $fileName = substr(strrchr($remoteName,"/"),1); + $localName = USERDATADIR.$fileName; + $isFile = true; + } + else + { + $isTimeTable = $_POST['remoteTT'] ? true : false; + $remoteName = $isTimeTable ? $_POST['remoteTT'] : $_POST['remoteCat']; + $fileName = substr(strrchr($remoteName,"/"),1); + $localName = USERTEMPDIR.$fileName; + $isFile = false; + } - $url = null; + $url = null; - if (substr($remoteName,0,4) == 'http') - $url = 'http'; - if (substr($remoteName,0,3) == 'ftp') - $url = 'ftp'; + if (substr($remoteName,0,4) == 'http') $url = 'http'; + if (substr($remoteName,0,3) == 'ftp') $url = 'ftp'; - if (!$url) - { - $response = array( 'success' => false, 'error' => 'Unknown net protocol'); - die(json_encode($response)); - } + if (!$url) + { + $response = array( 'success' => false, 'error' => 'Unknown net protocol'); + die(json_encode($response)); + } - if (file_exists($localName) && $isFile) - { - $response = array( 'success' => false, 'error' => 'File '.$fileName.' exists'); - die(json_encode($response)); - } + if (file_exists($localName) && $isFile) + { + $response = array( 'success' => false, 'error' => 'File '.$fileName.' exists'); + die(json_encode($response)); + } - if ($url == 'ftp') - $fileSize = filesize($remoteName); - else - $fileSize = getUrlFileSize($remoteName); + if ($url == 'ftp') $fileSize = filesize($remoteName); + else $fileSize = getUrlFileSize($remoteName); - if (!$fileSize) - { - $response = array( 'success' => false, 'error' => 'Can\'t estimate file size '.$fileName); - die(json_encode($response)); - } + if (!$fileSize) + { + $response = array( 'success' => false, 'error' => 'Can\'t estimate file size '.$fileName); + die(json_encode($response)); + } - if ($file['size'] > DISK_QUOTA) - { - $response = array( 'success' => false, 'error' => 'The file you selected is too big for allowed disk quota'); - die(json_encode($response)); - } - - if ($wsMgr->getWsSize() + $fileSize > DISK_QUOTA && $isFile) - { - $response = array( 'success' => false, 'error' => 'Please clean up you workspace. You are about to exceed available disk space'); - die(json_encode($response)); - } + if ($file['size'] > DISK_QUOTA) + { + $response = array( 'success' => false, 'error' => 'The file you selected is too big for allowed disk quota'); + die(json_encode($response)); + } + + if ($wsMgr->getWsSize() + $fileSize > DISK_QUOTA && $isFile) + { + $response = array( 'success' => false, 'error' => 'Please clean up you workspace. You are about to exceed available disk space'); + die(json_encode($response)); + } - if ($fileSize > maxSize) - { - $response = array( 'success' => false, 'error' => 'The uploaded file exceeds '.maxSize); - die(json_encode($response)); - } + if ($fileSize > maxSize) + { + $response = array( 'success' => false, 'error' => 'The uploaded file exceeds '.maxSize); + die(json_encode($response)); + } - if (!copy($remoteName, $localName)) - { - $response = array( 'success' => false, 'error' => 'Can\'t copy '.$fileName); - die(json_encode($response)); - } + if (!copy($remoteName, $localName)) + { + $response = array( 'success' => false, 'error' => 'Can\'t copy '.$fileName); + die(json_encode($response)); + } - if (is_executable($localName)) - { - $response = array( 'success' => false, 'error' => 'File '.$fileName.' is executable'); - unlink($localName); - die(json_encode($response)); - } + if (is_executable($localName)) + { + $response = array( 'success' => false, 'error' => 'File '.$fileName.' is executable'); + unlink($localName); + die(json_encode($response)); + } - if ($isFile) - { - $fileMgr = new FilesMgr(); - $amdaStat = new AmdaStats($_POST['sessionID']); - if ($amdaStat->success) - $amdaStat->addTask('upload', $_POST['sessionID'], null); - } - // Time Table - else - { - $response = array( 'success' => true, 'file' => $fileName, 'format' => $_POST['ttfrmt'] ); - die(json_encode($response)); - } - } - else - { - // local files check - if ($_FILES['localFileName']) - { - $file = $_FILES['localFileName']; - $localName = USERDATADIR.$file['name']; - $isFile = true; - } - else if ($_FILES['attachment']) - { - if (!is_dir(ATTACHMENTDIR)) - mkdir(ATTACHMENTDIR,755); + if ($isFile) + { + $fileMgr = new FilesMgr(); + $amdaStat = new AmdaStats($_POST['sessionID']); + if ($amdaStat->success) $amdaStat->addTask('upload', $_POST['sessionID'], null); + } + // Time Table + else if ($isTimeTable) + { + $response = array( 'success'=>true, 'file'=>$fileName, 'format'=>$_POST['ttfrmt'] ); + die(json_encode($response)); + } + else + { + $response = array( 'success'=>true, 'file'=>$fileName, 'format'=>$_POST['catfrmt'] ); + die(json_encode($response)); + } + } + else + { + // local files check + if ($_FILES['localFileName']) + { + $file = $_FILES['localFileName']; + $localName = USERDATADIR.$file['name']; + $isFile = true; + } + else if ($_FILES['attachment']) + { + if (!is_dir(ATTACHMENTDIR)) mkdir(ATTACHMENTDIR,755); - $file = $_FILES['attachment']; - $file['name'] = str_replace(" ","_",$file['name']); - $file['name'] = $_POST['sessionID'].'_'.date("Y-m-d\TH:i:s").'_'.$file['name']; - $localName = ATTACHMENTDIR.$file['name']; - $isFile = false; - } - else - { - $file = $_FILES['localTTName']; - $localName = USERTEMPDIR.$file['name']; - $isFile = false; - } + $file = $_FILES['attachment']; + $file['name'] = str_replace(" ","_",$file['name']); + $file['name'] = $_POST['sessionID'].'_'.date("Y-m-d\TH:i:s").'_'.$file['name']; + $localName = ATTACHMENTDIR.$file['name']; + $isFile = false; + } + else + { + $isTimeTable = $_FILES['localTTName'] ? true : false; + $file = $isTimeTable ? $_FILES['localTTName'] : $_FILES['localCatName']; + $localName = USERTEMPDIR.$file['name']; + $isFile = false; + } - if($file['size'] === 0 && $file['error'] === 0){ - $file['error'] = 5; - } + if($file['size'] === 0 && $file['error'] === 0) + { + $file['error'] = 5; + } - if ($file['error'] !== 0) - { - $response = array( 'success' => false, 'error' => file_upload_error_message($file['error'])); - die(json_encode($response)); - } + if ($file['error'] !== 0) + { + $response = array( 'success'=>false, 'error'=>file_upload_error_message($file['error'])); + die(json_encode($response)); + } - if (file_exists($localName) && $isFile) - { - $response = array( 'success' => false, 'error' => 'File '.$file['name'].' exists'); - die(json_encode($response)); - } + if (file_exists($localName) && $isFile) + { + $response = array( 'success'=>false, 'error'=>'File '.$file['name'].' exists'); + die(json_encode($response)); + } - if (is_executable($file['tmp_name'])) - { - $response = array( 'success' => false, 'error' => 'File '.$file['name'].' is executable'); - unlink($file['tmp_name']); - die(json_encode($response)); - } + if (is_executable($file['tmp_name'])) + { + $response = array( 'success'=>false, 'error'=>'File '.$file['name'].' is executable'); + unlink($file['tmp_name']); + die(json_encode($response)); + } - if (!is_uploaded_file($file['tmp_name'])) - { - $response = array( 'success' => false, 'error' => 'File '.$file['name'].' WASN\'T UPLOADED'); - unlink($file['tmp_name']); - die(json_encode($response)); - } + if (!is_uploaded_file($file['tmp_name'])) + { + $response = array( 'success'=>false, 'error'=>'File '.$file['name'].' WASN\'T UPLOADED'); + unlink($file['tmp_name']); + die(json_encode($response)); + } - if ($file['size'] > DISK_QUOTA) - { - $response = array( 'success' => false, 'error' => 'The file you selected is too big for allowed disk quota'); - die(json_encode($response)); - } + if ($file['size'] > DISK_QUOTA) + { + $response = array( 'success'=>false, 'error'=>'The file you selected is too big for allowed disk quota'); + die(json_encode($response)); + } - if ($wsMgr->getWsSize() + $file['size'] > DISK_QUOTA) - { - $response = array( 'success' => false, 'error' => 'Please clean up your workspace. You are about to exceed available disk space'); - die(json_encode($response)); - } + if ($wsMgr->getWsSize() + $file['size'] > DISK_QUOTA) + { + $response = array( 'success'=>false, 'error'=>'Please clean up your workspace. You are about to exceed available disk space'); + die(json_encode($response)); + } - if (!rename($file['tmp_name'], $localName)) - { - $response = array( 'success' => false, 'error' => 'Cannot copy file '.$file['name']); - unlink($file['tmp_name']); - die(json_encode($response)); - } + if (!rename($file['tmp_name'], $localName)) + { + $response = array( 'success'=>false, 'error'=>'Cannot copy file '.$file['name']); + unlink($file['tmp_name']); + die(json_encode($response)); + } - if (file_exists($localName) && !$isFile) - { - if ($_POST['ttfrmt'] == 'VOT') - { - $votMgr = new VOTableMgr(); - if (!$votMgr->load($localName) || !$votMgr->isValidSchema()) - { - $response = array( 'success' => false, 'error' => 'File '.$file['name'].' is not valid'); - unlink($localName); - die(json_encode($response)); - } - } - } + if (file_exists($localName) && !$isFile) + { + if ($_POST['ttfrmt'] == 'VOT' || $_POST['catfrmt'] == 'VOT') + { + $votMgr = new VOTableMgr(); + if (!$votMgr->load($localName) || !$votMgr->isValidSchema()) + { + $response = array( 'success'=>false, 'error'=>'File '.$file['name'].' is not valid'); + unlink($localName); + die(json_encode($response)); + } + } + } - $fileName = $file['name']; + $fileName = $file['name']; - if ($isFile) - { - $fileMgr = new FilesMgr(); - $amdaStat = new AmdaStats($_POST['sessionID']); - if ($amdaStat->success) - $amdaStat->addTask('upload', $_POST['sessionID'], null); - } - // Time Table - else - { - $response = array( 'success' => true, 'file' => $fileName, 'format' => $_POST['ttfrmt'] ); - die(json_encode($response)); - } - } + if ($isFile) + { + $fileMgr = new FilesMgr(); + $amdaStat = new AmdaStats($_POST['sessionID']); + if ($amdaStat->success) $amdaStat->addTask('upload', $_POST['sessionID'], null); + } + // Time Table or Catalog + else + { + $format = $isTimeTable ? $_POST['ttfrmt'] : $_POST['catfrmt']; + $response = array( 'success'=>true, 'file'=>$fileName, 'format'=>$format ); + die(json_encode($response)); + } + } - $response = $fileMgr->addFile($fileName, $allFormats); + $response = $fileMgr->addFile($fileName, $allFormats); - echo json_encode($response); + echo json_encode($response); ?> -- libgit2 0.21.2