2017-11-23 18:09:36 -05:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Class for creating and rendering an incident
|
|
|
|
*/
|
|
|
|
class Incident
|
|
|
|
{
|
|
|
|
private $id;
|
|
|
|
private $date;
|
|
|
|
private $end_date;
|
|
|
|
private $text;
|
|
|
|
private $type;
|
|
|
|
private $title;
|
|
|
|
private $username;
|
|
|
|
|
2018-01-07 14:39:10 -05:00
|
|
|
/**
|
|
|
|
* Constructs service from its data.
|
|
|
|
* @param array $data incident data
|
|
|
|
*/
|
2017-11-23 18:09:36 -05:00
|
|
|
function __construct($data)
|
|
|
|
{
|
2018-01-07 14:39:10 -05:00
|
|
|
//TODO: Maybe get data from id?
|
2017-11-23 18:09:36 -05:00
|
|
|
$this->id = $data['status_id'];
|
|
|
|
$this->date = new DateTime("@".$data['time']);
|
|
|
|
$this->date = $this->date->format('Y-m-d H:i:sP');
|
|
|
|
if ($data['end_time']>0){
|
|
|
|
$this->end_date = new DateTime("@".$data['end_time']);
|
|
|
|
$this->end_date = $this->end_date->format('Y-m-d H:i:sP');
|
|
|
|
}
|
|
|
|
$this->type = $data['type'];
|
|
|
|
$this->title = $data['title'];
|
|
|
|
$this->text = $data['text'];
|
|
|
|
$this->username = $data['username'];
|
|
|
|
}
|
|
|
|
|
2018-01-07 14:39:10 -05:00
|
|
|
/**
|
|
|
|
* Deletes incident by ID.
|
|
|
|
* @param int ID
|
|
|
|
*/
|
2017-11-23 18:09:36 -05:00
|
|
|
public static function delete($id){
|
2018-01-07 14:39:10 -05:00
|
|
|
//TODO: This should check whether it's admin or their own post...
|
2017-11-23 18:09:36 -05:00
|
|
|
global $mysqli, $message;
|
|
|
|
|
|
|
|
$stmt = $mysqli->prepare("DELETE FROM services_status WHERE status_id = ?");
|
|
|
|
$stmt->bind_param("i", $id);
|
|
|
|
$stmt->execute();
|
|
|
|
$query = $stmt->get_result();
|
|
|
|
|
|
|
|
$stmt = $mysqli->prepare("DELETE FROM status WHERE id= ?");
|
|
|
|
$stmt->bind_param("i", $id);
|
|
|
|
$stmt->execute();
|
|
|
|
$query = $stmt->get_result();
|
|
|
|
header("Location: /admin");
|
|
|
|
}
|
|
|
|
|
2018-01-07 14:39:10 -05:00
|
|
|
/**
|
|
|
|
* Processes submitted form and adds incident unless problem is encountered,
|
|
|
|
* calling this is possible only for admin or higher rank. Also checks requirements
|
|
|
|
* for char limits.
|
|
|
|
* @return void
|
|
|
|
*/
|
2017-11-23 18:09:36 -05:00
|
|
|
public static function add()
|
|
|
|
{
|
|
|
|
global $mysqli, $message;
|
|
|
|
$user_id = $_SESSION['user'];
|
|
|
|
$type = $_POST['type'];
|
|
|
|
$title = $_POST['title'];
|
|
|
|
$text = $_POST['text'];
|
|
|
|
|
|
|
|
if (strlen($title)==0)
|
|
|
|
{
|
2017-12-30 18:41:58 -05:00
|
|
|
$message = _("Please enter title");
|
2017-11-23 18:09:36 -05:00
|
|
|
return;
|
|
|
|
}else if(strlen($title)>50){
|
2017-12-30 18:41:58 -05:00
|
|
|
$message = _("Title too long! Character limit is 50");
|
2017-11-23 18:09:36 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strlen($title)==0)
|
|
|
|
{
|
2017-12-30 18:41:58 -05:00
|
|
|
$message = _("Please enter text");
|
2017-11-23 18:09:36 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($type == 2 && (!strlen(trim($_POST['time'])) || !strlen(trim($_POST['end_time']))))
|
|
|
|
{
|
2017-12-30 18:41:58 -05:00
|
|
|
$message = _("Please set start and end time! Use ISO 8601 format.");
|
2017-11-23 18:09:36 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($_POST['services'])){
|
2017-12-30 18:41:58 -05:00
|
|
|
$message = _("Please select at least one service");
|
2017-11-23 18:09:36 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!is_array($_POST['services']))
|
|
|
|
{
|
|
|
|
$services = array($_POST['services']);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$services = $_POST['services'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($_POST['time'])){
|
|
|
|
$time = strtotime($_POST['time']);
|
|
|
|
$end_time = strtotime($_POST['end_time']);
|
|
|
|
if (!$time)
|
|
|
|
{
|
2017-12-30 18:41:58 -05:00
|
|
|
$message = _("Start date format is not recognized. Please use ISO 8601 format.");
|
2017-11-23 18:09:36 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$end_time)
|
|
|
|
{
|
2017-12-30 18:41:58 -05:00
|
|
|
$message = _("End date format is not recognized. Please use ISO 8601 format.");
|
2017-11-23 18:09:36 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
$time = time();
|
|
|
|
$end_time = '';
|
|
|
|
}
|
|
|
|
|
2017-11-29 09:01:16 -05:00
|
|
|
$stmt = $mysqli->prepare("INSERT INTO status VALUES (NULL,?, ?, ?, ?, ?, ?)");
|
2017-11-23 18:09:36 -05:00
|
|
|
$stmt->bind_param("issiii", $type, $title, $text, $time ,$end_time ,$user_id);
|
|
|
|
$stmt->execute();
|
|
|
|
$query = $stmt->get_result();
|
|
|
|
$status_id = $mysqli->insert_id;
|
|
|
|
|
|
|
|
foreach ($services as $service) {
|
2017-11-29 09:01:16 -05:00
|
|
|
$stmt = $mysqli->prepare("INSERT INTO services_status VALUES (NULL,?, ?)");
|
2017-11-23 18:09:36 -05:00
|
|
|
$stmt->bind_param("ii", $service, $status_id);
|
|
|
|
$stmt->execute();
|
|
|
|
$query = $stmt->get_result();
|
|
|
|
}
|
|
|
|
header("Location: /admin");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-07 14:39:10 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders incident
|
|
|
|
* @param Boolean $admin - decides whether admin controls should be rendered
|
|
|
|
* @return void
|
|
|
|
*/
|
2017-11-23 18:09:36 -05:00
|
|
|
public function render($admin=0){
|
|
|
|
global $icons;
|
|
|
|
global $classes, $user;
|
|
|
|
$admin = $admin && (($user->get_rank()<=1) || ($user->get_username() == $this->username));
|
|
|
|
?>
|
|
|
|
<article class="panel panel-<?php echo $classes[$this->type];?>">
|
|
|
|
<div class="panel-heading icon">
|
|
|
|
<i class="<?php echo $icons[$this->type];?>"></i>
|
|
|
|
</div>
|
|
|
|
<div class="panel-heading clearfix">
|
|
|
|
<h2 class="panel-title"><?php echo $this->title; ?></h2>
|
|
|
|
<?php if ($admin){
|
|
|
|
echo '<a href="?delete='.$this->id.'" class="pull-right delete"><i class="fa fa-trash"></i></a>';
|
|
|
|
}?>
|
|
|
|
<time class="pull-right timeago" datetime="<?php echo $this->date; ?>"><?php echo $this->date; ?></time>
|
|
|
|
</div>
|
|
|
|
<div class="panel-body">
|
|
|
|
<?php echo $this->text; ?>
|
|
|
|
</div>
|
2017-12-12 08:17:10 -05:00
|
|
|
<div class="panel-footer clearfix">
|
2017-12-30 18:41:58 -05:00
|
|
|
<small><?php echo _("Posted by");?>: <?php echo $this->username;
|
2017-11-23 18:09:36 -05:00
|
|
|
if (isset($this->end_date)){?>
|
2017-12-30 18:41:58 -05:00
|
|
|
<span class="pull-right"><?php echo strtotime($this->end_date)>time()?_("Ending"):_("Ended");?>: <time class="pull-right timeago" datetime="<?php echo $this->end_date; ?>"><?php echo $this->end_date; ?></time></span>
|
2017-11-23 18:09:36 -05:00
|
|
|
<?}?>
|
|
|
|
</small>
|
|
|
|
</div>
|
|
|
|
</article>
|
|
|
|
<?php
|
|
|
|
}
|
|
|
|
}
|