diff --git a/evolutions/002-event-notes.sql b/evolutions/002-event-notes.sql new file mode 100644 index 0000000..93c6f19 --- /dev/null +++ b/evolutions/002-event-notes.sql @@ -0,0 +1 @@ +alter table `event` add column `notes` varchar(64) not null; diff --git a/html/en/fragments.html b/html/en/fragments.html index b7032cc..9bca668 100644 --- a/html/en/fragments.html +++ b/html/en/fragments.html @@ -428,22 +428,10 @@ <input type="hidden" name="page" 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" id="product" name="product" value="¤serial¤" /> - <button> - Check out - </button> - <br/> <label>Loan length:</label> ¤loan_presets¤ <br/> @@ -453,6 +441,22 @@ onClick="JavaScript:calendar(event)" name="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> </div> @@ -724,7 +728,7 @@ ¤initiator¤ </td> <td> - ¤note¤ + ¤misc¤ </td> </tr> @@ -852,11 +856,11 @@ disabled /> </div> <div> - <label for="notes"> + <label for="user-notes"> Notes: </label> <textarea name="notes" - id="notes" + id="user-notes" disabled>¤notes¤</textarea> </div> </form> @@ -882,6 +886,11 @@ value="¤end¤" ¤disabled¤ /> <br/> + <label for="loan-notes">Notes:</label> + <textarea id="loan-notes" + name="notes" + ¤disabled¤></textarea> + <br/> <label for="product">Product:</label> <input type="text" id="product" diff --git a/html/sv/fragments.html b/html/sv/fragments.html index 508c789..37012f3 100644 --- a/html/sv/fragments.html +++ b/html/sv/fragments.html @@ -428,22 +428,10 @@ <input type="hidden" name="page" 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" id="product" name="product" value="¤serial¤" /> - <button> - Låna ut - </button> - <br/> <label>Löptid:</label> ¤loan_presets¤ <br/> @@ -453,6 +441,22 @@ onClick="JavaScript:calendar(event)" name="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> </div> @@ -724,7 +728,7 @@ ¤initiator¤ </td> <td> - ¤note¤ + ¤misc¤ </td> </tr> @@ -853,11 +857,11 @@ disabled /> </div> <div> - <label for="notes"> + <label for="user-notes"> Anteckningar: </label> <textarea name="notes" - id="notes" + id="user-notes" disabled>¤notes¤</textarea> </div> </form> @@ -883,6 +887,11 @@ value="¤end¤" ¤disabled¤ /> <br/> + <label for="loan-notes">Anteckningar:</label> + <textarea id="loan-notes" + name="notes" + ¤disabled¤></textarea> + <br/> <label for="product">Artikel:</label> <input type="text" id="product" diff --git a/include/Ajax.php b/include/Ajax.php index 6455536..7ba83a7 100644 --- a/include/Ajax.php +++ b/include/Ajax.php @@ -95,6 +95,7 @@ class Ajax extends Responder { Loan::create_loan($user, $product, $_POST['end'], + trim($_POST['notes']), $this->logged_in_user); return new Success(i18n('{product} checked out.', $product)); } catch(Exception $e) { diff --git a/include/Event.php b/include/Event.php index 3586b03..7763be2 100644 --- a/include/Event.php +++ b/include/Event.php @@ -1,11 +1,16 @@ <?php class Event { protected $id = 0; + protected $initiator = 0; protected $product = 0; protected $starttime = 0; 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(); if($status != 'available') { $emsg = ''; @@ -36,11 +41,12 @@ class Event { throw new Excpetion("Invalid argument '$type'"); } $now = time(); - $insert = prepare('insert into `event` - (`product`, `type`, `starttime`, `initiator`) - values (?, ?, ?, ?)'); - bind($insert, 'isis', - $product->get_id(), $type, $now, $initiator->get_id()); + $insert = prepare( + 'insert into `event` + (`product`, `type`, `starttime`, `notes`, `initiator`) + values (?, ?, ?, ?, ?)'); + bind($insert, 'isiss', + $product->get_id(), $type, $now, $notes, $initiator->get_id()); execute($insert); $event_id = $insert->insert_id; return new Event($event_id); @@ -68,6 +74,7 @@ class Event { $this->starttime = $result['starttime']; $this->returntime = $result['returntime']; $this->initiator = $result['initiator']; + $this->notes = $result['notes']; } public function get_id() { @@ -94,6 +101,10 @@ class Event { return $this->returntime; } + public function get_notes() { + return $this->notes; + } + public function is_active() { if($this->returntime === null) { return true; diff --git a/include/Loan.php b/include/Loan.php index 10eba37..b71cd5d 100644 --- a/include/Loan.php +++ b/include/Loan.php @@ -3,9 +3,13 @@ class Loan extends Event { private $user = 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(); - $event = parent::create_event($product, 'loan', $initiator); + $event = parent::create_event($product, 'loan', $notes, $initiator); $event_id = $event->get_id(); $insert = prepare('insert into `loan`(`event`, `user`, `endtime`) values (?, ?, ?)'); diff --git a/include/ProductPage.php b/include/ProductPage.php index 1838349..3275680 100644 --- a/include/ProductPage.php +++ b/include/ProductPage.php @@ -115,6 +115,7 @@ class ProductPage extends Page { $itemlink = 'Service'; $start = $event->get_starttime(); $end = $event->get_returntime(); + $notes = $event->get_notes(); $initiator = $event->get_initiator(); $initiator_name = i18n('Unknown'); if($initiator) { @@ -124,7 +125,7 @@ class ProductPage extends Page { 'page' => 'users'), $this->fragments['item_link']); } - $note = ''; + $misc = ''; if($event instanceof Loan) { $user = $event->get_user(); $product = $event->get_product(); @@ -135,7 +136,7 @@ class ProductPage extends Page { if(!$end) { $end = $event->get_endtime(); $extend = format_date(default_loan_end()); - $note = replace(array('id' => $product->get_id(), + $misc = replace(array('id' => $product->get_id(), 'end_new' => $extend), $this->fragments['loan_extend_form']); } @@ -145,7 +146,8 @@ class ProductPage extends Page { 'start_date' => format_date($start), 'end_date' => format_date($end), 'initiator' => $initiator_name, - 'note' => $note), + 'notes' => $notes, + 'misc' => $misc), $this->fragments['product_loan_table_row']); } return replace(array('rows' => $rows),