diff --git a/application/config/form_validation.php b/application/config/form_validation.php index 2a24c08..116dff5 100644 --- a/application/config/form_validation.php +++ b/application/config/form_validation.php @@ -36,6 +36,44 @@ $config['auth/forgot_password'] = array( ), ); +/** +* Rules for the settings page. +* +* @var array +*/ +$config['auth/settings'] = array( + array( + 'field' => 'firstname', + 'label' => _('First name'), + 'rules' => 'required|max_length[50]|trim', + ), + array( + 'field' => 'lastname', + 'label' => _('Last name'), + 'rules' => 'required|max_length[50]|trim', + ), + array( + 'field' => 'email', + 'label' => _('Email address'), + 'rules' => 'required|valid_email|trim', + ), + array( + 'field' => 'institution', + 'label' => _('Institution'), + 'rules' => 'max_length[100]|trim', + ), + array( + 'field' => 'phone', + 'label' => _('Phone number'), + 'rules' => 'regex_match[/^\+\d{2,4}\s\d{2,4}\s\d{3,10}+$/i]|trim', + ), + array( + 'field' => 'new_password', + 'label' => _('New password'), + 'rules' => 'min_length[6]|matches[new_password_confirm]', + ), +); + /** * Rules for creating users. * @@ -131,40 +169,35 @@ $config['programs/edit'] = array( ); /** - * Rules for the settings page. + * Rules for creating parameters. * * @var array */ -$config['auth/settings'] = array( +$config['parameters/create'] = array( array( - 'field' => 'firstname', - 'label' => _('First name'), - 'rules' => 'required|max_length[50]|trim', + 'field' => 'name', + 'label' => _('Name'), + 'rules' => 'required|max_length[255]|trim', ), array( - 'field' => 'lastname', - 'label' => _('Last name'), - 'rules' => 'required|max_length[50]|trim', + 'field' => 'readable', + 'label' => _('Human-readable name'), + 'rules' => 'required|max_length[100]|trim', ), array( - 'field' => 'email', - 'label' => _('Email address'), - 'rules' => 'required|valid_email|trim', + 'field' => 'unit', + 'label' => _('Name'), + 'rules' => 'max_length[20]|trim', ), array( - 'field' => 'institution', - 'label' => _('Institution'), - 'rules' => 'max_length[100]|trim', + 'field' => 'default_value', + 'label' => _('Default value'), + 'rules' => 'max_length[255]|trim', ), array( - 'field' => 'phone', - 'label' => _('Phone number'), - 'rules' => 'regex_match[/^\+\d{2,4}\s\d{2,4}\s\d{3,10}+$/i]|trim', - ), - array( - 'field' => 'new_password', - 'label' => _('New password'), - 'rules' => 'min_length[6]|matches[new_password_confirm]', + 'field' => 'type', + 'label' => _('Type'), + 'rules' => 'required|max_length[20]|trim', ), ); diff --git a/application/controllers/admin/parameters.php b/application/controllers/admin/parameters.php new file mode 100644 index 0000000..ca4289f --- /dev/null +++ b/application/controllers/admin/parameters.php @@ -0,0 +1,133 @@ + + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +require_once APPPATH . 'core/Admin_Controller.php'; + +/** + * + * @author Eike Foken + */ +class Parameters extends Admin_Controller { + + /** + * Calls the parent constructor. + */ + public function __construct() { + parent::__construct(); + $this->load->model('parameter'); + $this->load->model('program'); + } + + /** + * Allows admins to create a new parameter. + * + * @param string $programId + */ + public function create($programId = '') { + $program = $this->program->getByID($programId); + + if (empty($programId) || !isset($program['id'])) { + show_404(); + } + + if ($this->form_validation->run('parameters/create') === true) { + $paramName = $this->input->post('name'); + + $data = array( + 'program_id' => $program['id'], + 'name' => $paramName, + 'readable' => $this->input->post('readable'), + 'unit' => $this->input->post('unit'), + 'description' => $this->input->post('description'), + 'type' => $this->input->post('type'), + 'default_value' => $this->input->post('default_value'), + ); + + if ($this->parameter->create($data)) { + $this->messages->add(sprintf(_("The parameter '%s' has been successfully created."), $paramName), 'success'); + redirect('admin/programs/edit/' . $program['id'], 303); + } + } + + $data = array(); // empty the data array + $data['types'] = $this->parameter->getTypes(); + $data['program'] = $program; + + $this->load->view('admin/parameters/create', $data); + } + + /** + * Allows admins to edit a parameter. + * + * @param string $id + */ + public function edit($id = '') { + $parameter = $this->parameter->getByID($id); + + if (empty($id) || !isset($parameter['id'])){ + show_404(); + } + + if ($this->form_validation->run('parameters/create') === true) { + $data = array( + 'name' => $this->input->post('name'), + 'readable' => $this->input->post('readable'), + 'unit' => $this->input->post('unit'), + 'description' => $this->input->post('description'), + 'type' => $this->input->post('type'), + 'default_value' => $this->input->post('default_value'), + ); + + if ($this->parameter->update($data, $id)) { + $this->messages->add(sprintf(_("The parameter '%s' has been successfully updated."), $parameter['name']), 'success'); + redirect('admin/programs/edit/' . $parameter['program_id'], 303); + } + } + + $data = array(); // empty the data array + $data['types'] = $this->parameter->getTypes(); + $data['parameter'] = $parameter; + + $this->load->view('admin/parameters/edit', $data); + } + + /** + * Allows admins to delete a parameter. + * + * @param string $id + */ + public function delete($id = '') { + $parameter = $this->parameter->getByID($id); + + if (empty($id) || !isset($parameter['id'])) { + show_404(); + } else { + if ($this->parameter->delete($parameter['id'])) { + $this->messages->add(_('The selected parameter has been successfully deleted.'), 'success'); + } + redirect('admin/programs/edit/' . $parameter['program_id'], 303); + } + } +} + +/* End of file parameters.php */ +/* Location: ./application/controllers/admin/parameters.php */ diff --git a/application/controllers/admin/programs.php b/application/controllers/admin/programs.php index c7703c0..f613959 100644 --- a/application/controllers/admin/programs.php +++ b/application/controllers/admin/programs.php @@ -13,6 +13,7 @@ class Programs extends CI_Controller { parent::__construct(); $this->load->library('form_validation'); $this->load->model('program'); + $this->load->model('parameter'); } /** @@ -43,8 +44,9 @@ class Programs extends CI_Controller { } $data['program'] = $program; - $data['parameters'] = $this->program->getParameters($program['id']); + $data['parameters'] = $this->parameter->getAll($program['id']); $this->load->view('admin/programs/edit', $data); } + } \ No newline at end of file diff --git a/application/models/program.php b/application/models/program.php index 2a1e9d8..905979e 100644 --- a/application/models/program.php +++ b/application/models/program.php @@ -119,19 +119,9 @@ class Program extends CI_Model { * @return array The parameters */ public function getParameters($id) { - $query = $this->db->order_by('order ASC') + $query = $this->db->order_by('sort_number ASC') ->get_where('parameters', array('program_id' => $id)); return $query->result_array(); } - - /** - * - * @param string $programId - */ - public function sortParameters($order, $programId) { - foreach ($order as $key => $value) { - $this->db->update('parameters', array('order' => $key), array('id' => $value)); - } - } } diff --git a/application/views/admin/parameters/create.php b/application/views/admin/parameters/create.php new file mode 100644 index 0000000..2aca436 --- /dev/null +++ b/application/views/admin/parameters/create.php @@ -0,0 +1,73 @@ +load->view('header');?> + +
+ +
+

+
+ +
+
+
    +
  • + + * +
    + + +
    +
  • +
  • + + * +
    + + +
    +
  • +
  • + +
    + + +
    +
  • +
  • + +
    + + +
    +
  • +
  • + + * +
    + + +
    +
  • +
  • + +
    + + +
    +
  • +
+

+ +

+
+
+
+ +load->view('footer');?> \ No newline at end of file diff --git a/application/views/admin/parameters/edit.php b/application/views/admin/parameters/edit.php new file mode 100644 index 0000000..1c233b4 --- /dev/null +++ b/application/views/admin/parameters/edit.php @@ -0,0 +1,74 @@ +load->view('header');?> + +
+ +
+

+
+ +
+
+
    +
  • + + * +
    + + +
    +
  • +
  • + + * +
    + + +
    +
  • +
  • + +
    + + +
    +
  • +
  • + +
    + + +
    +
  • +
  • + + * +
    + + +
    +
  • +
  • + +
    + + +
    +
  • +
+

+ + +

+
+
+
+ +load->view('footer');?> \ No newline at end of file diff --git a/application/views/admin/programs/edit.php b/application/views/admin/programs/edit.php index a713d62..825665b 100644 --- a/application/views/admin/programs/edit.php +++ b/application/views/admin/programs/edit.php @@ -4,11 +4,7 @@ $(document).ready(function() { $('#parameters').tableDnD({ onDrop: function(table, row) { - /*var rows = table.tBodies[0].rows; - for (var i = 0; i < rows.length; i++) { - $(rows[i]).children().find('input[type=hidden]').val(i + 1); - }*/ - $.post(SITE_URL + 'ajax/sort_parameters/', $.tableDnD.serialize()); + $.post(SITE_URL + 'ajax/sort_parameters', $.tableDnD.serialize()); }, dragHandle: 'drag_handle' }); @@ -61,7 +57,7 @@ $(document).ready(function() { - | + |

- +

diff --git a/application/views/admin/programs/list.php b/application/views/admin/programs/list.php index e4f091f..19f9e1f 100644 --- a/application/views/admin/programs/list.php +++ b/application/views/admin/programs/list.php @@ -29,7 +29,7 @@ -

+