4 require_once 'Pman.php';
8 * not really sure how save our factory method is....!!!
11 * Uses these methods of the dataobjects:
12 * - checkPerm('L'/'E'/'A', $authuser) - can we list the stuff
14 * - applySort($au, $sortcol, $direction, $array_of_columns, $multisort) -- does not support multisort at present..
15 * - applyFilters($_REQUEST, $authUser) -- apply any query filters on data. and hide stuff not to be seen.
16 * - postListExtra($_REQUEST) : array(extra_data) - add extra column data on the results (like new messages etc.)
17 * - postListFilter($data, $authUser, $request) return $data - add extra data to an object
19 * - toRooSingleArray($authUser, $request) // single fetch, add data..
20 * - toRooArray($request) /// toArray if you need to return different data.. for a list fetch.
23 * - beforeDelete($ar) -- return false for fail and set DO->err;
24 * Argument is an array of un-find/fetched dependant items.
25 * - onUpdate($old, $request,$roo) - after update // return value ignored
26 * - onInsert($request,$roo) - after insert
28 * - setFromRoo($ar) - values from post (deal with dates etc.) - return true|error string.
30 * - toEventString (for logging - this is generically prefixed to all database operations.)
33 class Pman_Roo extends Pman
37 var $key; // used by update currenly to store primary key.
40 parent::getAuth(); // load company!
41 $au = $this->getAuthUser();
43 $this->jerr("Not authenticated", array('authFailure' => true));
45 $this->authUser = $au;
49 * GET method Roo/TABLENAME.php
50 * -- defaults to listing data. with args.
53 * !colname=.... => colname != ....
54 * !colname[0]=... !colname[1]=... => colname NOT IN (.....) ** only supports main table at present..
55 * colname[0]=... colname[1]=... => colname IN (.....) ** only supports main table at present..
58 * _post = simulate a post with debuggin on.
59 * lookup = array( k=>v) single fetch based on a key/value pair
60 * _id = single fetch based on id.
61 * _delete = delete a list of ids element. (seperated by ,);
62 * _columns = comma seperated list of columns.
63 * _distinct = a distinct column lookup.
64 * _requestMeta = default behaviour of Roo stores.. on first query..
66 * csvCols[0] csvCols[1].... = .... column titles for CSV output
68 * csvTitles[0], csvTitles[1] .... = columns to use for CSV output
70 * sort = sort column (',' comma delimited)
71 * dir = sort direction ?? in future comma delimited...
72 * _multisort = JSON encoded { sort : { row : direction }, order : [ row, row, row ] }
74 * limit = limit number
76 * _toggleActive !:!:!:! - this hsould not really be here..
77 * query[add_blank] - add a line in with an empty option... - not really needed???
82 // $this->jerr("Not authenticated", array('authFailure' => true));
83 //echo '<PRE>';print_R($_GET);
84 //DB_DataObject::debuglevel(1);
86 $this->init(); // from pnan.
87 //DB_DataObject::debuglevel(1);
88 HTML_FlexyFramework::get()->generateDataobjectsCache($this->isDev);
90 if (!empty($_GET['_post'])) {
92 //DB_DAtaObject::debuglevel(1);
93 return $this->post($tab);
95 $tab = str_replace('/', '',$tab); // basic protection??
97 $x = DB_DataObject::factory($tab);
99 if (!is_a($x, 'DB_DataObject')) {
100 $this->jerr('invalid url');
102 $_columns = !empty($_REQUEST['_columns']) ? explode(',', $_REQUEST['_columns']) : false;
104 if (isset( $_REQUEST['lookup'] )) { // single fetch based on key/value pairs
105 if (method_exists($x, 'checkPerm') && !$x->checkPerm('S', $this->authUser)) {
106 $this->jerr("PERMISSION DENIED");
108 $this->loadMap($x, $_columns);
109 $x->setFrom($_REQUEST['lookup'] );
111 if (!$x->find(true)) {
114 $this->jok($x->toArray());
119 if (isset($_REQUEST['_id'])) { // single fetch
121 if (empty($_REQUEST['_id'])) {
122 $this->jok($x->toArray()); // return an empty array!
125 $this->loadMap($x, $_columns);
127 if (!$x->get($_REQUEST['_id'])) {
128 $this->jerr("no such record");
131 if (method_exists($x, 'checkPerm') && !$x->checkPerm('S', $this->authUser)) {
132 $this->jerr("PERMISSION DENIED");
135 $this->jok(method_exists($x, 'toRooSingleArray') ? $x->toRooSingleArray($this->authUser, $_REQUEST) : $x->toArray());
140 if (isset($_REQUEST['_delete'])) {
144 $this->jerr('no key');
147 $this->key = $keys[0];
150 // do we really delete stuff!?!?!?
151 return $this->delete($x,$_REQUEST);
157 if (isset($_REQUEST['_toggleActive'])) {
158 // do we really delete stuff!?!?!?
159 if (!$this->hasPerm("Core.Staff", 'E')) {
160 $this->jerr("PERMISSION DENIED");
162 $clean = create_function('$v', 'return (int)$v;');
163 $bits = array_map($clean, explode(',', $_REQUEST['_toggleActive']));
164 if (in_array($this->authUser->id, $bits) && $this->authUser->active) {
165 $this->jerr("you can not disable yourself");
167 $x->query('UPDATE Person SET active = !active WHERE id IN (' .implode(',', $bits).')');
168 $this->addEvent("USERTOGGLE", false, implode(',', $bits));
169 $this->jok("Updated");
172 //DB_DataObject::debugLevel(1);
173 if (method_exists($x, 'checkPerm') && !$x->checkPerm('S', $this->authUser)) {
174 $this->jerr("PERMISSION DENIED");
177 // sets map and countWhat
178 $this->loadMap($x, $_columns, empty($_REQUEST['_distinct']) ? false: $_REQUEST['_distinct']);
180 $this->setFilters($x,$_REQUEST);
183 // build join if req.
184 //DB_DataObject::debugLevel(1);
185 $total = $x->count($this->countWhat);
188 //var_dump($total);exit;
189 $this->applySort($x);
194 empty($_REQUEST['start']) ? 0 : (int)$_REQUEST['start'],
195 min(empty($_REQUEST['limit']) ? 25 : (int)$_REQUEST['limit'], 5000)
198 $queryObj = clone($x);
199 //DB_DataObject::debuglevel(1);
206 if (!empty($_REQUEST['query']['add_blank'])) {
207 $ret[] = array( 'id' => 0, 'name' => '----');
212 //if (($tab == 'Groups') && ($_REQUEST['type'] != 0)) { // then it's a list of teams..
213 if ($tab == 'Groups') {
215 $ret[] = array( 'id' => 0, 'name' => 'EVERYONE');
216 $ret[] = array( 'id' => -1, 'name' => 'NOT_IN_GROUP');
217 //$ret[] = array( 'id' => 999999, 'name' => 'ADMINISTRATORS');
224 $rooar = method_exists($x, 'toRooArray');
226 while ($x->fetch()) {
228 $add = $rooar ? $x->toRooArray($_REQUEST) : $x->toArray();
230 $ret[] = !$_columns ? $add : array_intersect_key($add, array_flip($_columns));
233 if (method_exists($queryObj ,'postListExtra')) {
234 $extra = $queryObj->postListExtra($_REQUEST);
236 // filter results, and add any data that is needed...
237 if (method_exists($x,'postListFilter')) {
238 $ret = $x->postListFilter($ret, $this->authUser, $_REQUEST);
241 if (!empty($_REQUEST['csvCols']) && !empty($_REQUEST['csvTitles']) ) {
242 header('Content-type: text/csv');
244 header('Content-Disposition: attachment; filename="list-export-'.date('Y-m-d') . '.csv"');
245 //header('Content-type: text/plain');
246 $fh = fopen('php://output', 'w');
247 fputcsv($fh, $_REQUEST['csvTitles']);
250 foreach($ret as $x) {
251 //echo "<PRE>"; print_r(array($_REQUEST['csvCols'], $x->toArray())); exit;
253 foreach($_REQUEST['csvCols'] as $k) {
254 $line[] = isset($x[$k]) ? $x[$k] : '';
265 //if ($x->tableName() == 'Documents_Tracking') {
266 // $ret = $this->replaceSubject(&$ret, 'doc_id_subject');
271 if (!empty($_REQUEST['_requestMeta']) && count($ret)) {
272 $meta = $this->meta($x, $ret);
274 $extra['metaData'] = $meta;
278 // echo "<PRE>"; print_r($ret);
279 $this->jdata($ret,$total, $extra );
286 * apply REQUEST[sort] and [dir]
287 * sort may be an array of columsn..
289 * @arg DB_DataObject $x
292 function applySort($x, $sort = '', $dir ='')
295 // Db_DataObject::debugLevel(1);
296 $sort = empty($_REQUEST['sort']) ? $sort : $_REQUEST['sort'];
297 $dir = empty($_REQUEST['dir']) ? $dir : $_REQUEST['dir'];
298 $dir = $dir == 'ASC' ? 'ASC' : 'DESC';
300 $ms = empty($_REQUEST['_multisort']) ? false : $_REQUEST['_multisort'];
302 if (method_exists($x, 'applySort')) {
303 $sorted = $x->applySort(
307 array_keys($this->cols),
308 $ms ? json_decode($ms) : false
312 return $this->multiSort($x);
315 if ($sorted === false) {
318 $sort_ar = explode(',', $sort);
321 foreach($sort_ar as $sort) {
323 if (strlen($sort) && isset($cols[$sort]) ) {
324 $sort_str[] = $x->tableName() .'.'.$sort . ' ' . $dir ;
326 } else if (in_array($sort, array_keys($this->cols))) {
327 $sort_str[] = $sort . ' ' . $dir ;
332 $x->orderBy(implode(', ', $sort_str ));
337 function multiSort($x)
339 //DB_DataObject::debugLevel(1);
340 $ms = json_decode($_REQUEST['_multisort']);
345 foreach($ms->order as $col) {
346 if (!isset($ms->sort->{$col})) {
347 continue; // no direction..
349 $ms->sort->{$col} = $ms->sort->{$col} == 'ASC' ? 'ASC' : 'DESC';
351 if (strlen($col) && isset($cols[$col]) ) {
352 $sort_str[] = $x->tableName() .'.'.$col . ' ' . $ms->sort->{$col};
354 } else if (in_array($col, array_keys($this->cols))) {
355 $sort_str[] = $col. ' ' . $ms->sort->{$col};
360 $x->orderBy(implode(', ', $sort_str ));
370 * POST method Roo/TABLENAME.php
371 * -- updates the data..
374 * _debug - forces debugging on.
375 * _get - forces a get request
376 * _ids - multiple update of records.
377 * {colid} - forces fetching
380 function post($tab) // update / insert (?? dleete??)
382 //DB_DataObject::debugLevel(1);
383 if (!empty($_REQUEST['_debug'])) {
384 DB_DataObject::debugLevel(1);
387 if (!empty($_REQUEST['_get'])) {
388 return $this->get($tab);
391 $_columns = !empty($_REQUEST['_columns']) ? explode(',', $_REQUEST['_columns']) : false;
393 $tab = str_replace('/', '',$tab); // basic protection??
394 $x = DB_DataObject::factory($tab);
395 if (!is_a($x, 'DB_DataObject')) {
396 $this->jerr('invalid url');
398 // find the key and use that to get the thing..
401 $this->jerr('no key');
404 $this->key = $keys[0];
406 // delete should be here...
407 if (isset($_REQUEST['_delete'])) {
408 // do we really delete stuff!?!?!?
409 return $this->delete($x,$_REQUEST);
415 // not sure if this is a good idea here...
417 if (!empty($_REQUEST['_ids'])) {
418 $ids = explode(',',$_REQUEST['_ids']);
419 $x->whereAddIn($this->key, $ids, 'int');
420 $ar = $x->fetchAll();
422 $this->update($x, $_REQUEST);
426 $this->jok("UPDATED");
431 if (!empty($_REQUEST[$this->key])) {
433 if (!$x->get($this->key, $_REQUEST[$this->key])) {
434 $this->jerr("Invalid request");
436 $this->jok($this->update($x, $_REQUEST));
440 $this->jerr("No data recieved for inserting");
443 $this->jok($this->insert($x, $_REQUEST));
450 function insert($x, $req)
454 if (method_exists($x, 'checkPerm') && !$x->checkPerm('A', $this->authUser, $req)) {
455 $this->jerr("PERMISSION DENIED");
458 $_columns = !empty($req['_columns']) ? explode(',', $req['_columns']) : false;
460 if (method_exists($x, 'setFromRoo')) {
461 $res = $x->setFromRoo($req, $this);
462 if (is_string($res)) {
472 if (isset($cols['created'])) {
473 $x->created = date('Y-m-d H:i:s');
475 if (isset($cols['created_dt'])) {
476 $x->created_dt = date('Y-m-d H:i:s');
478 if (isset($cols['created_by'])) {
479 $x->created_by = $this->authUser->id;
483 if (isset($cols['modified'])) {
484 $x->modified = date('Y-m-d H:i:s');
486 if (isset($cols['modified_dt'])) {
487 $x->modified_dt = date('Y-m-d H:i:s');
489 if (isset($cols['modified_by'])) {
490 $x->modified_by = $this->authUser->id;
493 if (isset($cols['updated'])) {
494 $x->updated = date('Y-m-d H:i:s');
496 if (isset($cols['updated_dt'])) {
497 $x->updated_dt = date('Y-m-d H:i:s');
499 if (isset($cols['updated_by'])) {
500 $x->updated_by = $this->authUser->id;
508 if ($res === false) {
509 $this->jerr($x->_lastError->toString());
511 if (method_exists($x, 'onInsert')) {
512 $x->onInsert($_REQUEST, $this);
514 $ev = $this->addEvent("ADD", $x);
519 // note setFrom might handle this before hand...!??!
520 if (!empty($_FILES) && method_exists($x, 'onUpload')) {
524 $r = DB_DataObject::factory($x->tableName());
525 // let's assume it has a key!!!
527 $r->{$this->key} = $x->{$this->key};
528 $this->loadMap($r, $_columns);
532 $rooar = method_exists($r, 'toRooArray');
533 //print_r(var_dump($rooar)); exit;
534 return $rooar ? $r->toRooArray($_REQUEST) : $r->toArray();
538 function update($x, $req)
540 if (method_exists($x, 'checkPerm') && !$x->checkPerm('E', $this->authUser, $_REQUEST)) {
541 $this->jerr("PERMISSION DENIED");
545 // only done if we recieve a lock_id.
546 // we are very trusing here.. that someone has not messed around with locks..
547 // the object might want to check in their checkPerm - if locking is essential..
548 $lock_warning = false;
549 $lock = DB_DataObjecT::factory('Core_locking');
550 if (is_a($lock,'DB_DataObject')) {
552 $lock->on_id = $x->{$this->key};
553 $lock->on_table= $x->tableName();
554 if (!empty($_REQUEST['_lock_id'])) {
555 $lock->whereAdd('id != ' . ((int)$_REQUEST['_lock_id']));
557 $lock->whereAdd('person_id !=' . $this->authUser->id);
561 if ($lock->find(true)) {
562 // it's locked by someone else..
563 $p = $lock->person();
564 $lock_warning = "Record was locked by " . $p->name . " at " .$lock->created.
565 " - Your changes have been saved - you may like to warn them if " .
566 " they are editing now";
568 // check the users lock.. - no point.. ??? - if there are no other locks and it's not the users, then they can
569 // edit it anyways...
578 $_columns = !empty($req['_columns']) ? explode(',', $req['_columns']) : false;
583 // this lot is generic.. needs moving
584 if (method_exists($x, 'setFromRoo')) {
585 $res = $x->setFromRoo($req, $this);
586 if (is_string($res)) {
592 $ev = $this->addEvent("EDIT", $x);
593 $ev->audit($x, $old);
599 if (isset($cols['modified'])) {
600 $x->modified = date('Y-m-d H:i:s');
602 if (isset($cols['modified_dt'])) {
603 $x->modified_dt = date('Y-m-d H:i:s');
605 if (isset($cols['modified_by'])) {
606 $x->modified_by = $this->authUser->id;
609 if (isset($cols['updated'])) {
610 $x->updated = date('Y-m-d H:i:s');
612 if (isset($cols['updated_dt'])) {
613 $x->updated_dt = date('Y-m-d H:i:s');
615 if (isset($cols['updated_by'])) {
616 $x->updated_by = $this->authUser->id;
619 //DB_DataObject::DebugLevel(1);
620 $res = $x->update($old);
621 if ($res === false) {
622 $this->jerr($x->_lastError->toString());
625 if (method_exists($x, 'onUpdate')) {
626 $x->onUpdate($old, $req, $this);
631 $this->jerr($lock_warning);
635 $r = DB_DataObject::factory($x->tableName());
636 // let's assume it has a key!!!
637 $r->{$this->key}= $x->{$this->key};
638 $this->loadMap($r, $_columns);
641 $rooar = method_exists($r, 'toRooArray');
642 //print_r(var_dump($rooar)); exit;
643 return $rooar ? $r->toRooArray($_REQUEST) : $r->toArray();
646 * Delete a number of records.
647 * calls $delete_obj->beforeDelete($array_of_dependant_dataobjects)
651 function delete($x, $req)
653 // do we really delete stuff!?!?!?
654 if (empty($req['_delete'])) {
655 $this->jerr("Delete Requested with no value");
657 // build a list of tables to queriy for dependant data..
662 $all_links = $GLOBALS['_DB_DATAOBJECT']['LINKS'][$x->_database];
663 foreach($all_links as $tbl => $links) {
664 foreach($links as $col => $totbl_col) {
665 $to = explode(':', $totbl_col);
666 if ($to[0] != $x->tableName()) {
670 $affects[$tbl .'.' . $col] = true;
676 // echo '<PRE>';print_r($affects);exit;
677 //DB_Dataobject::debugLevel(1);
680 $clean = create_function('$v', 'return (int)$v;');
682 $bits = array_map($clean, explode(',', $req['_delete']));
684 // print_r($bits);exit;
686 // let's assume it has a key!!!
689 $x->whereAdd($this->key .' IN ('. implode(',', $bits) .')');
691 $this->jerr("Nothing found to delete");
694 while ($x->fetch()) {
700 if (method_exists($x, 'checkPerm') && !$x->checkPerm('D', $this->authUser)) {
701 $this->jerr("PERMISSION DENIED");
705 foreach($affects as $k=> $true) {
706 $ka = explode('.', $k);
707 $chk = DB_DataObject::factory($ka[0]);
708 if (!is_a($chk,'DB_DataObject')) {
709 $this->jerr('Unable to load referenced table, check the links config: ' .$ka[0]);
711 $chk->{$ka[1]} = $xx->{$this->key};
712 $matches = $chk->count();
715 $match_ar[] = clone($chk);
720 $has_beforeDelete = method_exists($xx, 'beforeDelete');
721 // before delte = allows us to trash dependancies if needed..
724 if ( method_exists($xx, 'beforeDelete') ) {
725 if ($xx->beforeDelete($match_ar) === false) {
726 $errs[] = "Delete failed ({$xx->id})\n".
727 (isset($xx->err) ? $xx->err : '');
733 foreach($affects as $k=> $true) {
734 $ka = explode('.', $k);
735 $chk = DB_DataObject::factory($ka[0]);
736 if (!is_a($chk,'DB_DataObject')) {
737 $this->jerr('Unable to load referenced table, check the links config: ' .$ka[0]);
739 $chk->{$ka[1]} = $xx->$pk;
740 $matches = $chk->count();
741 $match_total += $matches;
743 $match_ar[] = clone($chk);
753 if (!empty($match_ar)) {
756 $o = $chk->fetchAll();
758 $desc = $chk->tableName(). '.' . $key .'='.$xx->$key ;
759 if (method_exists($chk, 'toEventString')) {
760 $desc .= ' : ' . $o[0]->toEventString();
763 $this->jerr("Delete Dependant records ($match_total found), " .
764 "first is ( $desc )");
771 $this->addEvent("DELETE", $x);
776 $this->jerr(implode("\n<BR>", $errs));
778 $this->jok("Deleted");
786 function loadMap($do, $filter=false, $distinct = false)
788 //DB_DataObject::debugLevel(1);
790 $this->countWhat = false;
796 $mods = explode(',',$this->appModules);
798 $ff = HTML_FlexyFramework::get();
805 $tabdef = $do->table();
806 if (isset($tabdef['passwd'])) {
807 // prevent exposure of passwords..
808 unset($tabdef['passwd']);
811 $xx = array_keys($tabdef);
812 $do->selectAdd(); // we need thsi as normally it's only cleared by an empty selectAs call.
814 $selectAs = array(array( $xx , '%s', false));
816 $has_distinct = false;
817 if ($filter || $distinct) {
819 //echo '<PRE>' ;print_r($filter);exit;
821 if ($distinct && $distinct == $c) {
822 $has_distinct = 'DISTINCT( ' . $do->tableName() .'.'. $c .') as ' . $c;
823 $this->countWhat = 'DISTINCT ' . $do->tableName() .'.'. $c .'';
826 if (!$filter || in_array($c, $filter)) {
832 $selectAs = empty($cols) ? array() : array(array( $cols , '%s', false)) ;
838 $this->cols = array();
839 $this->colsJoinName =array();
841 $this->cols[$k] = $do->tableName(). '.' . $k;
849 foreach($map as $ocl=>$info) {
851 list($tab,$col) = explode(':', $info);
852 // what about multiple joins on the same table!!!
853 $xx = DB_DataObject::factory($tab);
854 if (!is_a($xx, 'DB_DataObject')) {
857 // this is borked ... for multiple jions..
858 $do->joinAdd($xx, 'LEFT', 'join_'.$ocl.'_'. $col, $ocl);
859 $tabdef = $xx->table();
860 $table = $xx->tableName();
861 if (isset($tabdef['passwd'])) {
863 unset($tabdef['passwd']);
866 $xx = array_keys($tabdef);
869 if ($filter || $distinct) {
872 $tn = sprintf($ocl.'_%s', $c);
873 // echo '<PRE>'; var_dump($tn);
874 if ($distinct && $tn == $distinct) {
875 $has_distinct = 'DISTINCT( ' . 'join_'.$ocl.'_'.$col.'.'.$k .') as ' . $tn ;
876 $this->countWhat = 'DISTINCT join_'.$ocl.'_'.$col.'.'.$k;
881 if (!$filter || in_array($tn, $filter)) {
886 $selectAs[] = array($cols, $ocl.'_%s', 'join_'.$ocl.'_'. $col);
891 $selectAs[] = array($xx, $ocl.'_%s', 'join_'.$ocl.'_'. $col);
897 $this->cols[sprintf($ocl.'_%s', $k)] = $tab.'.'.$k;
898 $this->colsJname[sprintf($ocl.'_%s', $k)] = 'join_'.$ocl.'_'.$col.'.'.$k;
905 $do->selectAdd($has_distinct);
908 // we do select as after everything else as we need to plop distinct at the beginning??
910 // echo '<PRE>';print_r($this->colsJname);exit;
911 foreach($selectAs as $ar) {
912 $do->selectAs($ar[0], $ar[1], $ar[2]);
918 * generate the meta data neede by queries.
921 function meta($x, $data)
923 // this is not going to work on queries where the data does not match the database def..
924 // for unknown columns we send them as stirngs..
926 $cols = array_keys($data[0]);
931 //echo '<PRE>';print_r($this->cols); exit;
932 $options = &PEAR::getStaticProperty('DB_DataObject','options');
933 $reader = $options["ini_{$x->_database}"] .'.reader';
934 if (!file_exists( $reader )) {
938 $rdata = unserialize(file_get_contents($reader));
940 // echo '<PRE>';print_r($rdata);exit;
943 foreach($cols as $c ) {
944 if (!isset($this->cols[$c]) || !isset($rdata[$this->cols[$c]]) || !is_array($rdata[$this->cols[$c]])) {
948 $add = $rdata[$this->cols[$c]];
953 'totalProperty' => 'total',
954 'successProperty' => 'success',
963 function setFilters($x, $q)
965 // if a column is type int, and we get ',' -> the it should be come an inc clause..
966 // DB_DataObject::debugLevel(1);
967 if (method_exists($x, 'applyFilters')) {
968 // DB_DataObject::debugLevel(1);
969 $x->applyFilters($q, $this->authUser);
971 $q_filtered = array();
973 foreach($q as $key=>$val) {
975 // value is an array..
976 if (is_array($val) ) {
980 if ($key[0] == '!') {
982 $key = substr($key,1);
985 if (!in_array( $key, array_keys($this->cols))) {
989 // support a[0] a[1] ..... => whereAddIn(
992 foreach($val as $k=>$v) {
993 if (!is_numeric($k)) {
997 // FIXME: note this is not typesafe for anything other than mysql..
999 if (!is_numeric($v) || !is_long($v)) {
1008 $x->whereAddIn($pref . (
1009 isset($this->colsJname[$key]) ?
1010 $this->colsJname[$key] :
1011 ($x->tableName(). '.'.$key)),
1012 $ar, $quote ? 'string' : 'int');
1020 if ($key[0] == '!' && in_array(substr($key, 1), array_keys($this->cols))) {
1022 $key = substr($key, 1) ;
1025 isset($this->colsJname[$key]) ?
1026 $this->colsJname[$key] :
1027 $x->tableName(). '.'.$key ) . ' != ' .
1028 (is_numeric($val) ? $val : "'". $x->escape($val) . "'")
1038 // Events and remarks -- fixme - move to events/remarsk...
1039 case 'on_id': // where TF is this used...
1040 if (!empty($q['query']['original'])) {
1041 // DB_DataObject::debugLevel(1);
1042 $o = (int) $q['query']['original'];
1044 $x->whereAdd("(on_id = $oid OR
1045 on_id IN ( SELECT distinct(id) FROM Documents WHERE original = $o )
1055 $q_filtered[$key] = $val;
1058 // subjoined columns = check the values.
1059 // note this is not typesafe for anything other than mysql..
1061 if (isset($this->colsJname[$key])) {
1063 if (!is_numeric($val) || !is_long($val)) {
1066 $x->whereAdd( "{$this->colsJname[$key]} = " . ($quote ? "'". $x->escape($val) ."'" : $val));
1075 $x->setFrom($q_filtered);
1080 // nice generic -- let's get rid of it.. where is it used!!!!
1082 // Person / Group / most of my queries noww...
1083 if (!empty($q['query']['name'])) {
1084 $x->whereAdd($x->tableName().".name LIKE '". $x->escape($q['query']['name']) . "%'");
1087 // - projectdirectory staff list - persn queuy