Implemented tracking of who initiated an event.
This commit is contained in:
parent
ee082de50a
commit
63ccad38c8
@ -642,6 +642,9 @@
|
||||
<th>
|
||||
End date
|
||||
</th>
|
||||
<th>
|
||||
Started by
|
||||
</th>
|
||||
<th>
|
||||
Misc
|
||||
</th>
|
||||
@ -668,6 +671,9 @@
|
||||
<td>
|
||||
¤end_date¤
|
||||
</td>
|
||||
<td>
|
||||
¤initiator¤
|
||||
</td>
|
||||
<td>
|
||||
¤note¤
|
||||
</td>
|
||||
@ -688,6 +694,9 @@
|
||||
<th>
|
||||
End date
|
||||
</th>
|
||||
<th>
|
||||
Started by
|
||||
</th>
|
||||
<th>
|
||||
Misc
|
||||
</th>
|
||||
@ -711,6 +720,9 @@
|
||||
<td>
|
||||
¤end_date¤
|
||||
</td>
|
||||
<td>
|
||||
¤initiator¤
|
||||
</td>
|
||||
<td>
|
||||
¤note¤
|
||||
</td>
|
||||
|
@ -642,6 +642,9 @@
|
||||
<th>
|
||||
Slutdatum
|
||||
</th>
|
||||
<th>
|
||||
Startat av
|
||||
</th>
|
||||
<th>
|
||||
Övrigt
|
||||
</th>
|
||||
@ -668,6 +671,9 @@
|
||||
<td>
|
||||
¤end_date¤
|
||||
</td>
|
||||
<td>
|
||||
¤initiator¤
|
||||
</td>
|
||||
<td>
|
||||
¤note¤
|
||||
</td>
|
||||
@ -688,6 +694,9 @@
|
||||
<th>
|
||||
Slutdatum
|
||||
</th>
|
||||
<th>
|
||||
Startat av
|
||||
</th>
|
||||
<th>
|
||||
Övrigt
|
||||
</th>
|
||||
@ -711,6 +720,9 @@
|
||||
<td>
|
||||
¤end_date¤
|
||||
</td>
|
||||
<td>
|
||||
¤initiator¤
|
||||
</td>
|
||||
<td>
|
||||
¤note¤
|
||||
</td>
|
||||
|
@ -92,7 +92,10 @@ class Ajax extends Responder {
|
||||
return new Failure(i18n('Invalid serial number.'));
|
||||
}
|
||||
try {
|
||||
Loan::create_loan($user, $product, $_POST['end']);
|
||||
Loan::create_loan($user,
|
||||
$product,
|
||||
$_POST['end'],
|
||||
$this->logged_in_user);
|
||||
return new Success(i18n('{product} checked out.', $product));
|
||||
} catch(Exception $e) {
|
||||
return new Failure(i18n('The product is already on loan.'));
|
||||
@ -385,7 +388,7 @@ class Ajax extends Responder {
|
||||
private function toggle_service() {
|
||||
$product = new Product($_POST['id']);
|
||||
try {
|
||||
$product->toggle_service();
|
||||
$product->toggle_service($this->logged_in_user);
|
||||
return new Success(i18n('Product service status updated.'));
|
||||
} catch(Exception $e) {
|
||||
return new Failure(i18n('Cannot register service.'));
|
||||
|
@ -5,7 +5,7 @@ class Event {
|
||||
protected $starttime = 0;
|
||||
protected $returntime = null;
|
||||
|
||||
protected static function create_event($product, $type) {
|
||||
protected static function create_event($product, $type, $initiator) {
|
||||
$status = $product->get_status();
|
||||
if($status != 'available') {
|
||||
$emsg = '';
|
||||
@ -37,9 +37,10 @@ class Event {
|
||||
}
|
||||
$now = time();
|
||||
$insert = prepare('insert into `event`
|
||||
(`product`, `type`, `starttime`)
|
||||
values (?, ?, ?)');
|
||||
bind($insert, 'isi', $product->get_id(), $type, $now);
|
||||
(`product`, `type`, `starttime`, `initiator`)
|
||||
values (?, ?, ?, ?)');
|
||||
bind($insert, 'isis',
|
||||
$product->get_id(), $type, $now, $initiator->get_id());
|
||||
execute($insert);
|
||||
$event_id = $insert->insert_id;
|
||||
return new Event($event_id);
|
||||
@ -66,6 +67,7 @@ class Event {
|
||||
$this->product = $result['product'];
|
||||
$this->starttime = $result['starttime'];
|
||||
$this->returntime = $result['returntime'];
|
||||
$this->initiator = $result['initiator'];
|
||||
}
|
||||
|
||||
public function get_id() {
|
||||
@ -76,6 +78,14 @@ class Event {
|
||||
return new Product($this->product);
|
||||
}
|
||||
|
||||
public function get_initiator() {
|
||||
$initiator = $this->initiator;
|
||||
if($initiator === null) {
|
||||
return null;
|
||||
}
|
||||
return new User($this->initiator);
|
||||
}
|
||||
|
||||
public function get_starttime() {
|
||||
return $this->starttime;
|
||||
}
|
||||
|
@ -3,9 +3,9 @@ class Loan extends Event {
|
||||
private $user = 0;
|
||||
private $endtime = 0;
|
||||
|
||||
public static function create_loan($user, $product, $endtime) {
|
||||
public static function create_loan($user, $product, $endtime, $initiator) {
|
||||
begin_trans();
|
||||
$event = parent::create_event($product, 'loan');
|
||||
$event = parent::create_event($product, 'loan', $initiator);
|
||||
$event_id = $event->get_id();
|
||||
$insert = prepare('insert into `loan`(`event`, `user`, `endtime`)
|
||||
values (?, ?, ?)');
|
||||
|
@ -224,6 +224,15 @@ abstract class Page extends Responder {
|
||||
'page' => 'products'),
|
||||
$this->fragments['item_link']);
|
||||
$status = $loan->get_status();
|
||||
$initiator = $loan->get_initiator();
|
||||
$initiator_name = i18n('Unknown');
|
||||
if($initiator) {
|
||||
$initiator_name = replace(
|
||||
array('id' => $initiator->get_id(),
|
||||
'name' => $initiator->get_name(),
|
||||
'page' => 'users'),
|
||||
$this->fragments['item_link']);
|
||||
}
|
||||
$note = '';
|
||||
if($status !== 'inactive_loan') {
|
||||
$extend = format_date($loan->get_endtime());
|
||||
@ -241,6 +250,7 @@ abstract class Page extends Responder {
|
||||
'serial' => $product->get_serial(),
|
||||
'start_date' => format_date($start),
|
||||
'end_date' => format_date($end),
|
||||
'initiator' => $initiator_name,
|
||||
'note' => $note),
|
||||
$this->fragments['user_loan_table_row']);
|
||||
}
|
||||
|
@ -344,14 +344,14 @@ EOF;
|
||||
}
|
||||
}
|
||||
|
||||
public function toggle_service() {
|
||||
public function toggle_service($initiator) {
|
||||
$status = $this->get_status();
|
||||
$now = time();
|
||||
$update = '';
|
||||
if($status == 'service') {
|
||||
return $this->get_active_service()->end();
|
||||
} else if($status == 'available') {
|
||||
Service::create_service($this);
|
||||
Service::create_service($this, $initiator);
|
||||
return true;
|
||||
}
|
||||
$id = $this->get_id();
|
||||
|
@ -115,6 +115,15 @@ class ProductPage extends Page {
|
||||
$itemlink = 'Service';
|
||||
$start = $event->get_starttime();
|
||||
$end = $event->get_returntime();
|
||||
$initiator = $event->get_initiator();
|
||||
$initiator_name = i18n('Unknown');
|
||||
if($initiator) {
|
||||
$initiator_name = replace(
|
||||
array('id' => $initiator->get_id(),
|
||||
'name' => $initiator->get_name(),
|
||||
'page' => 'users'),
|
||||
$this->fragments['item_link']);
|
||||
}
|
||||
$note = '';
|
||||
if($event instanceof Loan) {
|
||||
$user = $event->get_user();
|
||||
@ -135,6 +144,7 @@ class ProductPage extends Page {
|
||||
'name' => $itemlink,
|
||||
'start_date' => format_date($start),
|
||||
'end_date' => format_date($end),
|
||||
'initiator' => $initiator_name,
|
||||
'note' => $note),
|
||||
$this->fragments['product_loan_table_row']);
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
abstract class Responder {
|
||||
protected $fragments = array();
|
||||
protected $ldap = null;
|
||||
protected $logged_in_user = null;
|
||||
|
||||
public function __construct() {
|
||||
global $language, $required_entitlements;
|
||||
@ -14,6 +15,8 @@ abstract class Responder {
|
||||
}
|
||||
}
|
||||
|
||||
$remote_user = explode('@', $_SERVER['REMOTE_USER'])[0];
|
||||
$this->logged_in_user = $this->user_init($remote_user, null);
|
||||
$this->fragments = get_fragments("./html/$language/fragments.html");
|
||||
$this->ldap = new Ldap();
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
<?php
|
||||
class Service extends Event {
|
||||
public static function create_service($product) {
|
||||
public static function create_service($product, $initiator) {
|
||||
begin_trans();
|
||||
$event = parent::create_event($product, 'service');
|
||||
$event = parent::create_event($product, 'service', $initiator);
|
||||
$event_id = $event->get_id();
|
||||
$insert = prepare('insert into `service`(`event`) values (?)');
|
||||
bind($insert, 'i', $event_id);
|
||||
|
@ -73,6 +73,10 @@ $i18n = array(
|
||||
"en" => function() { return "years"; },
|
||||
"sv" => function() { return "år"; },
|
||||
),
|
||||
"Unknown" => array(
|
||||
"en" => function() { return "Unknown"; },
|
||||
"sv" => function() { return "Okänd"; },
|
||||
),
|
||||
"{count} products" => array(
|
||||
"en" => function($count) { return "$count products"; },
|
||||
"sv" => function($count) { return "$count artiklar"; },
|
||||
|
Loading…
x
Reference in New Issue
Block a user