diff --git a/application/config/form_validation.php b/application/config/form_validation.php index 84dcddc..bea2c54 100644 --- a/application/config/form_validation.php +++ b/application/config/form_validation.php @@ -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 */ diff --git a/application/controllers/admin/servers.php b/application/controllers/admin/servers.php index 218a646..fea8dd1 100644 --- a/application/controllers/admin/servers.php +++ b/application/controllers/admin/servers.php @@ -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. * diff --git a/application/models/server.php b/application/models/server.php index 7af90e8..913d9ab 100644 --- a/application/models/server.php +++ b/application/models/server.php @@ -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; + } } /** diff --git a/application/views/admin/servers/create.php b/application/views/admin/servers/create.php new file mode 100644 index 0000000..ec2e514 --- /dev/null +++ b/application/views/admin/servers/create.php @@ -0,0 +1,58 @@ +load->view('header');?> + +
+ =anchor('/admin/servers/create', _('Create a new server'), array('class' => 'button add'));?> +
+