From 5b9a0c1e913be7d359366e872e0e0a9489492e8a Mon Sep 17 00:00:00 2001 From: Ricardo Rodriguez Date: Wed, 12 Oct 2022 09:29:12 +0200 Subject: [PATCH 1/5] Create dependency-review.yml --- .github/workflows/dependency-review.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 .github/workflows/dependency-review.yml diff --git a/.github/workflows/dependency-review.yml b/.github/workflows/dependency-review.yml new file mode 100644 index 000000000..fe461b424 --- /dev/null +++ b/.github/workflows/dependency-review.yml @@ -0,0 +1,20 @@ +# Dependency Review Action +# +# This Action will scan dependency manifest files that change as part of a Pull Request, surfacing known-vulnerable versions of the packages declared or updated in the PR. Once installed, if the workflow run is marked as required, PRs introducing known-vulnerable packages will be blocked from merging. +# +# Source repository: https://github.com/actions/dependency-review-action +# Public documentation: https://docs.github.com/en/code-security/supply-chain-security/understanding-your-software-supply-chain/about-dependency-review#dependency-review-enforcement +name: 'Dependency Review' +on: [pull_request] + +permissions: + contents: read + +jobs: + dependency-review: + runs-on: ubuntu-latest + steps: + - name: 'Checkout Repository' + uses: actions/checkout@v3 + - name: 'Dependency Review' + uses: actions/dependency-review-action@v2 From e344048da22582cacbc0891df7e96a4c5d40acee Mon Sep 17 00:00:00 2001 From: ch-ricardor Date: Fri, 14 Oct 2022 17:09:51 +0200 Subject: [PATCH 2/5] Catalog Upload Survey Fix --- application/config/form_validation.php | 11 ++ application/controllers/admin/Catalog.php | 123 +++++++++++++----- application/views/catalog/ddi_upload_form.php | 45 +++---- 3 files changed, 127 insertions(+), 52 deletions(-) create mode 100644 application/config/form_validation.php diff --git a/application/config/form_validation.php b/application/config/form_validation.php new file mode 100644 index 000000000..1adbb27e3 --- /dev/null +++ b/application/config/form_validation.php @@ -0,0 +1,11 @@ +'; +$config['error_suffix'] = ''; diff --git a/application/controllers/admin/Catalog.php b/application/controllers/admin/Catalog.php index d284536d7..3e6a9f8d4 100644 --- a/application/controllers/admin/Catalog.php +++ b/application/controllers/admin/Catalog.php @@ -24,7 +24,7 @@ public function __construct() $this->load->helper('querystring_helper','url'); $this->load->helper('form'); //$this->load->helper("catalog"); - $this->template->set_template('admin'); + $this->template->set_template('admin'); $this->load->library("Dataset_manager"); //load language file @@ -64,10 +64,10 @@ public function __construct() */ function index() { - $this->template->set_template('admin5'); + $this->template->set_template('admin5'); //css files $inline_styles=$this->load->view('catalog/catalog_style',NULL, TRUE); - $this->template->add_css($inline_styles,'embed'); + $this->template->add_css($inline_styles,'embed'); //js files @@ -300,31 +300,84 @@ private function get_temp_upload_folder() function upload() - { - $this->add_study(); - } - - /** - * Upload form for DDI (xml) file - * - * @return void - **/ - function add_study() { //user has permissions on the repo //$this->acl->user_has_repository_access($this->active_repo->id); $this->acl_manager->has_access_or_die('study', 'create',null,$this->active_repo->repositoryid); - $this->template->set_template('admin'); + // @TODO: File Validation Rules + // Files XML or RDF should be allowed in one field, they are exclusive + $this->form_validation->set_rules('userfile',t('msg_select_ddi'),'callback_upload_file_check'); + // RRE - One call back check both + //$this->form_validation->set_rules('rdf-file',t('msg_select_ddi'),'callback_upload_file_check'); + +// $this->form_validation->set_rules('userfile',t('msg_select_ddi'),'uploaded[userfile]|ext_in[userfile.xml]]'); +// $this->form_validation->set_rules('rdf-file',t('msg_select_ddi'),'uploaded[rdf-file]|mime_in[rdf-file.xml]|ext_in[rdf-file.xml]'); + + if ($this->form_validation->run() == FALSE) { + + $this->template->set_template('admin'); - //show upload form when no DDI is uploaded - if(!$this->input->post("submit")){ $content=$this->load->view('catalog/ddi_upload_form', array('active_repo'=>$this->active_repo),true); $this->template->write('content', $content,true); $this->template->render(); return; + } else { + + $new_survey=$this->add_study(); + + if (!empty($new_survey)){ + // RRE Clear Errors + $this->session->unset_userdata('error'); + //redirect('admin/catalog/edit/'.$result['sid'],'refresh'); + redirect('admin/catalog/edit/'.$new_survey,'refresh'); + return; + } + + } + return redirect('admin/catalog/upload'); + } + + /** + * Upload Form Validation file + * + * @return TRUE | FALSE + * RRE - Validation runs for xml and rdf files + * Rules: $_FILES Array() + * fields: xml - userfile,rdf - rdf-file + * rdf files requires xml + * matching file names + **/ + function upload_file_check() + { + if (empty($_FILES['userfile']['name'])) { + $this->form_validation->set_message('upload_file_check','{field} '.t('msg_select_ddi')); + return FALSE; } + if (!empty($_FILES['rdf-file']['name'])) { + if (strtolower(basename($_FILES['rdf-file']['name'],'.rdf')) <> strtolower(basename($_FILES['userfile']['name'],'.xml'))) { + $this->form_validation->set_message('upload_file_check','{field} '.t('Files need to have the same Name')); + return FALSE; + } + } + return TRUE; + } + + /** + * Upload form for DDI (xml) file + * + * @return void + * @return Survey ID | NULL + * @TODO: Due a possible Duplicated Record Error or Parse Error + * Message should be returned to the form + **/ + function add_study() + { + // @TODO: Move the Form one level up, add_study calls the model + + //process form + $overwrite=$this->input->post("overwrite"); $repositoryid=$this->input->post("repositoryid"); @@ -335,8 +388,7 @@ function add_study() $overwrite=FALSE; } - //process form - + // Uploads the xml File $temp_upload_folder=$this->get_temp_upload_folder(); //upload class configurations for DDI @@ -347,8 +399,8 @@ function add_study() $this->load->library('upload', $config); - //process uploaded ddi file - $ddi_upload_result=$this->upload->do_upload(); + + $ddi_upload_result=$this->upload->do_upload('userfile'); $uploaded_ddi_path=NULL; @@ -357,7 +409,8 @@ function add_study() $error = $this->upload->display_errors(); $this->db_logger->write_log('ddi-upload',$error,'catalog'); $this->session->set_flashdata('error', $error); - redirect('admin/catalog/add_study','refresh'); + return NULL; + //redirect('admin/catalog/add_study','refresh'); } else //successful upload { @@ -369,7 +422,7 @@ function add_study() $this->load->model("Data_file_model"); $this->load->library('DDI2_import'); - + $user=$this->ion_auth->current_user(); $ddi_path=$uploaded_ddi_path; @@ -390,8 +443,11 @@ function add_study() $this->events->emit('db.after.update', 'surveys', $result['sid'],'refresh'); $this->session->set_flashdata('success', $result); - redirect('admin/catalog/edit/'.$result['sid'],'refresh');return; + + //redirect('admin/catalog/edit/'.$result['sid'],'refresh');return; + return $result['sid']; } + // @TODO: Find how to replicate this error catch(ValidationException $e){ $error_output=array( 'status'=>'failed', @@ -399,13 +455,19 @@ function add_study() 'errors'=>$e->GetValidationErrors() ); - $error_str='Validation Error
'.print_r($e->GetValidationErrors(),true).'
'; + $error_str='Validation Error
'.print_r($e->GetValidationErrors(),true).'
'; $this->session->set_flashdata('error', $error_str); - redirect('admin/catalog/add_study','refresh');return; + //redirect('admin/catalog/add_study','refresh');return; + //redirect('admin/catalog/upload','refresh'); + + // @TODO: Find how to replicate this error +return; } catch(Exception $e){ $this->session->set_flashdata('error', $e->getMessage()); - redirect('admin/catalog/add_study','refresh');return; + //redirect('admin/catalog/add_study','refresh');return; + //redirect('admin/catalog/upload','refresh'); + return NULL; } } @@ -413,7 +475,7 @@ function add_study() private function upload_rdf_file($sid) { $this->load->library('catalog_admin'); - + //upload class configurations for RDF $config['upload_path'] = $this->get_temp_upload_folder(); $config['overwrite'] = FALSE; @@ -423,7 +485,8 @@ private function upload_rdf_file($sid) $this->upload->initialize($config); //process uploaded rdf file - $rdf_upload_result=$this->upload->do_upload('rdf'); + //$rdf_upload_result=$this->upload->do_upload('rdf'); + $rdf_upload_result=$this->upload->do_upload('rdf-file'); $uploaded_rdf_path=''; @@ -445,9 +508,9 @@ private function upload_rdf_file($sid) return true; } - + /** - * + * * Sanitize file name */ private function sanitize_filename($name) diff --git a/application/views/catalog/ddi_upload_form.php b/application/views/catalog/ddi_upload_form.php index a4c8bc0e2..ad75e6832 100644 --- a/application/views/catalog/ddi_upload_form.php +++ b/application/views/catalog/ddi_upload_form.php @@ -25,38 +25,39 @@ session->flashdata('error');?> -'.$error.'' : '';?> +'.$error.'' : '';?> session->flashdata('message');?> '.$message.'' : '';?> +
-

