Skip to content

Commit 93d1491

Browse files
committed
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)
1 parent 48b9cbb commit 93d1491

File tree

9 files changed

+515
-42
lines changed

9 files changed

+515
-42
lines changed

admin/index.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
define("PHP_MAILER_USER", $db->getSetting($mysqli, "php_mailer_user"));
3737
define("PHP_MAILER_PASS", $db->getSetting($mysqli, "php_mailer_pass"));
3838
define("CRON_SERVER_IP", $db->getSetting($mysqli, "cron_server_ip"));
39-
39+
4040
// Process the subscriber notification queue
4141
// If CRON_SERVER_IP is not set, call notification once incident has been saved
4242
if ( empty(CRON_SERVER_IP) )
@@ -110,6 +110,16 @@
110110
require_once("new-user.php");
111111
break;
112112

113+
case 'new-service':
114+
case 'edit-service':
115+
require_once('service.php');
116+
break;
117+
118+
case 'new-service-group':
119+
case 'edit-service-group':
120+
require_once('service-group.php');
121+
break;
122+
113123
case 'options':
114124
require_once("options.php");
115125
break;

admin/service-group.php

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<?php
2+
if (isset($_GET['new']))
3+
{
4+
ServiceGroup::add();
5+
}
6+
7+
if (isset($_GET['edit']))
8+
{
9+
ServiceGroup::edit();
10+
}
11+
12+
if (isset($_GET['delete']))
13+
{
14+
ServiceGroup::delete();
15+
}
16+
17+
$boolEdit = false;
18+
$group_value = isset($_POST['group']) ? $_POST['group'] : '';
19+
$description_value = isset($_POST['description']) ? $_POST['description'] : '';
20+
$visibility_id_value = isset($_POST['visibility_id']) ? $_POST['visibility_id'] : '';
21+
22+
if ( isset($_GET['id']) && !isset($_POST['id']) ) {
23+
$group_id = (int) $_GET['id'];
24+
$boolEdit = true;
25+
$stmt = $mysqli->prepare("SELECT * FROM services_groups WHERE id LIKE ?");
26+
$stmt->bind_param("i", $group_id);
27+
$stmt->execute();
28+
$query = $stmt->get_result();
29+
$data = $query->fetch_assoc();
30+
$group_value = $data['name'];
31+
$description_value = $data['description'];
32+
$visibility_id_value = $data['visibility'];
33+
}
34+
35+
36+
if (!$boolEdit) {
37+
38+
Template::render_header(_("New service group"), true); ?>
39+
<div class="text-center">
40+
<h2><?php echo _("Add new service group");?></h2>
41+
</div>
42+
<?php
43+
$form_url = WEB_URL .'/admin/?do=new-service-group&amp;new=group';
44+
45+
} else {
46+
Template::render_header(_("Edit service group"), true); ?>
47+
<div class="text-center">
48+
<h2><?php echo _("Edit service group");?></h2>
49+
</div>
50+
<?php
51+
$form_url = WEB_URL .'/admin/?do=edit-service-group&amp;edit&amp;id='.$group_id;
52+
53+
}
54+
?>
55+
56+
<form action="<?php echo $form_url;?>" method="POST" class="form-horizontal">
57+
<?php if (isset($message))
58+
{?>
59+
<p class="alert alert-danger"><?php echo $message?></p>
60+
<?php
61+
} ?>
62+
<div class="form-group">
63+
<div class="col-sm-6"><label for="group"><?php echo _("Service Group Name");?>: </label><input type="text" maxlength="50" name="group" value="<?php echo ((isset($_POST['group']))?htmlspecialchars($_POST['group'],ENT_QUOTES):$group_value);?>" id="group" placeholder="<?php echo _("service group name");?>" class="form-control" required></div>
64+
<div class="col-sm-6"><label for="description"><?php echo _("Description");?>: </label><input type="text" maxlength="100" name="description" value="<?php echo ((isset($_POST['description']))?htmlspecialchars($description_value,ENT_QUOTES):$description_value);?>" id="description" placeholder="<?php echo _("Description");?>" class="form-control"></div>
65+
</div>
66+
<div class="form-group">
67+
<div class="col-sm-6">
68+
<label for="visibility_id"><?php echo _("Visibility");?>: </label>
69+
<select name="visibility_id" id="visibility_id" class="form-control">
70+
<?php
71+
if (!empty($visibility_id_value))
72+
{
73+
$visibility_id = $visibility_id_value;
74+
}
75+
else
76+
{
77+
$visibility_id = null;
78+
}
79+
//$visibilitys = Service::get_groups();
80+
foreach ($visibility as $key => $value) {
81+
if ($visibility_id == $key)
82+
{
83+
echo '<option value="'.$key.'" selected>'.$value.'</option>';
84+
}
85+
else{
86+
echo '<option value="'.$key.'">'.$value.'</option>';
87+
}
88+
}
89+
?>
90+
</select>
91+
</div>
92+
</div>
93+
<?php
94+
if ( $boolEdit ) {
95+
echo '<input type="hidden" id="id" name="id" value="'.$group_id.'">';
96+
}
97+
?>
98+
<button type="submit" class="btn btn-primary pull-right"><?php echo _("Submit");?></button>
99+
</form>

