diff --git a/application/controllers/admin/parameters.php b/application/controllers/admin/parameters.php
index affb569..133d222 100644
--- a/application/controllers/admin/parameters.php
+++ b/application/controllers/admin/parameters.php
@@ -76,6 +76,54 @@ class Parameters extends Admin_Controller {
$this->load->view('admin/parameters/create', $data);
}
+ /**
+ * Allows admins to upload a CSV file to create a bunch of parameters.
+ *
+ * @param string $programId
+ */
+ public function upload_csv($programId = '') {
+ $program = $this->program->getByID($programId);
+
+ if (empty($programId) || !isset($program['id'])) {
+ show_404();
+ }
+
+ if (count($_FILES) > 0) {
+ if ($_FILES['csv_file']['type'] == 'text/csv') {
+ $row = 1;
+ $inserted = 0;
+ $handler = fopen($_FILES['csv_file']['tmp_name'], "r");
+
+ while (($parameter = fgetcsv($handler, 1000, ',')) !== false) {
+ if ($row > 1) {
+ $data = array(
+ 'program_id' => $program['id'],
+ 'name' => $parameter[0],
+ 'readable' => $parameter[1],
+ 'unit' => $parameter[2],
+ 'type' => $parameter[3],
+ 'default_value' => $parameter[4],
+ 'description' => $parameter[5],
+ );
+
+ if ($this->parameter->create($data)) {
+ $inserted++;
+ }
+ }
+ $row++;
+ }
+
+ if ($inserted > 0) {
+ $this->messages->add(sprintf(_('%s parameters were successfully created.'), $inserted), 'success');
+ }
+ } else {
+ $this->messages->add(_('No CSV file specified.'), 'error');
+ }
+ }
+
+ redirect('admin/programs/edit/' . $program['id'], 303);
+ }
+
/**
* Allows admins to edit a parameter.
*
diff --git a/application/views/admin/programs/edit.php b/application/views/admin/programs/edit.php
index 825665b..ddf9f4e 100644
--- a/application/views/admin/programs/edit.php
+++ b/application/views/admin/programs/edit.php
@@ -20,7 +20,7 @@ $(document).ready(function() {
-
-
=_('Parameters');?>
-
-
-
- | |
- =_('Readable name');?> |
- =_('Unit');?> |
- =_('Type');?> |
- =_('Actions');?> |
-
-
-
+ =_('Parameters');?>
+
+
+
+ | |
+ =_('Readable name');?> |
+ =_('Unit');?> |
+ =_('Type');?> |
+ =_('Actions');?> |
+
+
+
-
- |
- =$parameter['readable'];?> |
- =$parameter['unit'];?> |
- =$parameter['type'];?> |
- =anchor('admin/parameters/edit/' . $parameter['id'], _('Edit'));?> | =_('Delete');?> |
-
+
+ |
+ =$parameter['readable'];?> |
+ =$parameter['unit'];?> |
+ =$parameter['type'];?> |
+ =anchor('admin/parameters/edit/' . $parameter['id'], _('Edit'));?> | =_('Delete');?> |
+
-
-
-
- =_('Add new parameter');?>
-
-
+
+
+
+ =_('Add new parameter');?>
+
+
+
diff --git a/assets/css/style.css b/assets/css/style.css
index e770c31..b32fb5b 100644
--- a/assets/css/style.css
+++ b/assets/css/style.css
@@ -423,6 +423,11 @@ a.save {
padding-left: 30px;
}
+a.upload {
+ background: url(../images/icons/drive-upload.png) 10px center no-repeat #f3f3f3;
+ padding-left: 30px;
+}
+
a.add {
background: url(../images/icons/plus-circle.png) 10px center no-repeat #f3f3f3;
padding-left: 30px;