Implement creation of servers

This commit is contained in:
Karsten Heiken
2011-10-16 15:31:23 +02:00
parent 74cde75be8
commit bee61fd017
5 changed files with 143 additions and 2 deletions

View File

@@ -235,7 +235,40 @@ $config['parameters/create'] = array(
);
/**
* Rules for creating servers.
* Rules for creating servers.
*
* @var array
*/
$config['servers/create'] = array(
array(
'field' => 'id',
'label' => _('Name'),
'rules' => 'required|trim',
),
array(
'field' => 'secret',
'label' => _('Secret'),
'rules' => 'required|trim',
),
array(
'field' => 'description',
'label' => _('Description'),
'rules' => 'trim',
),
array(
'field' => 'location',
'label' => _('Location'),
'rules' => 'required|max_length[255]|trim',
),
array(
'field' => 'owner',
'label' => _('Owner'),
'rules' => 'required|alpha_numeric|trim',
),
);
/**
* Rules for editing servers.
*
* @var array
*/

View File

@@ -59,6 +59,46 @@ class Servers extends Admin_Controller {
$this->load->view('admin/servers/detail', $data);
}
/**
* Allows admins to create a server.
*
* @param string $serverId
*/
public function create() {
if ($this->form_validation->run('servers/create') === true) {
$data = array(
'id' => $this->input->post('id'),
'description' => $this->input->post('description'),
'location' => $this->input->post('location'),
'owner' => $this->input->post('owner'),
'secret' => $this->input->post('secret'),
);
if ($this->server->create($data))
redirect('admin/servers', 303);
else
$this->messages->add(_("Something went wrong with the action you performed."), 'error');
}
$data = array(); // empty data array
$data['users'] = array();
$users = $this->user->getAll();
foreach ($users as $user) {
$data['users'][$user['id']] = $user['firstname'] . ' ' . $user['lastname'];
}
// generate a secret
$data['secret'] = $this->input->post('secret');
if(empty($data['secret']))
$data['secret'] = sha1(uniqid());
$this->load->view('admin/servers/create', $data);
}
/**
* Allows admins to edit a server.
*

View File

@@ -34,7 +34,11 @@ class Server extends CI_Model {
* @return boolean Returns TRUE if the insert was successful.
*/
public function create($data) {
return $this->db->insert('servers', $data);
if ($this->db->insert('servers', $data)) {
return $data['id'];
} else {
return false;
}
}
/**

View File

@@ -0,0 +1,58 @@
<?php $this->load->view('header');?>
<div id="content">
<div class="title">
<h2><?=anchor('admin/servers', _('Servers'));?> &raquo; <?=_('Add new server');?></h2>
</div>
<div class="box">
<form name="createServer" method="post" action="<?=site_url('admin/servers/create/')?>">
<h3><?=_('Required information');?></h3>
<ul>
<li>
<?=form_label(_('Name'), 'id');?> <span class="req">*</span>
<div>
<input type="text" name="id" id="id" class="medium text" value="<?=set_value('id');?>" />
<?=form_error('id');?>
</div>
<label class="note">The preferred format is SP-OWNER-NUMBER, for example SP-JDOE-01</label>
</li>
<li>
<?=form_label(_('Location'), 'location');?> <span class="req">*</span>
<div>
<input type="text" name="location" id="location" class="medium text" value="<?=set_value('location');?>" />
<?=form_error('location');?>
</div>
</li>
<li>
<?=form_label(_('Owner'), 'owner');?> <span class="req">*</span>
<div>
<?=form_dropdown('owner', $users, 'id="owner" class="drop"');?>
</div>
</li>
<li>
<?=form_label(_('Description'), 'description');?> <span class="req">*</span>
<div>
<textarea name="description" id="description" rows="6" cols="60" class="textarea"><?=set_value('description');?></textarea>
<?=form_error('description');?>
</div>
</li>
<li>
<?=form_label(_('Secret'), 'secret');?> <span class="req">*</span>
<div>
<input type="text" readonly="readonly" name="secret" id="secret" class="medium text" value="<?=set_value('secret', $secret);?>" />
<?=form_error('secret');?>
</div>
<label class="note"><?=_('This secret later needs to be entered in the client. Copy this secret to your clipboard!')?></label>
</li>
</ul>
<p>
<a href="javascript:void(0);" onclick="$('form[name=createServer]').submit();" class="button save"><?=_('Save');?></a>
<a href="<?=site_url('admin/servers');?>" class="button cancel"><?=_('Cancel');?></a>
</p>
</form>
</div>
</div>
<?php $this->load->view('footer');?>

View File

@@ -8,6 +8,7 @@
<div class="box">
<h3><?=_('Available servers');?></h3>
<table class="tableList paginated">
<thead>
<tr>
@@ -48,6 +49,11 @@
?>
</tbody>
</table>
<p>
<?=anchor('/admin/servers/create', _('Create a new server'), array('class' => 'button add'));?>
</p>
</div>
</div>