admin/service.php

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php
2+
if (isset($_GET['new']))
3+
{
4+
Service::add();
5+
}
6+
7+
if (isset($_GET['edit']))
8+
{
9+
Service::edit();
10+
}
11+
12+
/*if (isset($_GET['delete']))
13+
{
14+
Service::delete();
15+
}*/
16+
17+
$boolEdit = false;
18+
$service_value = isset($_POST['service']) ? $_POST['service'] : '';
19+
$description_value = isset($_POST['description']) ? $_POST['description'] : '';
20+
$group_id_value = isset($_POST['group_id']) ? $_POST['group_id'] : '';
21+
22+
if ( isset($_GET['id']) && !isset($_POST['id']) ) {
23+
$service_id = (int) $_GET['id'];
24+
$boolEdit = true;
25+
$stmt = $mysqli->prepare("SELECT * FROM services WHERE id LIKE ?");
26+
$stmt->bind_param("i", $service_id);
27+
$stmt->execute();
28+
$query = $stmt->get_result();
29+
$data = $query->fetch_assoc();
30+
//print_r($data);
31+
$service_value = $data['name'];
32+
$description_value = $data['description'];
33+
$group_id_value = $data['group_id'];
34+
}
35+
36+
37+
if (!$boolEdit) {
38+
39+
Template::render_header(_("New service"), true); ?>
40+
<div class="text-center">
41+
<h2><?php echo _("Add new service");?></h2>
42+
</div>
43+
<?php
44+
$form_url = WEB_URL . '/admin/?do=new-service&amp;new=service';
45+
} else {
46+
Template::render_header(_("New service"), true); ?>
47+
<div class="text-center">
48+
<h2><?php echo _("Add new service");?></h2>
49+
</div>
50+
<?php
51+
$form_url = WEB_URL . '/admin/?do=edit-service&amp;edit&amp;id='.$service_id;
52+
}
53+
?>
54+
<form action="<?php echo $form_url;?>" method="POST" class="form-horizontal">
55+
<?php if (isset($message))
56+
{?>
57+
<p class="alert alert-danger"><?php echo $message?></p>
58+
<?php
59+
} ?>
60+
<div class="form-group">
61+
<div class="col-sm-6"><label for="service"><?php echo _("Service");?>: </label><input type="text" maxlength="50" name="service" value="<?php echo ((isset($_POST['service']))?htmlspecialchars($_POST['service'],ENT_QUOTES):$service_value);?>" id="service" placeholder="<?php echo _("service");?>" class="form-control" required></div>
62+
<div class="col-sm-6"><label for="description"><?php echo _("Description");?>: </label><input type="text" maxlength="200" name="description" value="<?php echo ((isset($_POST['description']))?htmlspecialchars($_POST['description'],ENT_QUOTES):$description_value);?>" id="description" placeholder="<?php echo _("Description");?>" class="form-control"></div>
63+
</div>
64+
<div class="form-group">
65+
<div class="col-sm-6">
66+
<label for="group_id"><?php echo _("Service Group");?>: </label>
67+
<select name="group_id" id="group_id" class="form-control">
68+
<?php
69+
if (!empty($group_id_value))
70+
{
71+
$group_id = $group_id_value;
72+
}
73+
else
74+
{
75+
$group_id = null;
76+
}
77+
$groups = ServiceGroup::get_groups();
78+
foreach ($groups as $key => $value) {
79+
if ($group_id == $key)
80+
{
81+
echo '<option value="'.$key.'" selected>'.$value.'</option>';
82+
}
83+
else{
84+
echo '<option value="'.$key.'">'.$value.'</option>';
85+
}
86+
}
87+
?>
88+
</select>
89+
</div>
90+
</div>
91+
<?php
92+
if ( $boolEdit ) {
93+
echo '<input type="hidden" id="id" name="id" value="'.$service_id.'">';
94+
}
95+
?>
96+
<button type="submit" class="btn btn-primary pull-right"><?php echo _("Submit");?></button>
97+
</form>

