diff --git a/site/models/lock.php b/site/models/lock.php index 22dfa31..1c0191a 100644 --- a/site/models/lock.php +++ b/site/models/lock.php @@ -37,8 +37,10 @@ class Lock extends AppModel { $oldkey = $this->field('key'); $this->pr(5, compact('oldkey')); - if ($this->field('key') != $data['Lock']['key']) + if ($this->field('key') != $data['Lock']['key']) { $data['Lock']['last_key'] = $this->field('key'); + $data['Lock']['key_ts'] = date('Y-m-d G:i:s'); + } /* // Find the number of outstanding locks in use */ /* $locks = $this->find('first', */ @@ -52,6 +54,12 @@ class Lock extends AppModel { /* if ($locks[0]['inuse'] > $data['Lock']['qty']) */ /* return $this->prReturn(false); */ } + else { + // Brand new lock + } + + if (!$data['Lock']['qty']) + $data['Lock']['qty'] = 1; // Everything looks good... save it! return $this->prReturn($this->save($data, false)); diff --git a/site/views/locks/view.ctp b/site/views/locks/view.ctp index 201d42e..caf8816 100644 --- a/site/views/locks/view.ctp +++ b/site/views/locks/view.ctp @@ -16,8 +16,9 @@ $rows[] = array('Name', $lock['name']); if ($lock['qty'] > 1) $rows[] = array('Quantity', $lock['qty']); $rows[] = array('Key', $lock['key']); -if (!empty($lock['last_key'])) - $rows[] = array('Last Key', $lock['last_key']); +if (!empty($lock['last_key'])) { + $rows[] = array('Last Key', $lock['last_key'] . " (Changed on " . FormatHelper::datetime($lock['key_ts']) . ")"); +} $rows[] = array('Comment', $lock['comment']); echo $this->element('table',