- +

+

- 'form') );?> - + 'form') );?> -
- - - (MB) -
+ +
+ + + (MB) +
-
- - -
+
+ + + (MB) +
-
- -
+
+ " /> + +
@@ -66,7 +67,7 @@

- +
@@ -80,7 +81,7 @@ - +
@@ -88,4 +89,4 @@
- \ No newline at end of file + From eccb1fffa6bd6e7c50713501b26f4401ee7e1204 Mon Sep 17 00:00:00 2001 From: ch-ricardor Date: Tue, 18 Oct 2022 15:09:05 +0200 Subject: [PATCH 3/5] Catalog Batch Import --- application/controllers/admin/Catalog.php | 47 +++++++------ application/libraries/Chunked_uploader.php | 22 ++++-- .../views/catalog/batch_file_upload.php | 13 ++-- .../views/catalog/ddi_batch_import.php | 69 ++++++++++--------- 4 files changed, 83 insertions(+), 68 deletions(-) diff --git a/application/controllers/admin/Catalog.php b/application/controllers/admin/Catalog.php index 3e6a9f8d4..956528131 100644 --- a/application/controllers/admin/Catalog.php +++ b/application/controllers/admin/Catalog.php @@ -93,12 +93,12 @@ function index() //data access types $this->data_access_types=$this->Form_model->get_all(); //data types - $this->catalog_data_types=$this->Search_helper_model->get_dataset_types($this->active_repo->repositoryid); + $this->catalog_data_types=$this->Search_helper_model->get_dataset_types($this->active_repo->repositoryid); if ($db_rows['rows']) { $sid_list=array(); - foreach($db_rows['rows'] as $row) + foreach($db_rows['rows'] as $row) { $sid_list[]=$row['id']; } @@ -120,10 +120,10 @@ function index() $this->template->write('content', $content,true); $this->template->render(); } - + function search() - { + { if (isset($this->active_repo) && $this->active_repo!=null){ $this->Catalog_model->active_repo=$this->active_repo->repositoryid; } @@ -544,9 +544,9 @@ private function __replace_ddi($sid,$new_ddi_file) 'file_type'=>'survey', 'file_path'=>$new_ddi_file ); - + $this->load->library('Metadata_parser', $parser_params); - + //parser to read metadata $parser=$this->metadata_parser->get_reader(); @@ -701,14 +701,14 @@ function refresh($id=NULL) } } - + /** * * Clear files from the imports folder **/ function clear_import_folder() - { + { $this->load->helper('file'); $import_folder=$this->config->item('ddi_import_folder'); @@ -743,17 +743,16 @@ function process_batch_uploads() { //import folder path $import_folder=$this->config->item('ddi_import_folder'); - if (!file_exists($import_folder)){ show_error('FOLDER-NOT-SET'); } $config = array( - 'max_tmp_file_age' => 900, - 'max_execution_time' => 300, - 'target_dir' => $import_folder, + 'max_tmp_file_age' => 900, + 'max_execution_time' => 300, + 'target_dir' => $import_folder, 'allowed_extensions' =>'xml|rdf', - 'overwrite_file' =>TRUE + 'overwrite_file' =>TRUE ); $this->load->library('Chunked_uploader', $config, 'uploader'); @@ -783,7 +782,6 @@ function process_batch_uploads() } - /** * Imports multiple ddi files from the server folder * @@ -802,20 +800,25 @@ function batch_import() $import_folder=$this->config->item('ddi_import_folder'); if (!file_exists($import_folder) ){ - $import_folder="/datasets"; + // @TODO: Review datasets directory does not exist either + // $import_folder="/datasets"; + $import_folder="/datafiles/tmp"; } //read files $files['files']=get_dir_file_info($import_folder); if ( $files['files']){ - foreach($files['files'] as $key=>$value){ - if (substr($value['name'],-4)!='.xml'){ + foreach($files['files'] as $key=>$value){ + //if (substr($value['name'],-4)!='.xml'){ + //if (! in_array(pathinfo($value['name'], PATHINFO_EXTENSION), array('xml','rdf'))) { + if (! in_array(pathinfo($value['name'], PATHINFO_EXTENSION), array('xml'))) { + // @TODO: Check if rdf files should be processed unset($files['files'][$key]); } } } - + $options=array( 'repositories'=>$this->Repository_model->select_all(), 'files'=>$files['files'], @@ -855,10 +858,10 @@ function do_batch_import() echo json_encode(array('error'=>t('REPO_ACCESS_DENIED')) ); exit; } - + $this->load->model("Data_file_model"); $this->load->library('DDI2_import'); - + $user=$this->ion_auth->current_user(); $ddi_path=$ddi_file; @@ -890,7 +893,7 @@ function do_batch_import() 'message'=>$e->getMessage(), 'errors'=>$e->GetValidationErrors() ); - + $error=print_r($e->GetValidationErrors(),true); echo json_encode(array('error'=>$error) ); die(); @@ -902,7 +905,7 @@ function do_batch_import() } } - + /** * diff --git a/application/libraries/Chunked_uploader.php b/application/libraries/Chunked_uploader.php index 1017d392f..4256028f5 100644 --- a/application/libraries/Chunked_uploader.php +++ b/application/libraries/Chunked_uploader.php @@ -329,7 +329,7 @@ class Chunked_upload_request { private $_file_type; // mime-type of file /** - * Initialises new object with values from the $_REQUEST and + * Initialises new object with values from the $_REQUEST and * $_SERVER arrays */ @@ -344,25 +344,33 @@ public function __construct() $this->_file_type = isset($_SERVER['HTTP_X_FILE_TYPE']) ? $_SERVER['HTTP_X_FILE_TYPE'] : ''; + + // @TODO: Fatal error: Unparenthesized 'a ? b : c ? d : e' is not supported. + // Use either '(a ? b : c) ? d : e' or 'a ? b : (c ? d : e) // attempt to get file name from $_REQUEST, otherwise look for X_FILE_NAME header $name = isset($_REQUEST["name"]) ? $_REQUEST["name"] - : (isset($_SERVER['HTTP_X_FILE_NAME']) + : ( + (isset($_SERVER['HTTP_X_FILE_NAME']) ? $_SERVER['HTTP_X_FILE_NAME'] - : 'file'); + : 'file') + ); + // clean the filename for security $this->_name = preg_replace('/[^\w\._]+/', '_', $name); // attempt to get the content-type from $_SERVER array $this->_content_type = (isset($_SERVER["HTTP_CONTENT_TYPE"])) ? $_SERVER["HTTP_CONTENT_TYPE"] - : (isset($_SERVER["CONTENT_TYPE"])) + : ( + (isset($_SERVER["CONTENT_TYPE"])) ? $_SERVER["CONTENT_TYPE"] - : ''; + : '' + ); } /** * Returns the original filename (from client machine) - * @return string file name + * @return string file name */ public function get_name() { @@ -426,4 +434,4 @@ public function is_multipart() } /* End of file Chunked_uploader.php */ -/* Location: /sparks/chunked_uploader/0.0.1/libraries/Chunked_uploader.php */ \ No newline at end of file +/* Location: /sparks/chunked_uploader/0.0.1/libraries/Chunked_uploader.php */ diff --git a/application/views/catalog/batch_file_upload.php b/application/views/catalog/batch_file_upload.php index fe37534f5..24b9bbb49 100644 --- a/application/views/catalog/batch_file_upload.php +++ b/application/views/catalog/batch_file_upload.php @@ -6,8 +6,7 @@ // Convert divs to queue widgets when the DOM is ready $(function() { - function log() - { + function log() { } $("#uploader").pluploadQueue({ @@ -21,9 +20,11 @@ function log() multipart_params: { 'upload_folder': 'default', 'overwrite':0}, // Specify what files to browse for - filters : [ + filters : { + mime_types: [ {title : "External Resources", extensions : ""} - ], + ] + }, // Flash settings flash_swf_url : 'javascript/plupload/js/Moxie.swf', @@ -79,12 +80,12 @@ function log() FileUploaded: function(up, file, info) { // Called when a file has finished uploading - //console.log('[FileUploaded] File:', file, "Info:", info); + console.log('[FileUploaded] File:', file, "Info:", info); }, ChunkUploaded: function(up, file, info) { // Called when a file chunk has finished uploading - //log('[ChunkUploaded] File:', file, "Info:", info); + log('[ChunkUploaded] File:', file, "Info:", info); }, UploadComplete: function (up, file) { diff --git a/application/views/catalog/ddi_batch_import.php b/application/views/catalog/ddi_batch_import.php index 442b09f51..33c9a890b 100644 --- a/application/views/catalog/ddi_batch_import.php +++ b/application/views/catalog/ddi_batch_import.php @@ -15,12 +15,12 @@ } ?> -'xml,rdf', - 'destination_url' =>'admin/catalog/batch_import', - 'upload_url' =>'admin/catalog/process_batch_uploads' + 'destination_url' =>'admin/catalog/batch_import', + 'upload_url' =>'admin/catalog/process_batch_uploads' ); $batch_uploader=$this->load->view('catalog/batch_file_upload',$batch_upload_options,TRUE); ?> @@ -34,30 +34,31 @@
-
+
config->item('ddi_import_folder'));?>
-
- +
- +
-
- +
+
@@ -66,7 +67,7 @@ @@ -103,90 +104,92 @@ $(".log").css({ border: '1px solid gray'}); var batch_import = { - + id:null, queue:[], queue_idx:0, xhr:null, isprocessing:false, - + process : function() { - + if (this.isprocessing==true){ return false; } - + this.queue_idx=0; this.queue=[]; obj=this; var i=0; - $('.chk').each(function(){ + $('.chk').each(function(){ if (this.checked==true) { obj.queue[i++]={id:this.id,name:this.value}; } - }); + }); html=$("#batch-import-box").html(); $("#batch-import-log").html(""); this.process_queue(); }, - + //process items in queue process_queue: function(){ - if (this.queue_idx['+this.queue[this.queue_idx].name+']'; html+=' ' +i18n.cancel_import_process+''; $("#batch-import-box").show(); $("#batch-import-processing").html(html); - + this.isprocessing=true; - this.import_single(this.queue[this.queue_idx++].id); + this.import_single(this.queue[this.queue_idx++].id); } else{ $("#batch-import-processing").html(i18n.import_completed); this.isprocessing=false; } - + }, - + import_single: function(id) { obj=this; //set error hanlder $.ajaxSetup({ - error:function(x,e){ + error:function(x,e){ alert("Error code: " + x.status + " " + x.responseText); obj.abort(); } - }); - + }); + var overwrite=0; var repositoryid=null; if ($("#overwrite").is(":checked")){overwrite=1} repositoryid=$("#repositoryid").val(); - //post + //post this.xhr=$.post(CI.base_url+"/admin/catalog/do_batch_import",{id:id,overwrite:overwrite,repositoryid:repositoryid},func_data, "json"); - + //handle json returned values function func_data(data){ if (data.success){ obj.queue[obj.queue_idx-1].status=data.success; - $("#batch-import-log").append('
#' + (obj.queue_idx) + ': ' + obj.queue[obj.queue_idx-1].name + ' - ' + data.success+ '
'); + // $("#batch-import-log").append('
#' + (obj.queue_idx) + ': ' + obj.queue[obj.queue_idx-1].name + ' - ' + data.success+ '
'); + $("#batch-import-log").append('
#' + (obj.queue_idx) + ': ' + obj.queue[obj.queue_idx-1].name + ' - ' + data.success+ '
'); } else{ obj.queue[obj.queue_idx-1].status=data.error; - $("#batch-import-log").append('
#' + (obj.queue_idx) + ': ' + obj.queue[obj.queue_idx-1].name + ' - ' + data.error+ '
'); + //$("#batch-import-log").append('
#' + (obj.queue_idx) + ': ' + obj.queue[obj.queue_idx-1].name + ' - ' + data.error+ '
'); + $("#batch-import-log").append('
#' + (obj.queue_idx) + ': ' + obj.queue[obj.queue_idx-1].name + ' - ' + data.error+ '
'); } obj.process_queue(); }//end-func }, - + abort: function(){ $("#batch-import-processing").html(i18n.import_cancelled); this.xhr.abort(); this.isprocessing=false; - } + } }; From 670ce18b29a1d92169596ae498cf39759a302631 Mon Sep 17 00:00:00 2001 From: ch-ricardor Date: Wed, 16 Nov 2022 11:13:23 +0100 Subject: [PATCH 4/5] Chunk Uploader merge --- application/libraries/Chunked_uploader.php | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/application/libraries/Chunked_uploader.php b/application/libraries/Chunked_uploader.php index 4880a2c75..a5d658bd1 100644 --- a/application/libraries/Chunked_uploader.php +++ b/application/libraries/Chunked_uploader.php @@ -359,21 +359,11 @@ public function __construct() // clean the filename for security $this->_name = preg_replace('/[^\w\._]+/', '_', $name); // attempt to get the content-type from $_SERVER array -<<<<<<< HEAD - $this->_content_type = (isset($_SERVER["HTTP_CONTENT_TYPE"])) - ? $_SERVER["HTTP_CONTENT_TYPE"] - : ( - (isset($_SERVER["CONTENT_TYPE"])) - ? $_SERVER["CONTENT_TYPE"] - : '' - ); -======= $this->_content_type = (isset($_SERVER["HTTP_CONTENT_TYPE"])) ? $_SERVER["HTTP_CONTENT_TYPE"]: ''; if ($this->_content_type==''){ $this->_content_type=(isset($_SERVER["CONTENT_TYPE"])) ? $_SERVER["CONTENT_TYPE"]: ''; } ->>>>>>> 98c5587e4833f56a75e39c8fa7fd5be5b9471044 } /** From fe0e145ee47af709590cc7e6885f435eef69dc7a Mon Sep 17 00:00:00 2001 From: ch-ricardor Date: Fri, 18 Nov 2022 11:50:26 +0100 Subject: [PATCH 5/5] Batch Upload Add Study Bootstrap Clean uploaded files --- application/controllers/admin/Catalog.php | 42 +++++++++---- .../views/catalog/ddi_batch_import.php | 59 ++++++++++++++----- application/views/catalog/ddi_upload_form.php | 20 +++++-- application/views/catalog/edit_study.php | 19 +++--- application/views/catalog/index.php | 18 +++++- 5 files changed, 115 insertions(+), 43 deletions(-) diff --git a/application/controllers/admin/Catalog.php b/application/controllers/admin/Catalog.php index f452149a4..f86f50548 100644 --- a/application/controllers/admin/Catalog.php +++ b/application/controllers/admin/Catalog.php @@ -64,12 +64,16 @@ public function __construct() */ function index() { + // @TODO: Confirm Cleaning of Erros and Messages from previous Forms + $this->session->unset_userdata('error'); + $this->session->unset_userdata('message'); + $this->template->set_template('admin5'); //css files $inline_styles=$this->load->view('catalog/catalog_style',NULL, TRUE); - - $this->template->add_css($inline_styles,'embed'); - + + $this->template->add_css($inline_styles,'embed'); + //js files $this->template->add_js('var site_url="'.site_url().'";','embed'); $this->template->add_js('javascript/catalog_admin.js'); @@ -317,7 +321,6 @@ function upload() if ($this->form_validation->run() == FALSE) { $this->template->set_template('admin'); - $content=$this->load->view('catalog/ddi_upload_form', array('active_repo'=>$this->active_repo),true); $this->template->write('content', $content,true); $this->template->render(); @@ -328,6 +331,7 @@ function upload() if (!empty($new_survey)){ // RRE Clear Errors + // @TODO: Review if messages should be unset too $this->session->unset_userdata('error'); //redirect('admin/catalog/edit/'.$result['sid'],'refresh'); redirect('admin/catalog/edit/'.$new_survey,'refresh'); @@ -389,6 +393,7 @@ function add_study() } // Uploads the xml File + // @TODO: review if the file should reamin in the directory after the process is executed $temp_upload_folder=$this->get_temp_upload_folder(); //upload class configurations for DDI @@ -399,7 +404,7 @@ function add_study() $this->load->library('upload', $config); - + // @TODO: Review ONLY XML file is in this reference, RDF files ? or XML RDF pair? $ddi_upload_result=$this->upload->do_upload('userfile'); $uploaded_ddi_path=NULL; @@ -434,7 +439,7 @@ function add_study() 'overwrite'=>$overwrite ); - try{ + try { //import ddi $result=$this->ddi2_import->import($params); @@ -448,27 +453,38 @@ function add_study() return $result['sid']; } // @TODO: Find how to replicate this error - catch(ValidationException $e){ + catch (ValidationException $e){ $error_output=array( 'status'=>'failed', 'message'=>$e->getMessage(), 'errors'=>$e->GetValidationErrors() ); - $error_str='Validation Error
'.print_r($e->GetValidationErrors(),true).'
'; +// RRE @TODO: Multiple errors in the xml validation + // $error_str='Validation Error
'.print_r($e->GetValidationErrors(),true).'
'; + $arr_errors=$e->GetValidationErrors(); + $error_str='Validation Error
';
+			foreach ($arr_errors as $key_error) {
+				$error_str.=$key_error['message'].'
'; + } + $error_str.='
'; $this->session->set_flashdata('error', $error_str); //redirect('admin/catalog/add_study','refresh');return; //redirect('admin/catalog/upload','refresh'); - // @TODO: Find how to replicate this error -return; + return NULL; } - catch(Exception $e){ + catch (Exception $e){ $this->session->set_flashdata('error', $e->getMessage()); //redirect('admin/catalog/add_study','refresh');return; //redirect('admin/catalog/upload','refresh'); return NULL; } + finally { + // @TODO: Review if this is OK. + unlink($ddi_path); + + } } @@ -556,7 +572,7 @@ private function __replace_ddi($sid,$new_ddi_file) if ($new_idno!==$this->sanitize_filename($new_idno)){ throw new Exception(t('IDNO_INVALID_FORMAT').': '.$new_idno); } - + //check if the study already exists, find the sid $new_ddi_sid=$this->dataset_manager->find_by_idno($new_idno); @@ -801,6 +817,8 @@ function batch_import() if (!file_exists($import_folder) ){ // @TODO: Review datasets directory does not exist either + // @TODO: Review if this default should set config->item('ddi_import_folder') + // The next calls to config->item('ddi_import_folder') will fail if this is not set. // $import_folder="/datasets"; $import_folder="/datafiles/tmp"; } diff --git a/application/views/catalog/ddi_batch_import.php b/application/views/catalog/ddi_batch_import.php index 33c9a890b..1b830d015 100644 --- a/application/views/catalog/ddi_batch_import.php +++ b/application/views/catalog/ddi_batch_import.php @@ -27,15 +27,33 @@
-session->flashdata('error');?> -'.$error.'
' : '';?> +session->flashdata('error'); ?> + +
+ +
+ + +session->flashdata('message');?> + +
+ +
+

-
- config->item('ddi_import_folder'));?> +
+ + config->item('ddi_import_folder'));?>
@@ -58,7 +76,7 @@ @@ -73,7 +91,7 @@
- +
@@ -94,7 +112,7 @@ diff --git a/application/views/catalog/ddi_upload_form.php b/application/views/catalog/ddi_upload_form.php index ad75e6832..a71d2c386 100644 --- a/application/views/catalog/ddi_upload_form.php +++ b/application/views/catalog/ddi_upload_form.php @@ -24,11 +24,23 @@
-session->flashdata('error');?> -'.$error.'
' : '';?> +session->flashdata('error'); ?> + +
+ +
+session->flashdata('message');?> -'.$message.'' : '';?> + +
+ +
+ @@ -69,7 +81,7 @@

