From bee61fd0176fdda767754c92e82a6f2df0bfc660 Mon Sep 17 00:00:00 2001 From: Karsten Heiken Date: Sun, 16 Oct 2011 15:31:23 +0200 Subject: [PATCH] Implement creation of servers --- application/config/form_validation.php | 35 ++++++++++++- application/controllers/admin/servers.php | 40 +++++++++++++++ application/models/server.php | 6 ++- application/views/admin/servers/create.php | 58 ++++++++++++++++++++++ application/views/admin/servers/list.php | 6 +++ 5 files changed, 143 insertions(+), 2 deletions(-) create mode 100644 application/views/admin/servers/create.php 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');?> + +
+ +
+

»

+
+ +
+
+

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

+ + +

+
+
+
+ +load->view('footer');?> diff --git a/application/views/admin/servers/list.php b/application/views/admin/servers/list.php index 344ea08..21f332f 100644 --- a/application/views/admin/servers/list.php +++ b/application/views/admin/servers/list.php @@ -8,6 +8,7 @@

+ @@ -48,6 +49,11 @@ ?>
+ +

+ 'button add'));?> +

+