mirror of
https://github.com/ShaYmez/FreeSTAR-Status-Engine.git
synced 2026-06-01 21:54:48 -04:00
Add functionality to services in backend.
- Add functionallity to categorize a one or more services under one service group. Partial fix for #7 and #90. (Frontend code to be done) - Add description field to service to be displayed as a help text on front page. Partial fix for #51 (Frontend code to be done)
This commit is contained in:
+15
-14
@@ -2,6 +2,7 @@
|
||||
//DIR Because of include problems
|
||||
require_once(__DIR__ . "/incident.php");
|
||||
require_once(__DIR__ . "/service.php");
|
||||
require_once(__DIR__ . "/service-group.php");
|
||||
require_once(__DIR__ . "/user.php");
|
||||
require_once(__DIR__ . "/token.php");
|
||||
/**
|
||||
@@ -20,7 +21,7 @@ class Constellation
|
||||
public function render_incidents($future=false, $offset=0, $limit = 5, $admin = 0){
|
||||
if ($offset<0)
|
||||
{
|
||||
$offset = 0;
|
||||
$offset = 0;
|
||||
}
|
||||
|
||||
$limit = (isset($_GET['limit'])?$_GET['limit']:5);
|
||||
@@ -37,7 +38,7 @@ class Constellation
|
||||
}
|
||||
else if (count($incidents["incidents"]) &&!$ajax)
|
||||
{
|
||||
if ($offset)
|
||||
if ($offset)
|
||||
{
|
||||
echo '<noscript><div class="centered"><a href="'.WEB_URL.'/?offset='.($offset-$limit).'×tamp='.$timestamp.'" class="btn btn-default">'._("Back").'</a></div></noscript>';
|
||||
}
|
||||
@@ -66,11 +67,11 @@ class Constellation
|
||||
/**
|
||||
* Renders service status - in admin page it returns array so it can be processed further.
|
||||
* @param boolean $admin
|
||||
* @return array of services
|
||||
* @return array of services
|
||||
*/
|
||||
public function render_status($admin = false, $heading = true){
|
||||
global $mysqli;
|
||||
|
||||
|
||||
$query = $mysqli->query("SELECT id, name FROM services");
|
||||
$array = array();
|
||||
if ($query->num_rows){
|
||||
@@ -91,7 +92,7 @@ class Constellation
|
||||
else{
|
||||
$array[] = new Service($result['id'], $result['name']);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($heading)
|
||||
{
|
||||
echo Service::current_status($array);
|
||||
@@ -131,14 +132,14 @@ class Constellation
|
||||
$limit--;
|
||||
$more = false;
|
||||
if ($query->num_rows>$limit){
|
||||
$more = true;
|
||||
$more = true;
|
||||
}
|
||||
if ($query->num_rows){
|
||||
while(($result = $query->fetch_assoc()) && $limit-- > 0)
|
||||
{
|
||||
// Add service id and service names to an array in the Incident class
|
||||
$stmt_service = $mysqli->prepare("SELECT services.id,services.name FROM services
|
||||
INNER JOIN services_status ON services.id = services_status.service_id
|
||||
$stmt_service = $mysqli->prepare("SELECT services.id,services.name FROM services
|
||||
INNER JOIN services_status ON services.id = services_status.service_id
|
||||
WHERE services_status.status_id = ?");
|
||||
$stmt_service->bind_param("i", $result['status_id']);
|
||||
$stmt_service->execute();
|
||||
@@ -156,17 +157,17 @@ class Constellation
|
||||
"incidents" => $array
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function render_warning($header, $message, $show_link = false, $url = null, $link_text = null)
|
||||
{
|
||||
$this->render_alert('alert-warning', $header, $message, $show_link, $url, $link_text);
|
||||
$this->render_alert('alert-warning', $header, $message, $show_link, $url, $link_text);
|
||||
}
|
||||
function render_success($header, $message, $show_link = false, $url = null, $link_text = null)
|
||||
{
|
||||
$this->render_alert('alert-success', $header, $message, $show_link, $url, $link_text);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Renders an alert on screen with an optional button to return to a given URL
|
||||
* @param string alert_type - Type of warning to render alert-danger, alert-warning, alert-success etc
|
||||
@@ -188,8 +189,8 @@ class Constellation
|
||||
if ( $show_link ) {
|
||||
echo '<div class="clearfix"><a href="'.$url.'" class="btn btn-success" role="button">'.$link_text.'</a></div>';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$constellation = new Constellation();
|
||||
$constellation = new Constellation();
|
||||
|
||||
@@ -0,0 +1,167 @@
|
||||
<?php
|
||||
/**
|
||||
* Class for managing services
|
||||
*/
|
||||
class ServiceGroup
|
||||
{
|
||||
private $id;
|
||||
private $name;
|
||||
private $description;
|
||||
private $visibility_id;
|
||||
|
||||
/**
|
||||
* Constructs servicegroup from its data.
|
||||
* @param int $id service ID
|
||||
* @param String $name service name
|
||||
* @param String $description tooltip text
|
||||
* @param int $visibility_id how to display group items
|
||||
*/
|
||||
function __construct($id, $name, $description, $visibility_id)
|
||||
|
||||
{
|
||||
//TODO: Maybe get data from ID?
|
||||
$this->id = $id;
|
||||
$this->name = $name;
|
||||
$this->description = $description;
|
||||
$this->visibility_id = $visibility_id;
|
||||
$this->status = $status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns id of this servicegroup
|
||||
* @return int id
|
||||
*/
|
||||
public function get_id()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns name of this servicegroup
|
||||
* @return String name
|
||||
*/
|
||||
public function get_name()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of this servicegroup
|
||||
* @return String description
|
||||
*/
|
||||
public function get_description()
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes submitted form and adds service unless problem is encountered,
|
||||
* calling this is possible only for admin or higher rank. Also checks requirements
|
||||
* for char limits.
|
||||
* @return void
|
||||
*/
|
||||
public static function add()
|
||||
{
|
||||
global $user, $message;
|
||||
if (strlen($_POST['group'])>50)
|
||||
{
|
||||
$message = _("Service group name is too long! Character limit is 50");
|
||||
return;
|
||||
}else if (strlen(trim($_POST['group']))==0){
|
||||
$message = _("Please enter name!");
|
||||
return;
|
||||
}
|
||||
|
||||
if ($user->get_rank()<=1)
|
||||
{
|
||||
global $mysqli;
|
||||
$name = $_POST["group"];
|
||||
$description = $_POST["description"];
|
||||
$visibility_id = $_POST["visibility_id"];
|
||||
$stmt = $mysqli->prepare("INSERT INTO services_groups VALUES(NULL,?,?,?)");
|
||||
$stmt->bind_param("ssi", $name, $description, $visibility_id);
|
||||
$stmt->execute();
|
||||
$stmt->get_result();
|
||||
header("Location: ".WEB_URL."/admin/?do=settings");
|
||||
}else
|
||||
{
|
||||
$message = _("You don't have the permission to do that!");
|
||||
}
|
||||
}
|
||||
|
||||
public static function edit()
|
||||
{
|
||||
global $user, $message;
|
||||
if (strlen($_POST['group'])>50)
|
||||
{
|
||||
$message = _("Service group name is too long! Character limit is 50");
|
||||
return;
|
||||
}else if (strlen(trim($_POST['group']))==0){
|
||||
$message = _("Please enter name!");
|
||||
return;
|
||||
}
|
||||
|
||||
if ($user->get_rank()<=1)
|
||||
{
|
||||
global $mysqli;
|
||||
$name = $_POST["group"];
|
||||
$description = $_POST["description"];
|
||||
$visibility_id = $_POST["visibility_id"];
|
||||
$group_id = $_POST["id"];
|
||||
$stmt = $mysqli->prepare("UPDATE services_groups SET name=?, description=?,visibility=? WHERE id LIKE ?");
|
||||
$stmt->bind_param("ssii", $name, $description, $visibility_id, $group_id);
|
||||
$stmt->execute();
|
||||
$stmt->get_result();
|
||||
header("Location: ".WEB_URL."/admin/?do=settings");
|
||||
}else
|
||||
{
|
||||
$message = _("You don't have the permission to do that!");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Deletes this service - first checks if user has permission to do that.
|
||||
* @return void
|
||||
*/
|
||||
public static function delete()
|
||||
{
|
||||
global $user, $message;
|
||||
if ($user->get_rank()<=1)
|
||||
{
|
||||
global $mysqli;
|
||||
$id = $_GET['delete'];
|
||||
|
||||
$stmt = $mysqli->prepare("DELETE FROM services_groups WHERE id = ?");
|
||||
$stmt->bind_param("i", $id);
|
||||
$stmt->execute();
|
||||
$query = $stmt->get_result();
|
||||
|
||||
$stmt = $mysqli->prepare("UPDATE services SET group_id = NULL WHERE group_id = ?");
|
||||
$stmt->bind_param("i", $id);
|
||||
$stmt->execute();
|
||||
$query = $stmt->get_result();
|
||||
|
||||
header("Location: ".WEB_URL."/admin/?do=settings");
|
||||
}
|
||||
else
|
||||
{
|
||||
$message = _("You don't have the permission to do that!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get list of services groups.
|
||||
* @return array $groups
|
||||
*/
|
||||
public function get_groups() {
|
||||
global $mysqli;
|
||||
$stmt = $mysqli->query("SELECT id, name FROM services_groups ORDER by name ASC");
|
||||
|
||||
$groups = array();
|
||||
$groups[0] = '';
|
||||
while ($res = $stmt->fetch_assoc()) {
|
||||
$groups[$res['id']] = $res['name'];
|
||||
}
|
||||
return $groups;
|
||||
}
|
||||
}
|
||||
+41
-4
@@ -70,9 +70,11 @@ class Service implements JsonSerializable
|
||||
if ($user->get_rank()<=1)
|
||||
{
|
||||
global $mysqli;
|
||||
$name = $_POST['service'];
|
||||
$stmt = $mysqli->prepare("INSERT INTO services ( name ) VALUES ( ? )");
|
||||
$stmt->bind_param("s", $name);
|
||||
$name = htmlspecialchars($_POST['service']);
|
||||
$description = htmlspecialchars($_POST['description']);
|
||||
$group_id = $_POST['group_id'];
|
||||
$stmt = $mysqli->prepare("INSERT INTO services ( name, description, group_id ) VALUES ( ?, ?, ? )");
|
||||
$stmt->bind_param("ssi", $name, $description, $group_id);
|
||||
$stmt->execute();
|
||||
$stmt->get_result();
|
||||
header("Location: ".WEB_URL."/admin/?do=settings");
|
||||
@@ -81,6 +83,41 @@ class Service implements JsonSerializable
|
||||
$message = _("You don't have the permission to do that!");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Processes submitted form and adds service unless problem is encountered,
|
||||
* calling this is possible only for admin or higher rank. Also checks requirements
|
||||
* for char limits.
|
||||
* @return void
|
||||
*/
|
||||
public static function edit()
|
||||
{
|
||||
global $user, $message;
|
||||
if (strlen($_POST['service'])>50)
|
||||
{
|
||||
$message = _("Service name is too long! Character limit is 50");
|
||||
return;
|
||||
}else if (strlen(trim($_POST['service']))==0){
|
||||
$message = _("Please enter name!");
|
||||
return;
|
||||
}
|
||||
|
||||
if ($user->get_rank()<=1)
|
||||
{
|
||||
global $mysqli;
|
||||
$service_id = $_POST["id"];
|
||||
$name = htmlspecialchars($_POST['service']);
|
||||
$description = htmlspecialchars($_POST["description"]);
|
||||
$group_id = $_POST["group_id"];
|
||||
$stmt = $mysqli->prepare("UPDATE services SET name=?, description=?, group_id=? WHERE id = ?");
|
||||
$stmt->bind_param("ssii", $name, $description, $group_id, $service_id);
|
||||
$stmt->execute();
|
||||
$stmt->get_result();
|
||||
header("Location: ".WEB_URL."/admin/?do=settings");
|
||||
}else
|
||||
{
|
||||
$message = _("You don't have the permission to do that!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes this service - first checks if user has permission to do that.
|
||||
@@ -139,7 +176,7 @@ class Service implements JsonSerializable
|
||||
{
|
||||
$worst = $service->get_status();
|
||||
}
|
||||
$statuses[$service->get_status()]++;
|
||||
$statuses[$service->get_status()]++;
|
||||
}
|
||||
|
||||
echo '<div id="status-big" class="status '.$classes[$worst].'">';
|
||||
|
||||
Reference in New Issue
Block a user