Added support for notes on events.

As of yet the notes get saved but never displayed anywhere.
This commit is contained in:
Erik Thuning 2025-03-14 15:26:07 +01:00
parent a7bfc49afc
commit afb3020a34
7 changed files with 78 additions and 41 deletions

@ -0,0 +1 @@
alter table `event` add column `notes` varchar(64) not null;

@ -428,22 +428,10 @@
<input type="hidden" <input type="hidden"
name="page" name="page"
value="checkout" /> value="checkout" />
<label for="user">Username:</label>
<input onFocus="JavaScript:suggest(this, 'user')"
type="text"
name="user"
list="user_suggest"
autocomplete="off"
placeholder="Username"
required />
<input type="hidden" <input type="hidden"
id="product" id="product"
name="product" name="product"
value="¤serial¤" /> value="¤serial¤" />
<button>
Check out
</button>
<br/>
<label>Loan length:</label> <label>Loan length:</label>
¤loan_presets¤ ¤loan_presets¤
<br/> <br/>
@ -453,6 +441,22 @@
onClick="JavaScript:calendar(event)" onClick="JavaScript:calendar(event)"
name="end" name="end"
value="¤end¤" /> value="¤end¤" />
<br/>
<label for="note">Notes:</label>
<textarea id="notes"
name="notes"></textarea>
<br/>
<label for="user">Username:</label>
<input onFocus="JavaScript:suggest(this, 'user')"
type="text"
name="user"
list="user_suggest"
autocomplete="off"
placeholder="Username"
required />
<button>
Check out
</button>
</form> </form>
</div> </div>
@ -724,7 +728,7 @@
¤initiator¤ ¤initiator¤
</td> </td>
<td> <td>
¤note¤ ¤misc¤
</td> </td>
</tr> </tr>
@ -852,11 +856,11 @@
disabled /> disabled />
</div> </div>
<div> <div>
<label for="notes"> <label for="user-notes">
Notes: Notes:
</label> </label>
<textarea name="notes" <textarea name="notes"
id="notes" id="user-notes"
disabled>¤notes¤</textarea> disabled>¤notes¤</textarea>
</div> </div>
</form> </form>
@ -882,6 +886,11 @@
value="¤end¤" value="¤end¤"
¤disabled¤ /> ¤disabled¤ />
<br/> <br/>
<label for="loan-notes">Notes:</label>
<textarea id="loan-notes"
name="notes"
¤disabled¤></textarea>
<br/>
<label for="product">Product:</label> <label for="product">Product:</label>
<input type="text" <input type="text"
id="product" id="product"

@ -428,22 +428,10 @@
<input type="hidden" <input type="hidden"
name="page" name="page"
value="checkout" /> value="checkout" />
<label for="user">Användarnamn:</label>
<input onFocus="JavaScript:suggest(this, 'user')"
type="text"
name="user"
list="user_suggest"
autocomplete="off"
placeholder="Användarnamn"
required />
<input type="hidden" <input type="hidden"
id="product" id="product"
name="product" name="product"
value="¤serial¤" /> value="¤serial¤" />
<button>
Låna ut
</button>
<br/>
<label>Löptid:</label> <label>Löptid:</label>
¤loan_presets¤ ¤loan_presets¤
<br/> <br/>
@ -453,6 +441,22 @@
onClick="JavaScript:calendar(event)" onClick="JavaScript:calendar(event)"
name="end" name="end"
value="¤end¤" /> value="¤end¤" />
<br/>
<label for="note">Anteckningar:</label>
<textarea id="notes"
name="notes"></textarea>
<br/>
<label for="user">Användarnamn:</label>
<input onFocus="JavaScript:suggest(this, 'user')"
type="text"
name="user"
list="user_suggest"
autocomplete="off"
placeholder="Användarnamn"
required />
<button>
Låna ut
</button>
</form> </form>
</div> </div>
@ -724,7 +728,7 @@
¤initiator¤ ¤initiator¤
</td> </td>
<td> <td>
¤note¤ ¤misc¤
</td> </td>
</tr> </tr>
@ -853,11 +857,11 @@
disabled /> disabled />
</div> </div>
<div> <div>
<label for="notes"> <label for="user-notes">
Anteckningar: Anteckningar:
</label> </label>
<textarea name="notes" <textarea name="notes"
id="notes" id="user-notes"
disabled>¤notes¤</textarea> disabled>¤notes¤</textarea>
</div> </div>
</form> </form>
@ -883,6 +887,11 @@
value="¤end¤" value="¤end¤"
¤disabled¤ /> ¤disabled¤ />
<br/> <br/>
<label for="loan-notes">Anteckningar:</label>
<textarea id="loan-notes"
name="notes"
¤disabled¤></textarea>
<br/>
<label for="product">Artikel:</label> <label for="product">Artikel:</label>
<input type="text" <input type="text"
id="product" id="product"

