git-svn-id: file:///svn-source/pmgr/branches/ledger_transactions_20090605@108 97e9348a-65ac-dc4b-aefc-98561f571b83
162 lines
5.3 KiB
PHP
162 lines
5.3 KiB
PHP
<?php
|
|
/* SVN FILE: $Id: app_controller.php 7945 2008-12-19 02:16:01Z gwoo $ */
|
|
/**
|
|
* Short description for file.
|
|
*
|
|
* This file is application-wide controller file. You can put all
|
|
* application-wide controller-related methods here.
|
|
*
|
|
* PHP versions 4 and 5
|
|
*
|
|
* CakePHP(tm) : Rapid Development Framework (http://www.cakephp.org)
|
|
* Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
|
|
*
|
|
* Licensed under The MIT License
|
|
* Redistributions of files must retain the above copyright notice.
|
|
*
|
|
* @filesource
|
|
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
|
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
|
|
* @package cake
|
|
* @subpackage cake.app
|
|
* @since CakePHP(tm) v 0.2.9
|
|
* @version $Revision: 7945 $
|
|
* @modifiedby $LastChangedBy: gwoo $
|
|
* @lastmodified $Date: 2008-12-18 18:16:01 -0800 (Thu, 18 Dec 2008) $
|
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
|
*/
|
|
/**
|
|
* Short description for class.
|
|
*
|
|
* Add your application-wide methods in the class below, your controllers
|
|
* will inherit them.
|
|
*
|
|
* @package cake
|
|
* @subpackage cake.app
|
|
*/
|
|
class AppController extends Controller {
|
|
var $helpers = array('Html', 'Form', 'Javascript', 'Format', 'Time');
|
|
var $components = array('DebugKit.Toolbar');
|
|
|
|
function sideMenuLinks() {
|
|
return array(
|
|
array('name' => 'Common', 'header' => true),
|
|
array('name' => 'Site Map', 'url' => array('controller' => 'maps', 'action' => 'view', 1)),
|
|
array('name' => 'Units', 'url' => array('controller' => 'units', 'action' => 'index')),
|
|
array('name' => 'Leases', 'url' => array('controller' => 'leases', 'action' => 'index')),
|
|
array('name' => 'Customers', 'url' => array('controller' => 'customers', 'action' => 'index')),
|
|
array('name' => 'Contacts', 'url' => array('controller' => 'contacts', 'action' => 'index')),
|
|
array('name' => 'Accounts', 'url' => array('controller' => 'accounts', 'action' => 'index')),
|
|
array('name' => 'Ledgers', 'url' => array('controller' => 'ledgers', 'action' => 'index')),
|
|
);
|
|
}
|
|
|
|
function beforeRender() {
|
|
$this->set('sidemenu', $this->sideMenuLinks());
|
|
}
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* action: jqGridData
|
|
* - Fetches the actual data requested by jqGrid as XML
|
|
*/
|
|
|
|
function jqGridData($model, $records, $query) {
|
|
// Assume we're debugging.
|
|
// The actual jqGrid request will set this to false
|
|
$debug = true;
|
|
|
|
$model_alias = $model->alias;
|
|
$model_id = $model_alias . '.id';
|
|
|
|
if (isset($this->passedArgs['debug']))
|
|
$debug = $this->passedArgs['debug'];
|
|
|
|
if (!$debug) {
|
|
$this->layout = null;
|
|
$this->autoLayout = false;
|
|
$this->autoRender = false;
|
|
Configure::write('debug', '0');
|
|
}
|
|
|
|
// Set up some defaults
|
|
$page = 1; // page number
|
|
$rows = 20; // rows in the grid - rowNum parameter
|
|
$sidx = $model_id; // sort column - index from colModel
|
|
$sord = 'ASC'; // sort order
|
|
|
|
// Extract the actual settings from the jqGrid request
|
|
if (isset($this->params['url']) && is_array($this->params['url']))
|
|
extract($this->params['url']);
|
|
|
|
// Unserialize our complex structure of fields
|
|
// This SHOULD be always set, except when debugging
|
|
if (isset($fields))
|
|
$fields = unserialize($fields);
|
|
else
|
|
$fields = array($model_id);
|
|
|
|
// Verify a few parameters and determine our starting row
|
|
$total = ($records < 0) ? 0 : ceil($records/$rows);
|
|
$page = ($page < 1) ? 1 : (($page > $total) ? $total : $page);
|
|
$start = $rows*$page - $rows;
|
|
|
|
// the actual query for the grid data
|
|
$query['group'] = $model_id;
|
|
$query['order'] = "$sidx $sord";
|
|
$query['limit'] = "$start, $rows";
|
|
$results = $model->find('all', $query);
|
|
|
|
if ($debug) {
|
|
ob_start();
|
|
print_r(compact('records', 'rows', 'total', 'page', 'start'));
|
|
}
|
|
else {
|
|
header("Content-type: text/xml;charset=utf-8");
|
|
}
|
|
|
|
echo "<?xml version='1.0' encoding='utf-8'?>\n";
|
|
echo "<rows>\n";
|
|
echo " <page>$page</page>\n";
|
|
echo " <total>$total</total>\n";
|
|
echo " <records>$records</records>\n";
|
|
|
|
foreach ($results AS $result) {
|
|
// Add the calculated fields (if any), to the model fields
|
|
if (isset($result[0]))
|
|
$result[$model_alias] += $result[0];
|
|
|
|
echo " <row id='{$result[$model_alias]['id']}'>\n";
|
|
foreach ($fields AS $field) {
|
|
list($tbl, $col) = explode(".", $field);
|
|
if (isset($col))
|
|
$data = $result[$tbl][$col];
|
|
else
|
|
$data = $result[$model_alias][$tbl];
|
|
|
|
// be sure to put text data in CDATA
|
|
if (preg_match("/^\d*$/", $data))
|
|
echo " <cell>$data</cell>\n";
|
|
else
|
|
echo " <cell><![CDATA[$data]]></cell>\n";
|
|
}
|
|
echo " </row>\n";
|
|
}
|
|
echo "</rows>\n";
|
|
|
|
if ($debug) {
|
|
$xml = ob_get_contents();
|
|
ob_end_clean();
|
|
|
|
$xml = preg_replace("/&/", "&", $xml);
|
|
$xml = preg_replace("/</", "<", $xml);
|
|
$xml = preg_replace("/>/", ">", $xml);
|
|
|
|
echo ("\n<PRE>\n$xml\n</PRE>\n");
|
|
}
|
|
}
|
|
|
|
}
|
|
?>
|