diff --git a/application/config/form_validation.php b/application/config/form_validation.php index c02c222..84dcddc 100644 --- a/application/config/form_validation.php +++ b/application/config/form_validation.php @@ -234,6 +234,29 @@ $config['parameters/create'] = array( ), ); +/** + * Rules for creating servers. + * + * @var array + */ +$config['servers/edit'] = array( + array( + 'field' => 'description', + 'label' => _('Description'), + 'rules' => 'required|trim', + ), + array( + 'field' => 'location', + 'label' => _('Location'), + 'rules' => 'required|max_length[255]|trim', + ), + array( + 'field' => 'owner', + 'label' => _('Owner'), + 'rules' => 'required|alpha_numeric|trim', + ), +); + /** * Rules for creating projects. * diff --git a/application/controllers/admin/servers.php b/application/controllers/admin/servers.php index d39e648..218a646 100644 --- a/application/controllers/admin/servers.php +++ b/application/controllers/admin/servers.php @@ -30,33 +30,88 @@ require_once APPPATH . 'core/Admin_Controller.php'; class Servers extends Admin_Controller { /** - * Constructor. + * Calls the parent constructor. */ function __construct() { parent::__construct(); $this->load->model('server'); + $this->load->library('form_validation'); } /** - * List all servers. + * Lists all servers. */ function index() { - $tpl->servers = $this->server->getAll(); - - $this->load->view('admin/server/list', $tpl); + $this->load->view('admin/servers/list', array('servers' => $this->server->getAll())); } /** - * Retrieve details of a server. + * Shows details of a server. * - * @param type $server_id + * @param string $serverId */ - function detail($server_id) { - $tpl->server = $this->server->getById($server_id); + function detail($serverId) { + $this->load->helper('typography'); - $this->load->view('admin/server/detail', $tpl); + $data['server'] = $this->server->getById($serverId); + $data['owner'] = $this->user->getUserByID($data['server']->owner); + + $this->load->view('admin/servers/detail', $data); } + /** + * Allows admins to edit a server. + * + * @param string $serverId + */ + public function edit($serverId) { + $server = $this->server->getById($serverId); + + if (!isset($server) || !is_object($server)) { + show_404(); + } + + if ($this->form_validation->run('servers/edit') === true) { + $data = array( + 'description' => $this->input->post('description'), + 'location' => $this->input->post('location'), + 'owner' => $this->input->post('owner'), + ); + + if ($this->server->update($serverId, $data)) { + $this->messages->add(sprintf(_("The server "%s" has been updated successfully."), $server->id), 'success'); + } + redirect('admin/servers', 303); + } + + $data = array(); // empty data array + $data['server'] = $server; + + $data['users'] = array(); + + $users = $this->user->getAll(); + foreach ($users as $user) { + $data['users'][$user['id']] = $user['firstname'] . ' ' . $user['lastname']; + } + + $this->load->view('admin/servers/edit', $data); + } + + /** + * Allows admins to delete a server. + * + * @param string $serverId + */ + public function delete($serverId) { + $server = $this->server->getById($serverId); + + if (!isset($server) || !is_object($server)) { + show_404(); + } else { + $this->server->delete($server->id); + redirect('admin/servers', 303); + } + } } /* End of file servers.php */ diff --git a/application/models/server.php b/application/models/server.php index e221c4e..7af90e8 100644 --- a/application/models/server.php +++ b/application/models/server.php @@ -1,6 +1,6 @@ + * Copyright (c) 2011 Karsten Heiken, Eike Foken * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -22,34 +22,36 @@ */ /** + * * @author Karsten Heiken */ class Server extends CI_Model { /** - * Create a new server. + * Creates a new server. * - * @param array $data the server informations - * @return bool was the insert successful + * @param array $data The server informations + * @return boolean Returns TRUE if the insert was successful. */ public function create($data) { return $this->db->insert('servers', $data); } /** - * Delete a server. + * Deletes a server. * - * @param string $server_id - * @return bool was the deletion successful + * @param string $serverId + * @return boolean Returns TRUE if the deletion was successful. */ - public function delete($server_id) { - return $this->db->delete('servers', array('id' => $server_id)); + public function delete($serverId) { + $this->db->delete('servers', array('id' => $serverId)); + return $this->db->affected_rows() > 0; } /** - * Get a list of all available servers. + * Gets a list of all available servers. * - * @return array List of all available servers. + * @return array The list of all available servers */ public function getAll() { $servers = $this->db->get('servers')->result_array(); @@ -60,22 +62,24 @@ class Server extends CI_Model { } /** - * Get a list of servers that could handle another job. + * Gets a list of servers that could handle another job. * - * @return array List of servers that could handle another job. + * @return array The list of servers that could handle another job */ public function getIdle() { return $this->db->get_where('servers', 'workload <= 2')->result_array(); } /** - * Update a server. - * * - * @param type $secret The server's secret for basic authentication. - * @param type $workload The server's workload. + * Updates a server. + * + * @param type $secret The server's secret for basic authentication + * @param type $workload The server's workload + * @return boolean Returns TRUE if the update was successful. */ - public function update($server_id, $data) { - return $this->db->where('id', $server_id)->update('servers', $data); + public function update($serverId, $data) { + $this->db->where('id', $serverId)->update('servers', $data); + return $this->db->affected_rows() > 0; } /** @@ -101,10 +105,11 @@ class Server extends CI_Model { * @param string $serverId */ public function getById($serverId) { - $this->load->helper('date'); $server = $this->db->get_where('servers', array('id' => $serverId))->row(); - $server->uptimestring = prettyTime($server->uptime); - $server->lastheartbeat = prettyTime(time_diff($server->last_update, mysql_now())); + if (is_object($server)) { + $server->uptimestring = prettyTime($server->uptime); + $server->lastheartbeat = prettyTime(time_diff($server->last_update, mysql_now())); + } return $server; } } diff --git a/application/views/admin/server/detail.php b/application/views/admin/server/detail.php deleted file mode 100644 index 99bd95c..0000000 --- a/application/views/admin/server/detail.php +++ /dev/null @@ -1,36 +0,0 @@ -load->view('header'); ?> - -
- -
-

Serververwaltung: id?>

-
- -
-

Miscellaneous

-

Location

-

location)?>

- -

Owner

-

Jörg Thomaschewski

- -

Technical information

-

Hardware & OS

-

- CPU: hardware;?>
- Uptime: uptimestring;?>
- OS: os;?>
- Workload: workload);?>
- Last heartbeat: lastheartbeat;?> -

