params['dev'] = false; $this->params['admin'] = false; parent::__construct(); } function sideMenuLinks() { // Stupid Cake... our constructor sets admin/dev, // but cake stomps it somewhere along the way // after constructing the CakeError controller. if ($this->name === 'CakeError') { $this->params['dev'] = false; $this->params['admin'] = false; } $menu = array(); $menu[] = array('name' => 'Common', 'header' => true); $menu[] = array('name' => 'Site Map', 'url' => array('controller' => 'maps', 'action' => 'view', 1)); $menu[] = array('name' => 'Units', 'url' => array('controller' => 'units', 'action' => 'index')); $menu[] = array('name' => 'Leases', 'url' => array('controller' => 'leases', 'action' => 'index')); $menu[] = array('name' => 'Customers', 'url' => array('controller' => 'customers', 'action' => 'index')); $menu[] = array('name' => 'Deposits', 'url' => array('controller' => 'transactions', 'action' => 'deposit')); if ($this->params['admin']) { $menu[] = array('name' => 'Admin', 'header' => true); $menu[] = array('name' => 'Accounts', 'url' => array('controller' => 'accounts', 'action' => 'index')); $menu[] = array('name' => 'Contacts', 'url' => array('controller' => 'contacts', 'action' => 'index')); $menu[] = array('name' => 'Ledgers', 'url' => array('controller' => 'ledgers', 'action' => 'index')); $menu[] = array('name' => 'Transactions', 'url' => array('controller' => 'transactions', 'action' => 'index')); $menu[] = array('name' => 'Ldgr Entries', 'url' => array('controller' => 'ledger_entries', 'action' => 'index')); $menu[] = array('name' => 'Stmt Entries', 'url' => array('controller' => 'statement_entries', 'action' => 'index')); $menu[] = array('name' => 'New Ledgers', 'url' => array('controller' => 'accounts', 'action' => 'newledger')); $menu[] = array('name' => 'Assess Charges', 'url' => array('controller' => 'leases', 'action' => 'assess_all')); } if ($this->params['dev']) { $menu[] = array('name' => 'Development', 'header' => true); $menu[] = array('name' => 'Un-Nuke', 'url' => '#', 'htmlAttributes' => array('onclick' => '$(".pr-section").show(); return false;')); $menu[] = array('name' => 'New Ledgers', 'url' => array('controller' => 'accounts', 'action' => 'newledger')); //array('name' => 'RESET DATA', 'url' => array('controller' => 'accounts', 'action' => 'reset_data')); } return $menu; } function beforeFilter() { $this->params['dev'] = (!empty($this->params['dev_route'])); $this->params['admin'] = (!empty($this->params['admin_route']) || !empty($this->params['dev_route'])); if (!$this->params['dev']) Configure::write('debug', '0'); } function beforeRender() { $this->set('sidemenu', $this->sideMenuLinks()); } function redirect($url, $status = null, $exit = true) { if (headers_sent()) { // If we've already sent the headers, it's because // we're debugging, and our debug output has gotten // out before the redirect. That's probably a good // thing, as we don't typically want pages to be // jerked out from under us while trying to read // the debug output. So, since we can't redirect // anyway, we may as well go with the flow and just // render this page instead, using an empty template $this->render('/empty'); if ($exit) $this->_stop(); } // OK, since the controller will not be able to // utilize our overriden url function in AppHelper, // we'll have to do it manually here. App::import('Helper', 'Html'); $url = HtmlHelper::url($url, true); return parent::redirect($url, $status, $exit); } function reset_data() { $this->layout = null; $this->autoLayout = false; $this->autoRender = false; Configure::write('debug', '0'); $script = $_SERVER['DOCUMENT_ROOT'] . '/pmgr/build.cmd'; echo "
" . date('r') . "\n"; //echo "
Script: $script" . "\n"; $db = & $this->Account->getDataSource(); $script .= ' "' . $db->config['database'] . '"'; $script .= ' "' . $db->config['login'] . '"'; $script .= ' "' . $db->config['password'] . '"'; $handle = popen($script . ' 2>&1', 'r'); //echo "
Handle: $handle; " . gettype($handle) . "\n"; echo "
\n";
while (($read = fread($handle, 2096))) {
echo $read;
}
echo "\n";
pclose($handle);
}
/**************************************************************************
**************************************************************************
**************************************************************************
* helper: gridView
* - called by derived controllers to create an index listing
*/
function gridView($title, $action = null, $element = null) {
$this->set('title', $title);
// The resulting page will contain a grid, which will
// use ajax to obtain the actual data for this action
$this->set('action', $action ? $action : $this->params['action']);
$this->render('/elements/' . ($element ? $element : $this->params['controller']));
}
/**************************************************************************
**************************************************************************
**************************************************************************
**************************************************************************
**************************************************************************
* action: gridData
* - Fetches the actual data requested by grid as XML
*/
function gridData() {
// Grab a copy of the parameters that control this request
$params = array();
if (isset($this->params['url']) && is_array($this->params['url']))
$params = $this->params['url'];
// Do any preliminary setup necessary
$this->gridDataSetup($params);
// Get the top level model for this grid
$model = $this->gridDataModel($params);
// Get the number of records prior to pagination
$count = $this->gridDataCount($params, $model);
// Determine pagination configuration (and save to $params)
$pagination = $this->gridDataPagination($params, $model, $count);
// Retreive the appropriate subset of data
$records = $this->gridDataRecords($params, $model, $pagination);
// Post process the records
$this->gridDataPostProcess($params, $model, $records);
// Output the resulting record set
$this->gridDataOutput($params, $model, $records, $pagination);
// Call out to finalize everything
$this->gridDataFinalize($params);
}
/**************************************************************************
**************************************************************************
**************************************************************************
**************************************************************************
**************************************************************************
* virtual: gridData* functions
* - These set up the context for the grid data, and will
* need to be overridden in the derived class for anything
* other than the most basic of grids.
*/
/**************************************************************************
**************************************************************************
**************************************************************************
* gridData SETUP / CLEANUP
*/
function gridDataModel(&$params) {
return $this->{$this->modelClass};
}
function gridDataSetup(&$params) {
// Debug only if requested
$params['debug'] = !empty($this->passedArgs['debug']);
if ($params['debug']) {
ob_start();
}
else {
$this->layout = null;
$this->autoLayout = false;
$this->autoRender = false;
Configure::write('debug', '0');
}
// Establish some defaults (except for serialized items)
$params = array_merge(array('page' => 1,
'rows' => 20),
$params);
// Unserialize our complex structure of post data.
// This SHOULD always be set, except when debugging
if (isset($params['post']))
$params['post'] = unserialize($params['post']);
else
$params['post'] = array();
// Unserialize our complex structure of dynamic post data
if (isset($params['dynamic_post']))
$params['dynamic_post'] = unserialize($params['dynamic_post']);
else
$params['dynamic_post'] = null;
// Unserialize our complex structure of dynamic post data
if (isset($params['dynamic_post_replace']))
$params['dynamic_post_replace'] = unserialize($params['dynamic_post_replace']);
else
$params['dynamic_post_replace'] = null;
// Merge the static and dynamic post data
if (!empty($params['dynamic_post']))
$params['post'] = array_merge_recursive($params['post'], $params['dynamic_post']);
if (!empty($params['dynamic_post_replace']))
$params['post'] = array_merge($params['post'], $params['dynamic_post_replace']);
// This SHOULD always be set, except when debugging
if (!isset($params['post']['fields']))
$params['post']['fields'] = array($this->{$this->modelClass}->alias
.'.'.
$this->{$this->modelClass}->primaryKey);
// Make sure the action parameter at least exists, and
// promote it to the top level (since it drives the operation).
if (isset($params['post']['action']))
$params['action'] = $params['post']['action'];
else
$params['action'] = null;
}
function gridDataFinalize(&$params) {
if ($params['debug']) {
$xml = ob_get_contents();
ob_end_clean();
$xml = preg_replace("/&/", "&", $xml);
$xml = preg_replace("/", "<", $xml);
$xml = preg_replace("/>/", ">", $xml);
echo ("\n\n$xml\n\n"); } } /************************************************************************** ************************************************************************** ************************************************************************** * gridData COUNTING */ function gridDataCount(&$params, &$model) { // Establish the tables and conditions for counting $query = array_intersect_key($this->gridDataCountTableSet($params, $model), array('link'=>1, 'contain'=>1)); // Conditions for the count $query['conditions'] = $this->gridDataCountConditionSet($params, $model); // Grouping (which would not be typical) $query['group'] = $this->gridDataCountGroup($params, $model); // DEBUG PURPOSES ONLY! $params['count_query'] = $query; // Get the number of records prior to pagination return $this->gridDataCountExecute($params, $model, $query); } function gridDataCountExecute(&$params, &$model, $query) { return $model->find('count', $query); } function gridDataCountTables(&$params, &$model) { // Same tables for counting as for retreiving return $this->gridDataTables($params, $model); } function gridDataCountTableSet(&$params, &$model) { // Preliminary set of tables $query = array_intersect_key($this->gridDataCountTables($params, $model), array('link'=>1, 'contain'=>1)); // Perform filtering based on user request: $params['post']['filter'] return array_intersect_key($this->gridDataFilterTables($params, $model, $query), array('link'=>1, 'contain'=>1)); } function gridDataCountConditions(&$params, &$model) { // Same conditions for counting as for retreiving return $this->gridDataConditions($params, $model); } function gridDataCountConditionSet(&$params, &$model) { // Conditions for the count $conditions = $this->gridDataCountConditions($params, $model); // Perform filtering based on user request: $params['post']['filter'] return $this->gridDataFilterConditions($params, $model, $conditions); } function gridDataCountGroup(&$params, &$model) { // Grouping will screw up the count, since it // causes the results to be split into chunks // based on the GROUP BY clause. We can't have // more than one row of data in the count query, // just a _single_ row with the actual count. return null; } /************************************************************************** ************************************************************************** ************************************************************************** * gridData FILTERING */ function gridDataFilterTables(&$params, &$model, $query) { if (isset($query['contain'])) $link = 'contain'; else $link = 'link'; if (empty($params['post']['filter'])) return $query; foreach ($params['post']['filter'] AS $filter => $filter_value) { $split = $this->gridDataFilterSplit($params, $model, $filter, $filter_value); /* pr(array('AppController::gridDataFilterTable' => */ /* array('checkpoint' => "Filter split") */ /* + compact('split'))); */ $table = $this->gridDataFilterTablesTable($params, $model, $split['table']); if (!$table) continue; $config = $this->gridDataFilterTablesConfig($params, $model, $split['table']); /* pr(array('AppController::gridDataFilterTable' => */ /* array('checkpoint' => "Add filter config to query") */ /* + array('query[link]' => $query[$link]) */ /* + compact('config'))); */ // If the table is already part of the query, append to it if ($table == $model->alias) { $query[$link] = array_merge_recursive(array_diff_key($config, array('fields'=>1)), $query[$link]); } elseif (isset($query[$link][$table])) { $query[$link][$table] = array_merge_recursive($config, $query[$link][$table]); } elseif (in_array($table, $query[$link])) { // REVISIT