Added jqGrid 3.4.4 and started the work to upgrade our table to use it. The work is by no means done, but it is at leasting working to some degree. I have some customer changes in mind and want to switch gears, so I'm checking in.
git-svn-id: file:///svn-source/pmgr/branches/ledger_transactions_20090605/site@103 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -102,11 +102,160 @@ class CustomersController extends AppController {
|
||||
function all() {
|
||||
$title = 'All Customers';
|
||||
$this->set('title', $title); $this->set('heading', $title);
|
||||
$this->set('customers', $this->paginate());
|
||||
$this->render('index');
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* action: data
|
||||
* -
|
||||
*/
|
||||
|
||||
function data($fields_str) {
|
||||
/* pr(array('fields' => $fields, */
|
||||
/* 'explode' => explode(";", $fields_str))); */
|
||||
|
||||
$fields = explode(";", $fields_str);
|
||||
|
||||
//$fields=array();
|
||||
/* foreach (explode(";", $fields_str) AS $i => $field) { */
|
||||
/* pr(array('field' => $field, */
|
||||
/* 'explode' => explode(".", $field))); */
|
||||
/* list($tbl, $col) = explode(".", $field); */
|
||||
/* unset($fields[$i]); */
|
||||
/* $fields[$tbl][] = $field; */
|
||||
/* } */
|
||||
|
||||
//pr(array('fields' => $fields));
|
||||
|
||||
$debug = true;
|
||||
if (isset($this->passedArgs['debug']))
|
||||
$debug = $this->passedArgs['debug'];
|
||||
|
||||
$this->autoRender = false;
|
||||
if (!$debug) {
|
||||
$this->layout = null;
|
||||
$this->autoLayout = false;
|
||||
$this->autoRender = false;
|
||||
Configure::write('debug', '0');
|
||||
}
|
||||
|
||||
$page = 1; // page number
|
||||
$rows = 20; // rows in the grid - rowNum parameter
|
||||
$sidx = 'Customer.id'; // sort column - index from colModel
|
||||
$sord = 'ASC'; // sort order
|
||||
|
||||
if (isset($this->params['url']) && is_array($this->params['url']))
|
||||
extract($this->params['url']);
|
||||
|
||||
// calculate the number of rows for the query. We need this for paging the result
|
||||
$row = $this->Customer->findCount();
|
||||
$count = $row;
|
||||
|
||||
// calculate the total pages for the query
|
||||
if( $count > 0 ) {
|
||||
$total_pages = ceil($count/$rows);
|
||||
} else {
|
||||
$total_pages = 0;
|
||||
}
|
||||
|
||||
// if for some reasons the requested page is greater than the total
|
||||
// set the requested page to total page
|
||||
if ($page > $total_pages) $page=$total_pages;
|
||||
|
||||
// calculate the starting position of the rows
|
||||
$start = $rows*$page - $rows;
|
||||
|
||||
// if for some reasons start position is negative set it to 0
|
||||
// typical case is that the user type 0 for the requested page
|
||||
if($start <0) $start = 0;
|
||||
|
||||
// the actual query for the grid data
|
||||
$customers = $this->Customer->find
|
||||
('all',
|
||||
array('contain' => array
|
||||
(// Models
|
||||
/* 'Contact' => */
|
||||
/* array(// Models */
|
||||
/* 'ContactPhone', */
|
||||
/* 'ContactEmail', */
|
||||
/* 'ContactAddress', */
|
||||
/* ), */
|
||||
|
||||
'Account' =>
|
||||
array('fields' => array('Account.id')),
|
||||
|
||||
'CurrentLease' =>
|
||||
array('fields' => array(),
|
||||
'Unit' =>
|
||||
array('fields' => array('name')),
|
||||
),
|
||||
),
|
||||
//'link' => array('fields' => $fields),
|
||||
'order' => "$sidx $sord",
|
||||
'limit' => "$start, $rows",
|
||||
));
|
||||
|
||||
//pr($customers);
|
||||
|
||||
if ($debug) {
|
||||
ob_start();
|
||||
}
|
||||
else {
|
||||
if ( stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml") ) {
|
||||
header("Content-type: application/xhtml+xml;charset=utf-8");
|
||||
} else {
|
||||
header("Content-type: text/xml;charset=utf-8");
|
||||
}
|
||||
|
||||
echo "<?xml version='1.0' encoding='utf-8'?>\n";
|
||||
}
|
||||
|
||||
echo "<rows>\n";
|
||||
/* echo " <parms>\n"; */
|
||||
/* echo " <a><![CDATA[{$a}]]></a>\n"; */
|
||||
/* echo " <b><![CDATA[{$b}]]></b>\n"; */
|
||||
/* echo " <c><![CDATA[{$c}]]></c>\n"; */
|
||||
/* echo " <d><![CDATA[{$d}]]></d>\n"; */
|
||||
/* echo " <named><![CDATA[" . print_r($this->params, true) . "]]></named>\n"; */
|
||||
/* echo " <passed><![CDATA[" . print_r($this->passedArgs, true) . "]]></passed>\n"; */
|
||||
/* echo " </parms>\n"; */
|
||||
echo " <page>".$page."</page>\n";
|
||||
echo " <total>".$total_pages."</total>\n";
|
||||
echo " <records>".$count."</records>\n";
|
||||
|
||||
// be sure to put text data in CDATA
|
||||
foreach ($customers AS $customer) {
|
||||
$customer['Customer']['units'] =
|
||||
implode("; ",
|
||||
array_map(create_function
|
||||
('$lease', 'return $lease["Unit"]["name"];'),
|
||||
$customer['CurrentLease']));
|
||||
|
||||
echo " <row id='{$customer['Customer']['id']}'>\n";
|
||||
foreach ($fields AS $field) {
|
||||
list($tbl, $col) = explode(".", $field);
|
||||
echo " <cell><![CDATA[{$customer[$tbl][$col]}]]></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");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
|
||||
Reference in New Issue
Block a user