git-svn-id: file:///svn-source/pmgr/branches/v0.3_work@1039 97e9348a-65ac-dc4b-aefc-98561f571b83
162 lines
5.0 KiB
PHP
162 lines
5.0 KiB
PHP
<?php
|
|
|
|
class LocksController extends AppController {
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* override: addGridViewSideMenuLinks
|
|
* - Adds grid view navigation side menu links
|
|
*/
|
|
|
|
function addGridViewSideMenuLinks() {
|
|
parent::addGridViewSideMenuLinks();
|
|
|
|
$this->addSideMenuLink('List',
|
|
array('controller' => 'locks', 'action' => 'all'), null,
|
|
'CONTROLLER');
|
|
$this->addSideMenuLink('Add',
|
|
array('controller' => 'locks', 'action' => 'add'), null,
|
|
'CONTROLLER');
|
|
}
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* action: index / all
|
|
* - Generate a listing of locks
|
|
*/
|
|
|
|
function index() { $this->all(); }
|
|
function all() { $this->gridView('Locks', 'all'); }
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* virtuals: gridData
|
|
* - With the application controller handling the gridData action,
|
|
* these virtual functions ensure that the correct data is passed
|
|
* to jqGrid.
|
|
*/
|
|
|
|
/* function gridDataCountTables(&$params, &$model) { */
|
|
/* return array('link' => array('Unit')); */
|
|
/* } */
|
|
|
|
function gridDataTables(&$params, &$model) {
|
|
$tables = parent::gridDataTables($params, $model);
|
|
$tables['link']['LocksUnit'] = array();
|
|
return $tables;
|
|
}
|
|
|
|
function gridDataFields(&$params, &$model) {
|
|
$fields = parent::gridDataFields($params, $model);
|
|
$fields[] = 'COUNT(LocksUnit.id) AS inuse';
|
|
$fields[] = 'Lock.qty - COUNT(LocksUnit.id) AS avail';
|
|
return $fields;
|
|
}
|
|
|
|
function gridDataPostProcessLinks(&$params, &$model, &$records, $links) {
|
|
$links['Lock'] = array('name');
|
|
return parent::gridDataPostProcessLinks($params, $model, $records, $links);
|
|
}
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* action: view
|
|
* - Displays information about a specific entry
|
|
*/
|
|
|
|
function view($id = null) {
|
|
if (!$id) {
|
|
$this->Session->setFlash(__('Invalid Item.', true));
|
|
$this->redirect(array('controller' => 'accounts', 'action'=>'index'));
|
|
}
|
|
|
|
// Get the UnitSize and related fields
|
|
$this->Lock->id = $id;
|
|
$lock = $this->Lock->find
|
|
('first', array
|
|
('contain' => array(),
|
|
));
|
|
//$lock['Lock'] = $lock[0] + $lock['lock'];
|
|
//unset($lock[0]);
|
|
|
|
$this->addSideMenuLink('Edit',
|
|
array('action' => 'edit', $id), null,
|
|
'ACTION');
|
|
|
|
$this->set(compact('lock'));
|
|
|
|
// Prepare to render.
|
|
$title = "Lock : {$lock['Lock']['name']}";
|
|
$this->set(compact('title'));
|
|
}
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* action: edit
|
|
* - Edit customer information
|
|
*/
|
|
|
|
function edit($id = null) {
|
|
if (isset($this->data)) {
|
|
// Check to see if the operation was cancelled.
|
|
if (isset($this->params['form']['cancel'])) {
|
|
if (isset($this->data['Lock']['id']))
|
|
$this->redirect(array('action'=>'view', $this->data['Lock']['id']));
|
|
|
|
$this->redirect(array('action'=>'index'));
|
|
}
|
|
|
|
// Save the lock and all associated data
|
|
if (!$this->Lock->saveLock($this->data)) {
|
|
$this->Session->setFlash("LOCK SAVE FAILED", true);
|
|
pr("LOCK SAVE FAILED");
|
|
}
|
|
|
|
// View the lock by redirect
|
|
$this->redirect(array('action'=>'view', $this->Lock->id));
|
|
}
|
|
|
|
if ($id) {
|
|
// Get details on this customer, its contacts and leases
|
|
$lock = $this->Lock->find
|
|
('first', array
|
|
('conditions' => array('Lock.id' => $id),
|
|
));
|
|
|
|
$this->data = $lock;
|
|
$title = 'Lock: ' . $this->data['Lock']['name'] . " : Edit";
|
|
}
|
|
else {
|
|
$title = "Enter New Lock Information";
|
|
$this->data = array();
|
|
}
|
|
|
|
// Prepare to render.
|
|
//pr($this->data);
|
|
$this->set(compact('title'));
|
|
$this->render('edit');
|
|
}
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* action: add
|
|
* - Add a new lock
|
|
*/
|
|
|
|
function add() {
|
|
$this->edit();
|
|
}
|
|
|
|
}
|