@ -95,6 +95,7 @@ class Ajax extends Responder {
Loan::create_loan($user, Loan::create_loan($user,
$product, $product,
$_POST['end'], $_POST['end'],
trim($_POST['notes']),
$this->logged_in_user); $this->logged_in_user);
return new Success(i18n('{product} checked out.', $product)); return new Success(i18n('{product} checked out.', $product));
} catch(Exception $e) { } catch(Exception $e) {

@ -1,11 +1,16 @@
<?php <?php
class Event { class Event {
protected $id = 0; protected $id = 0;
protected $initiator = 0;
protected $product = 0; protected $product = 0;
protected $starttime = 0; protected $starttime = 0;
protected $returntime = null; protected $returntime = null;
protected $notes = '';
protected static function create_event($product, $type, $initiator) { protected static function create_event($product,
$type,
$notes,
$initiator) {
$status = $product->get_status(); $status = $product->get_status();
if($status != 'available') { if($status != 'available') {
$emsg = ''; $emsg = '';
@ -36,11 +41,12 @@ class Event {
throw new Excpetion("Invalid argument '$type'"); throw new Excpetion("Invalid argument '$type'");
} }
$now = time(); $now = time();
$insert = prepare('insert into `event` $insert = prepare(
(`product`, `type`, `starttime`, `initiator`) 'insert into `event`
values (?, ?, ?, ?)'); (`product`, `type`, `starttime`, `notes`, `initiator`)
bind($insert, 'isis', values (?, ?, ?, ?, ?)');
$product->get_id(), $type, $now, $initiator->get_id()); bind($insert, 'isiss',
$product->get_id(), $type, $now, $notes, $initiator->get_id());
execute($insert); execute($insert);
$event_id = $insert->insert_id; $event_id = $insert->insert_id;
return new Event($event_id); return new Event($event_id);
@ -68,6 +74,7 @@ class Event {
$this->starttime = $result['starttime']; $this->starttime = $result['starttime'];
$this->returntime = $result['returntime']; $this->returntime = $result['returntime'];
$this->initiator = $result['initiator']; $this->initiator = $result['initiator'];
$this->notes = $result['notes'];
} }
public function get_id() { public function get_id() {
@ -94,6 +101,10 @@ class Event {
return $this->returntime; return $this->returntime;
} }
public function get_notes() {
return $this->notes;
}
public function is_active() { public function is_active() {
if($this->returntime === null) { if($this->returntime === null) {
return true; return true;

@ -3,9 +3,13 @@ class Loan extends Event {
private $user = 0; private $user = 0;
private $endtime = 0; private $endtime = 0;
public static function create_loan($user, $product, $endtime, $initiator) { public static function create_loan($user,
$product,
$endtime,
$notes,
$initiator) {
begin_trans(); begin_trans();
$event = parent::create_event($product, 'loan', $initiator); $event = parent::create_event($product, 'loan', $notes, $initiator);
$event_id = $event->get_id(); $event_id = $event->get_id();
$insert = prepare('insert into `loan`(`event`, `user`, `endtime`) $insert = prepare('insert into `loan`(`event`, `user`, `endtime`)
values (?, ?, ?)'); values (?, ?, ?)');

@ -115,6 +115,7 @@ class ProductPage extends Page {
$itemlink = 'Service'; $itemlink = 'Service';
$start = $event->get_starttime(); $start = $event->get_starttime();
$end = $event->get_returntime(); $end = $event->get_returntime();
$notes = $event->get_notes();
$initiator = $event->get_initiator(); $initiator = $event->get_initiator();
$initiator_name = i18n('Unknown'); $initiator_name = i18n('Unknown');
if($initiator) { if($initiator) {
@ -124,7 +125,7 @@ class ProductPage extends Page {
'page' => 'users'), 'page' => 'users'),
$this->fragments['item_link']); $this->fragments['item_link']);
} }
$note = ''; $misc = '';
if($event instanceof Loan) { if($event instanceof Loan) {
$user = $event->get_user(); $user = $event->get_user();
$product = $event->get_product(); $product = $event->get_product();
@ -135,7 +136,7 @@ class ProductPage extends Page {
if(!$end) { if(!$end) {
$end = $event->get_endtime(); $end = $event->get_endtime();
$extend = format_date(default_loan_end()); $extend = format_date(default_loan_end());
$note = replace(array('id' => $product->get_id(), $misc = replace(array('id' => $product->get_id(),
'end_new' => $extend), 'end_new' => $extend),
$this->fragments['loan_extend_form']); $this->fragments['loan_extend_form']);
} }
@ -145,7 +146,8 @@ class ProductPage extends Page {
'start_date' => format_date($start), 'start_date' => format_date($start),
'end_date' => format_date($end), 'end_date' => format_date($end),
'initiator' => $initiator_name, 'initiator' => $initiator_name,
'note' => $note), 'notes' => $notes,
'misc' => $misc),
$this->fragments['product_loan_table_row']); $this->fragments['product_loan_table_row']);
} }
return replace(array('rows' => $rows), return replace(array('rows' => $rows),