admin/settings.php

Lines changed: 71 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
<?php
2-
if (isset($_GET['new']))
2+
if (isset($_GET['delete']) && isset($_GET['type']))
33
{
4-
Service::add();
5-
}
6-
7-
if (isset($_GET['delete']))
8-
{
9-
Service::delete();
4+
if ( $_GET['type'] == 'service') {
5+
Service::delete();
6+
}
7+
elseif ( $_GET['type'] == 'groups') {
8+
ServiceGroup::delete();
9+
}
1010
}
1111

1212
Template::render_header(_("Settings"), true);
1313
?>
1414
<div class="text-center">
1515
<h2>Settings</h2>
1616
</div>
17-
<?php
17+
<?php
1818
if (isset($message)){
1919
?>
2020
<p class="alert alert-danger"><?php echo $message; ?></p>
@@ -24,36 +24,85 @@
2424
<?php if ($user->get_rank() <= 1){?>
2525
<form action="?do=settings&new=service" method="post">
2626
<div class="input-group pull-right new-service">
27-
<input class="form-control" name="service" placeholder="Name" type="text" value="<?php echo ((isset($_POST['service']))?htmlspecialchars($_POST['service']):''); ?>" maxlength="50" required>
28-
<span class="input-group-btn">
29-
<button type="submit" class="btn btn-success pull-right"><?php echo _("Add service");?></button>
30-
</span>
27+
<a href="<?php echo WEB_URL;?>/admin/?do=new-service" class="btn btn-success pull-right"><?php echo _("Add new service");?></a>
3128
</div>
3229
</form>
3330
<?php }?>
3431
<div class="table-responsive">
3532
<table class="table">
36-
33+
3734
<thead><tr>
38-
<th scope="col"><?php echo _("ID");?></th>
35+
<!--<th scope="col"><?php echo _("ID");?></th>-->
3936
<th scope="col"><?php echo _("Name");?></th>
37+
<th scope="col"><?php echo _("Description");?></th>
38+
<th scope="col"><?php echo _("Group");?></th>
4039
<?php if ($user->get_rank()<=1)
4140
{?>
4241
<th scope="col"><?php echo _("Delete");?></th>
4342
<?php } ?>
4443
</tr>
4544
</thead>
4645
<tbody>
47-
<?php
48-
$query = $mysqli->query("SELECT * FROM services");
46+
<?php
47+
$query = $mysqli->query("SELECT services.*, services_groups.name AS group_name FROM `services` LEFT JOIN services_groups ON services.group_id = services_groups.id ORDER BY services.name ASC");
4948
while($result = $query->fetch_assoc())
5049
{
5150
echo "<tr>";
52-
echo "<td>".$result['id']."</td>";
53-
echo "<td>".$result['name']."</td>";
51+
//echo "<td>".$result['id']."</td>";
52+
echo '<td><a href="'.WEB_URL.'/admin?do=edit-service&id='.$result['id'].'">'.$result['name'].'</a></th>';
53+
echo "<td>".$result['description']."</td>";
54+
echo "<td>".$result['group_name']."</td>";
55+
5456
if ($user->get_rank()<=1)
5557
{
56-
echo '<td><a href="'.WEB_URL.'/admin/?do=settings&delete='.$result['id'].'" class="pull-right delete-service"><i class="fa fa-trash"></i></a></td>';
58+
echo '<td><a href="'.WEB_URL.'/admin/?do=settings&type=service&delete='.$result['id'].'" class="pull-right delete-service"><i class="fa fa-trash"></i></a></td>';
59+
}
60+
echo "</tr>";
61+
}?>
62+
</tbody>
63+
</table>
64+
</div>
65+
</section>
66+
67+
<section>
68+
<h3 class="pull-left"><?php echo _("Services Groups");?></h3>
69+
<?php if ($user->get_rank() <= 1){?>
70+
<form action="?do=settings&new=service-group" method="post">
71+
<div class="input-group pull-right new-service">
72+
<a href="<?php echo WEB_URL;?>/admin/?do=new-service-group" class="btn btn-success pull-right"><?php echo _("Add new service group");?></a>
73+
</div>
74+
</form>
75+
<?php }?>
76+
<div class="table-responsive">
77+
<table class="table">
78+
79+
<thead><tr>
80+
<!--<th scope="col"><?php echo _("ID");?></th>-->
81+
<th scope="col"><?php echo _("Group Name");?></th>
82+
<th scope="col"><?php echo _("In use by");?></th>
83+
<th scope="col"><?php echo _("Description");?></th>
84+
<th scope="col"><?php echo _("Visibility");?></th>
85+
<?php if ($user->get_rank()<=1)
86+
{?>
87+
<th scope="col"><?php echo _("Delete");?></th>
88+
<?php } ?>
89+
</tr>
90+
</thead>
91+
<tbody>
92+
<?php
93+
$query = $mysqli->query("SELECT sg.* , (SELECT COUNT(*) FROM services WHERE services.group_id = sg.id) AS counter FROM services_groups AS sg ORDER BY sg.id ASC");
94+
while($result = $query->fetch_assoc())
95+
{
96+
echo "<tr>";
97+
//echo "<td>".$result['id']."</td>";
98+
echo '<td><a href="'.WEB_URL.'/admin?do=edit-service-group&id='.$result['id'].'">'.$result['name'].'</a></th>';
99+
echo '<td> <span class="badge badge-danger ml-2">'.$result['counter'].'</span>';
100+
echo "<td>".$result['description']."</td>";
101+
echo "<td>".$visibility[$result['visibility']]."</td>";
102+
103+
if ($user->get_rank()<=1)
104+
{
105+
echo '<td><a href="'.WEB_URL.'/admin/?do=settings&type=groups&delete='.$result['id'].'" class="pull-right delete-service"><i class="fa fa-trash"></i></a></td>';
57106
}
58107
echo "</tr>";
59108
}?>
@@ -68,10 +117,10 @@
68117
<?php if ($user->get_rank() == 0){?> <a href="<?php echo WEB_URL;?>/admin/?do=new-user" class="btn btn-success pull-right"><?php echo _("Add new user");?></a><?php }?>
69118
<div class="table-responsive">
70119
<table class="table">
71-
120+
72121
<thead><tr><th scope="col"><?php echo _("ID");?></th><th scope="col"><?php echo _("Username");?></th><th scope="col"><?php echo _("Name");?></th><th scope="col"><?php echo _("Surname");?></th><th scope="col"><?php echo _("Email");?></th><th scope="col"><?php echo _("Role");?></th><th scope="col">Active</th></tr></thead>
73122
<tbody>
74-
<?php
123+
<?php
75124
$query = $mysqli->query("SELECT * FROM users");
76125
while($result = $query->fetch_assoc())
77126
{
@@ -89,4 +138,4 @@
89138
</tbody>
90139
</table>
91140
</div>
92-
</section>
141+
</section>

0 commit comments

Comments
 (0)