- +
diff --git a/application/views/catalog/edit_study.php b/application/views/catalog/edit_study.php index 6ae35a347..d144d6bb1 100644 --- a/application/views/catalog/edit_study.php +++ b/application/views/catalog/edit_study.php @@ -52,8 +52,8 @@ function toggle(element){ //study publish/unpublish $(document.body).on("click","#survey .publish, .survey-publish .publish", function(){ var studyid=$(this).attr("data-sid"); - if ($(this).attr("data-value")==0){ - $this=this; + if ($(this).attr("data-value")==0){ + $this=this; $.post(CI.base_url+'/admin/catalog/publish/'+studyid+'/1?ajax=1', {submit:"submit"}, function( data ) { $($this).attr("data-value",1); $($this).html(""); @@ -65,7 +65,7 @@ function toggle(element){ }); } else{ - $this=this; + $this=this; $.post(CI.base_url+'/admin/catalog/publish/'+studyid+'/0?ajax=1', {submit:"submit"}, function( data ) { $($this).html(""); $($this).attr("data-value",0); @@ -617,13 +617,16 @@ function set_data_access_display(el)
- -session->flashdata('error');?> -'.$error.'
' : '';?> + +
+ + +
+ session->flashdata('message');?> -
+
@@ -637,7 +640,7 @@ function set_data_access_display(el)
- +

diff --git a/application/views/catalog/index.php b/application/views/catalog/index.php index a7291ac52..36997effb 100644 --- a/application/views/catalog/index.php +++ b/application/views/catalog/index.php @@ -11,11 +11,23 @@
load->view('catalog/catalog_page_links');?> -session->flashdata('error');?> -'.$error.'
' : '';?> +session->flashdata('error'); ?> + +
+ +
+ session->flashdata('message');?> -'.$message.'
' : '';?> + +
+ +
+