- -

ScattPort-Statistics

-

- Completed jobs: 47
- Available programs: PYTHA, ABC, DEF -

-
- -
- -load->view('footer'); ?> diff --git a/application/views/admin/server/list.php b/application/views/admin/server/list.php deleted file mode 100644 index 3e4b3b9..0000000 --- a/application/views/admin/server/list.php +++ /dev/null @@ -1,54 +0,0 @@ -load->view('header'); ?> - -
- -
-

Server management

-
- -
-

List of all available servers

- - - - - - - - - - - 0.8) { - $server['class'] = "pending"; - $server['status'] = 'busy'; - } else { - $server['class'] = "active"; - $server['status'] = 'available'; - } - } else { - $server['class'] = "closed"; - $server['status'] = "offline"; - } -?> - - - - - - - - -
IDLocationStatusActions
- - Edit | Delete
-
- -
- -load->view('footer'); ?> diff --git a/application/views/admin/servers/detail.php b/application/views/admin/servers/detail.php new file mode 100644 index 0000000..6b553e5 --- /dev/null +++ b/application/views/admin/servers/detail.php @@ -0,0 +1,41 @@ +load->view('header');?> + +
+ +
+

» id;?>

+
+ +
+

+

+ location);?> + +

+

+ "> +

+ +

+ description);?> + +

+

+

+ : hardware;?>
+ : uptimestring;?>
+ : os;?>
+ : workload);?>
+ : lastheartbeat;?> +

+ +

ScattPort-

+

+ : 47
+ : ScaTT +

+
+ +
+ +load->view('footer');?> diff --git a/application/views/admin/servers/edit.php b/application/views/admin/servers/edit.php new file mode 100644 index 0000000..656bc3f --- /dev/null +++ b/application/views/admin/servers/edit.php @@ -0,0 +1,42 @@ +load->view('header');?> + +
+ +
+

» id);?>

+
+ +
+
+

+
    +
  • + * +
    + + +
    +
  • +
  • + * +
    + owner, 'id="owner" class="drop"');?> +
    +
  • +
  • + * +
    + + +
    +
  • +
+

+ + +

+
+
+
+ +load->view('footer');?> diff --git a/application/views/admin/server/index.html b/application/views/admin/servers/index.html similarity index 100% rename from application/views/admin/server/index.html rename to application/views/admin/servers/index.html diff --git a/application/views/admin/servers/list.php b/application/views/admin/servers/list.php new file mode 100644 index 0000000..344ea08 --- /dev/null +++ b/application/views/admin/servers/list.php @@ -0,0 +1,54 @@ +load->view('header');?> + +
+ +
+

+
+ +
+

+ + + + + + + + + + + 0.8) { + $server['class'] = 'pending'; + $server['status'] = 'busy'; + } else { + $server['class'] = 'active'; + $server['status'] = 'available'; + } + } else { + $server['class'] = 'closed'; + $server['status'] = 'offline'; + } +?> + + + + + + + + +
+ | + | + +
+
+
+ +load->view('footer');?>