Implement program parameter management
This commit is contained in:
@@ -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.
|
* Rules for creating users.
|
||||||
*
|
*
|
||||||
@@ -131,40 +169,35 @@ $config['programs/edit'] = array(
|
|||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rules for the settings page.
|
* Rules for creating parameters.
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
$config['auth/settings'] = array(
|
$config['parameters/create'] = array(
|
||||||
array(
|
array(
|
||||||
'field' => 'firstname',
|
'field' => 'name',
|
||||||
'label' => _('First name'),
|
'label' => _('Name'),
|
||||||
'rules' => 'required|max_length[50]|trim',
|
'rules' => 'required|max_length[255]|trim',
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'field' => 'lastname',
|
'field' => 'readable',
|
||||||
'label' => _('Last name'),
|
'label' => _('Human-readable name'),
|
||||||
'rules' => 'required|max_length[50]|trim',
|
'rules' => 'required|max_length[100]|trim',
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'field' => 'email',
|
'field' => 'unit',
|
||||||
'label' => _('Email address'),
|
'label' => _('Name'),
|
||||||
'rules' => 'required|valid_email|trim',
|
'rules' => 'max_length[20]|trim',
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'field' => 'institution',
|
'field' => 'default_value',
|
||||||
'label' => _('Institution'),
|
'label' => _('Default value'),
|
||||||
'rules' => 'max_length[100]|trim',
|
'rules' => 'max_length[255]|trim',
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'field' => 'phone',
|
'field' => 'type',
|
||||||
'label' => _('Phone number'),
|
'label' => _('Type'),
|
||||||
'rules' => 'regex_match[/^\+\d{2,4}\s\d{2,4}\s\d{3,10}+$/i]|trim',
|
'rules' => 'required|max_length[20]|trim',
|
||||||
),
|
|
||||||
array(
|
|
||||||
'field' => 'new_password',
|
|
||||||
'label' => _('New password'),
|
|
||||||
'rules' => 'min_length[6]|matches[new_password_confirm]',
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
133
application/controllers/admin/parameters.php
Normal file
133
application/controllers/admin/parameters.php
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2011 Eike Foken <kontakt@eikefoken.de>
|
||||||
|
*
|
||||||
|
* 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 <kontakt@eikefoken.de>
|
||||||
|
*/
|
||||||
|
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 */
|
||||||
@@ -13,6 +13,7 @@ class Programs extends CI_Controller {
|
|||||||
parent::__construct();
|
parent::__construct();
|
||||||
$this->load->library('form_validation');
|
$this->load->library('form_validation');
|
||||||
$this->load->model('program');
|
$this->load->model('program');
|
||||||
|
$this->load->model('parameter');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -43,8 +44,9 @@ class Programs extends CI_Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$data['program'] = $program;
|
$data['program'] = $program;
|
||||||
$data['parameters'] = $this->program->getParameters($program['id']);
|
$data['parameters'] = $this->parameter->getAll($program['id']);
|
||||||
|
|
||||||
$this->load->view('admin/programs/edit', $data);
|
$this->load->view('admin/programs/edit', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -119,19 +119,9 @@ class Program extends CI_Model {
|
|||||||
* @return array The parameters
|
* @return array The parameters
|
||||||
*/
|
*/
|
||||||
public function getParameters($id) {
|
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));
|
->get_where('parameters', array('program_id' => $id));
|
||||||
|
|
||||||
return $query->result_array();
|
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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
73
application/views/admin/parameters/create.php
Normal file
73
application/views/admin/parameters/create.php
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
<?php $this->load->view('header');?>
|
||||||
|
|
||||||
|
<div id="content">
|
||||||
|
|
||||||
|
<div class="title">
|
||||||
|
<h2><?=_('Add a new parameter');?></h2>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="box">
|
||||||
|
<form name="addParameter" method="post" action="<?=site_url('admin/parameters/create/' . $program['id']);?>">
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<?=form_label(_('Name'), 'name');?>
|
||||||
|
<span class="req">*</span>
|
||||||
|
<div>
|
||||||
|
<input type="text" name="name" id="name" class="short text" value="<?=set_value('name');?>" />
|
||||||
|
<?=form_error('name');?>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<?=form_label(_('Human-readable name'), 'readable');?>
|
||||||
|
<span class="req">*</span>
|
||||||
|
<div>
|
||||||
|
<input type="text" name="readable" id="readable" class="medium text" value="<?=set_value('readable');?>" />
|
||||||
|
<?=form_error('readable');?>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<?=form_label(_('Unit'), 'unit');?>
|
||||||
|
<div>
|
||||||
|
<input type="text" name="unit" id="unit" class="short text" value="<?=set_value('unit');?>" />
|
||||||
|
<?=form_error('unit');?>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<?=form_label(_('Description'), 'description');?>
|
||||||
|
<div>
|
||||||
|
<textarea name="description" id="description" rows="6" cols="60" class="textarea"><?=set_value('description');?></textarea>
|
||||||
|
<?=form_error('description');?>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<?=form_label(_('Type'), 'type');?>
|
||||||
|
<span class="req">*</span>
|
||||||
|
<div>
|
||||||
|
<select name="type" id="type" class="drop">
|
||||||
|
<?php
|
||||||
|
foreach ($types as $type):
|
||||||
|
?>
|
||||||
|
<option value="<?=$type;?>" <?=set_select('type', $type);?>><?=$type;?></option>
|
||||||
|
<?php
|
||||||
|
endforeach;
|
||||||
|
?>
|
||||||
|
</select>
|
||||||
|
<?=form_error('type');?>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<?=form_label(_('Default value'), 'default_value');?>
|
||||||
|
<div>
|
||||||
|
<input type="text" name="default_value" id="default_value" class="short text" value="<?=set_value('default_value');?>" />
|
||||||
|
<?=form_error('default_value');?>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
<p>
|
||||||
|
<a class="button save" href="javascript:void(0);" onclick="$('form[name=addParameter]').submit();"><?=_('Save');?></a>
|
||||||
|
</p>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php $this->load->view('footer');?>
|
||||||
74
application/views/admin/parameters/edit.php
Normal file
74
application/views/admin/parameters/edit.php
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
<?php $this->load->view('header');?>
|
||||||
|
|
||||||
|
<div id="content">
|
||||||
|
|
||||||
|
<div class="title">
|
||||||
|
<h2><?php printf(_("Edit parameter '%s'"), $parameter['name']);?></h2>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="box">
|
||||||
|
<form name="editParameter" method="post" action="<?=site_url('admin/parameters/edit/' . $parameter['id']);?>">
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<?=form_label(_('Name'), 'name');?>
|
||||||
|
<span class="req">*</span>
|
||||||
|
<div>
|
||||||
|
<input type="text" name="name" id="name" class="short text" value="<?=set_value('name', $parameter['name']);?>" />
|
||||||
|
<?=form_error('name');?>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<?=form_label(_('Human-readable name'), 'readable');?>
|
||||||
|
<span class="req">*</span>
|
||||||
|
<div>
|
||||||
|
<input type="text" name="readable" id="readable" class="medium text" value="<?=set_value('readable', $parameter['readable']);?>" />
|
||||||
|
<?=form_error('readable');?>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<?=form_label(_('Unit'), 'unit');?>
|
||||||
|
<div>
|
||||||
|
<input type="text" name="unit" id="unit" class="short text" value="<?=set_value('unit', $parameter['unit']);?>" />
|
||||||
|
<?=form_error('unit');?>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<?=form_label(_('Description'), 'description');?>
|
||||||
|
<div>
|
||||||
|
<textarea name="description" id="description" rows="6" cols="60" class="textarea"><?=set_value('description', $parameter['description']);?></textarea>
|
||||||
|
<?=form_error('description');?>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<?=form_label(_('Type'), 'type');?>
|
||||||
|
<span class="req">*</span>
|
||||||
|
<div>
|
||||||
|
<select name="type" id="type" class="drop">
|
||||||
|
<?php
|
||||||
|
foreach ($types as $type):
|
||||||
|
?>
|
||||||
|
<option value="<?=$type;?>" <?=set_select('type', $type, $parameter['type'] == $type);?>><?=$type;?></option>
|
||||||
|
<?php
|
||||||
|
endforeach;
|
||||||
|
?>
|
||||||
|
</select>
|
||||||
|
<?=form_error('type');?>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<?=form_label(_('Default value'), 'default_value');?>
|
||||||
|
<div>
|
||||||
|
<input type="text" name="default_value" id="default_value" class="short text" value="<?=set_value('default_value', $parameter['default_value']);?>" />
|
||||||
|
<?=form_error('default_value');?>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
<p>
|
||||||
|
<a class="button save" href="javascript:void(0);" onclick="$('form[name=editParameter]').submit();"><?=_('Save');?></a>
|
||||||
|
<a class="button cancel" href="<?=site_url('admin/programs/edit/' . $parameter['program_id']);?>"><?=_('Cancel');?></a>
|
||||||
|
</p>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php $this->load->view('footer');?>
|
||||||
@@ -4,11 +4,7 @@
|
|||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
$('#parameters').tableDnD({
|
$('#parameters').tableDnD({
|
||||||
onDrop: function(table, row) {
|
onDrop: function(table, row) {
|
||||||
/*var rows = table.tBodies[0].rows;
|
$.post(SITE_URL + 'ajax/sort_parameters', $.tableDnD.serialize());
|
||||||
for (var i = 0; i < rows.length; i++) {
|
|
||||||
$(rows[i]).children().find('input[type=hidden]').val(i + 1);
|
|
||||||
}*/
|
|
||||||
$.post(SITE_URL + 'ajax/sort_parameters/<?=$program['id'];?>', $.tableDnD.serialize());
|
|
||||||
},
|
},
|
||||||
dragHandle: 'drag_handle'
|
dragHandle: 'drag_handle'
|
||||||
});
|
});
|
||||||
@@ -61,7 +57,7 @@ $(document).ready(function() {
|
|||||||
<td><?=$parameter['readable'];?></td>
|
<td><?=$parameter['readable'];?></td>
|
||||||
<td><?=$parameter['unit'];?></td>
|
<td><?=$parameter['unit'];?></td>
|
||||||
<td><?=$parameter['type'];?></td>
|
<td><?=$parameter['type'];?></td>
|
||||||
<td><?=anchor('admin/programs/edit_parameter/' . $parameter['id'], _('Edit'));?> | <a href="javascript:deleteConfirm('<?=site_url('admin/programs/delete_parameter/' . $parameter['id']);?>');"><?=_('Delete');?></a></td>
|
<td><?=anchor('admin/parameters/edit/' . $parameter['id'], _('Edit'));?> | <a href="javascript:deleteConfirm('<?=site_url('admin/parameters/delete/' . $parameter['id']);?>');"><?=_('Delete');?></a></td>
|
||||||
</tr>
|
</tr>
|
||||||
<?php
|
<?php
|
||||||
endforeach;
|
endforeach;
|
||||||
@@ -69,7 +65,7 @@ $(document).ready(function() {
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<p>
|
<p>
|
||||||
<a class="button add" href="<?=site_url('admin/programs/add_parameter');?>"><?=_('Add new parameter');?></a>
|
<a class="button add" href="<?=site_url('admin/parameters/create/' . $program['id']);?>"><?=_('Add new parameter');?></a>
|
||||||
</p>
|
</p>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -29,7 +29,7 @@
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<p><a class="button add" href="<?=site_url('admin/users/create')?>"><?=_('Create new user')?></a>
|
<p><a class="button add" href="<?=site_url('admin/programs/create')?>"><?=_('Add program')?></a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user