function get($tab)
{
// $this->jerr("Not authenticated", array('authFailure' => true));
- // DB_DataObject::debuglevel(1);
+ //echo '<PRE>';print_R($_GET); DB_DataObject::debuglevel(1);
$this->init(); // from pnan.
$this->jok("Updated");
}
- DB_DataObject::debugLevel(1);
+ //DB_DataObject::debugLevel(1);
if (method_exists($x, 'checkPerm') && !$x->checkPerm('S', $this->authUser)) {
$this->jerr("PERMISSION DENIED");
}
$this->loadMap($x, $_columns, empty($_REQUEST['_distinct']) ? false: $_REQUEST['_distinct']);
$this->setFilters($x,$_REQUEST);
-
-
-
+
+ //print_r($x);
// build join if req.
-
+ //DB_DataObject::debugLevel(1);
$total = $x->count($this->countWhat);
// sorting..
- // DB_DataObject::debugLevel(1);
-
+ //
+ //var_dump($total);exit;
$this->applySort($x);
* @arg DB_DataObject $x
*
*/
- function applySort($x)
+ function applySort($x, $sort = '', $dir ='')
{
// Db_DataObject::debugLevel(1);
- $sort = empty($_REQUEST['sort']) ? '' : $_REQUEST['sort'];
- $dir = (empty($_REQUEST['dir']) || strtoupper($_REQUEST['dir']) == 'ASC' ? 'ASC' : 'DESC');
+ $sort = empty($_REQUEST['sort']) ? $sort : $_REQUEST['sort'];
+ $dir = empty($_REQUEST['dir']) ? $dir : $_REQUEST['dir'];
+ $dir = $dir == 'ASC' ? 'ASC' : 'DESC';
$xx = array_keys($tabdef);
$do->selectAdd(); // we need thsi as normally it's only cleared by an empty selectAs call.
- $selectAs = array(array( $xx , '%s'));
+ $selectAs = array(array( $xx , '%s', false));
$this->countWhat = false;
$has_distinct = false;
if ($filter || $distinct) {
$cols = array();
- // echo '<PRE>' ;print_r($xx);exit;
+ //echo '<PRE>' ;print_r($filter);exit;
foreach($xx as $c) {
if ($distinct && $distinct == $c) {
$has_distinct = 'DISTINCT( ' . $do->tableName() .'.'. $c .') as ' . $c;
$cols[] = $c;
}
}
- echo '<PRE>' ;print_r($cols);exit;
- $selectAs = array(array( $cols , '%s'));
+
+
+ $selectAs = empty($cols) ? array() : array(array( $cols , '%s', false)) ;
+
+
}
$cols = array();
foreach($xx as $c) {
$tn = sprintf($ocl.'_%s', $c);
+ // echo '<PRE>'; var_dump($tn);
if ($distinct && $tn == $distinct) {
- $has_distinct = 'DISTINCT( ' . 'join_'.$ocl.'_'.$col.'.'.$k .') as ' . $tc ;
+ $has_distinct = 'DISTINCT( ' . 'join_'.$ocl.'_'.$col.'.'.$k .') as ' . $tn ;
$this->countWhat = 'DISTINCT join_'.$ocl.'_'.$col.'.'.$k;
continue;
}
$cols[] = $c;
}
}
- $selectAs[] = array($cols, $ocl.'_%s', 'join_'.$ocl.'_'. $col);
+ if (!empty($cols)) {
+ $selectAs[] = array($cols, $ocl.'_%s', 'join_'.$ocl.'_'. $col);
+ }
+
} else {
$selectAs[] = array($xx, $ocl.'_%s', 'join_'.$ocl.'_'. $col);
}
if ($has_distinct) {
- $this->selectAdd($has_distinct);
+ $do->selectAdd($has_distinct);
}
//DB_DataObject::debugLevel(1);
// we do select as after everything else as we need to plop distinct at the beginning??
/// well I assume..
- echo '<PRE>';print_r($selectAs );exit;
+ // echo '<PRE>';print_r($this->colsJname);exit;
foreach($selectAs as $ar) {
- $do->selectAs($ar[0], $ar[1]);
+ $do->selectAs($ar[0], $ar[1], $ar[2]);
}
$x->whereAddIn(
- isset($this->colsJoinName[$key]) ?
- $this->colsJoinName[$key] :
- $x->tableName(). '.'.$key,
+ isset($this->colsJname[$key]) ?
+ $this->colsJname[$key] :
+ ($x->tableName(). '.'.$key),
$ar, $quote ? 'string' : 'int');
}
$key = substr($key, 1) ;
$x->whereAdd( (
- isset($this->colsJoinName[$key]) ?
- $this->colsJoinName[$key] :
+ isset($this->colsJname[$key]) ?
+ $this->colsJname[$key] :
$x->tableName(). '.'.$key ) . ' != ' .
(is_numeric($val) ? $val : "'". $x->escape($val) . "'")
);