4 require_once 'Pman.php';
8 * not really sure how save our factory method is....!!!
11 * Uses these methods of the dataobjects:
13 * - checkPerm('L'/'E'/'A', $authuser) - can we list the stuff
15 * - applySort($au, $sortcol, $direction, $array_of_columns, $multisort) -- does not support multisort at present..
16 * - applyFilters($_REQUEST, $authUser, $roo) -- apply any query filters on data. and hide stuff not to be seen.
17 * - postListExtra($_REQUEST) : array(extra_name => data) - add extra column data on the results (like new messages etc.)
18 * - postListFilter($data, $authUser, $request) return $data - add extra data to an object
20 * - toRooSingleArray($authUser, $request) // single fetch, add data..
21 * - toRooArray($request) /// toArray if you need to return different data.. for a list fetch.
24 * CRUD - before/after handlers..
25 * - setFromRoo($ar, $roo) - values from post (deal with dates etc.) - return true|error string.
26 * ... call $roo->jerr() on failure...
29 * - beforeDelete($dependants_array, $roo) Argument is an array of un-find/fetched dependant items.
30 * - jerr() will stop insert.. (Prefered)
31 * - return false for fail and set DO->err;
32 * - beforeUpdate($old, $request,$roo) - after update - jerr() will stop insert..
33 * - beforeInsert($request,$roo) - before insert - jerr() will stop insert..
36 * - onUpdate($old, $request,$roo) - after update // return value ignored
37 * - onInsert($request,$roo) - after insert
42 * - toEventString (for logging - this is generically prefixed to all database operations.)
45 class Pman_Roo extends Pman
49 var $key; // used by update currenly to store primary key.
52 parent::getAuth(); // load company!
53 $au = $this->getAuthUser();
55 $this->jerr("Not authenticated", array('authFailure' => true));
57 $this->authUser = $au;
61 * GET method Roo/TABLENAME.php
62 * -- defaults to listing data. with args.
65 * !colname=.... => colname != ....
66 * !colname[0]=... !colname[1]=... => colname NOT IN (.....) ** only supports main table at present..
67 * colname[0]=... colname[1]=... => colname IN (.....) ** only supports main table at present..
70 * _post = simulate a post with debuggin on.
71 * lookup = array( k=>v) single fetch based on a key/value pair
72 * _id = single fetch based on id.
73 * _delete = delete a list of ids element. (seperated by ,);
74 * _columns = comma seperated list of columns.
75 * _distinct = a distinct column lookup.
76 * _requestMeta = default behaviour of Roo stores.. on first query..
78 * csvCols[0] csvCols[1].... = .... column titles for CSV output
80 * csvTitles[0], csvTitles[1] .... = columns to use for CSV output
82 * sort = sort column (',' comma delimited)
83 * dir = sort direction ?? in future comma delimited...
84 * _multisort = JSON encoded { sort : { row : direction }, order : [ row, row, row ] }
86 * limit = limit number
88 * _toggleActive !:!:!:! - this hsould not really be here..
89 * query[add_blank] - add a line in with an empty option... - not really needed???
94 // $this->jerr("Not authenticated", array('authFailure' => true));
95 //echo '<PRE>';print_R($_GET);
96 //DB_DataObject::debuglevel(1);
98 $this->init(); // from pnan.
99 //DB_DataObject::debuglevel(1);
100 HTML_FlexyFramework::get()->generateDataobjectsCache($this->isDev);
102 if (!empty($_GET['_post'])) {
104 //DB_DAtaObject::debuglevel(1);
105 return $this->post($tab);
107 $tab = str_replace('/', '',$tab); // basic protection??
109 $x = DB_DataObject::factory($tab);
111 if (!is_a($x, 'DB_DataObject')) {
112 $this->jerr('invalid url');
114 $_columns = !empty($_REQUEST['_columns']) ? explode(',', $_REQUEST['_columns']) : false;
116 if (isset( $_REQUEST['lookup'] )) { // single fetch based on key/value pairs
117 if (method_exists($x, 'checkPerm') && !$x->checkPerm('S', $this->authUser)) {
118 $this->jerr("PERMISSION DENIED");
120 $this->loadMap($x, $_columns);
121 $x->setFrom($_REQUEST['lookup'] );
123 if (!$x->find(true)) {
126 $this->jok($x->toArray());
131 if (isset($_REQUEST['_id'])) { // single fetch
133 if (empty($_REQUEST['_id'])) {
134 $this->jok($x->toArray()); // return an empty array!
137 $this->loadMap($x, $_columns);
139 if (!$x->get($_REQUEST['_id'])) {
140 $this->jerr("no such record");
143 if (method_exists($x, 'checkPerm') && !$x->checkPerm('S', $this->authUser)) {
144 $this->jerr("PERMISSION DENIED");
147 $this->jok(method_exists($x, 'toRooSingleArray') ? $x->toRooSingleArray($this->authUser, $_REQUEST) : $x->toArray());
152 if (isset($_REQUEST['_delete'])) {
156 $this->jerr('no key');
159 $this->key = $keys[0];
162 // do we really delete stuff!?!?!?
163 return $this->delete($x,$_REQUEST);
169 if (isset($_REQUEST['_toggleActive'])) {
170 // do we really delete stuff!?!?!?
171 if (!$this->hasPerm("Core.Staff", 'E')) {
172 $this->jerr("PERMISSION DENIED");
174 $clean = create_function('$v', 'return (int)$v;');
175 $bits = array_map($clean, explode(',', $_REQUEST['_toggleActive']));
176 if (in_array($this->authUser->id, $bits) && $this->authUser->active) {
177 $this->jerr("you can not disable yourself");
179 $x->query('UPDATE Person SET active = !active WHERE id IN (' .implode(',', $bits).')');
180 $this->addEvent("USERTOGGLE", false, implode(',', $bits));
181 $this->jok("Updated");
184 //DB_DataObject::debugLevel(1);
185 if (method_exists($x, 'checkPerm') && !$x->checkPerm('S', $this->authUser)) {
186 $this->jerr("PERMISSION DENIED");
189 // sets map and countWhat
190 $this->loadMap($x, $_columns, empty($_REQUEST['_distinct']) ? false: $_REQUEST['_distinct']);
192 $this->setFilters($x,$_REQUEST);
195 // build join if req.
196 //DB_DataObject::debugLevel(1);
197 $total = $x->count($this->countWhat);
200 //var_dump($total);exit;
201 $this->applySort($x);
206 empty($_REQUEST['start']) ? 0 : (int)$_REQUEST['start'],
207 min(empty($_REQUEST['limit']) ? 25 : (int)$_REQUEST['limit'], 5000)
210 $queryObj = clone($x);
211 //DB_DataObject::debuglevel(1);
212 if (false === $x->find()) {
213 $this->jerr($x->_lastError->toString());
221 if (!empty($_REQUEST['query']['add_blank'])) {
222 $ret[] = array( 'id' => 0, 'name' => '----');
227 //if (($tab == 'Groups') && ($_REQUEST['type'] != 0)) { // then it's a list of teams..
228 if ($tab == 'Groups') {
230 $ret[] = array( 'id' => 0, 'name' => 'EVERYONE');
231 $ret[] = array( 'id' => -1, 'name' => 'NOT_IN_GROUP');
232 //$ret[] = array( 'id' => 999999, 'name' => 'ADMINISTRATORS');
239 $rooar = method_exists($x, 'toRooArray');
241 while ($x->fetch()) {
243 $add = $rooar ? $x->toRooArray($_REQUEST) : $x->toArray();
245 $ret[] = !$_columns ? $add : array_intersect_key($add, array_flip($_columns));
248 if (method_exists($queryObj ,'postListExtra')) {
249 $extra = $queryObj->postListExtra($_REQUEST, $this);
251 // filter results, and add any data that is needed...
252 if (method_exists($x,'postListFilter')) {
253 $ret = $x->postListFilter($ret, $this->authUser, $_REQUEST);
256 if (!empty($_REQUEST['csvCols']) && !empty($_REQUEST['csvTitles']) ) {
257 header('Content-type: text/csv');
259 header('Content-Disposition: attachment; filename="list-export-'.date('Y-m-d') . '.csv"');
260 //header('Content-type: text/plain');
261 $fh = fopen('php://output', 'w');
262 fputcsv($fh, $_REQUEST['csvTitles']);
265 foreach($ret as $x) {
266 //echo "<PRE>"; print_r(array($_REQUEST['csvCols'], $x->toArray())); exit;
268 foreach($_REQUEST['csvCols'] as $k) {
269 $line[] = isset($x[$k]) ? $x[$k] : '';
280 //if ($x->tableName() == 'Documents_Tracking') {
281 // $ret = $this->replaceSubject(&$ret, 'doc_id_subject');
286 if (!empty($_REQUEST['_requestMeta']) && count($ret)) {
287 $meta = $this->meta($x, $ret);
289 $extra['metaData'] = $meta;
293 // echo "<PRE>"; print_r($ret);
294 $this->jdata($ret,$total, $extra );
301 * apply REQUEST[sort] and [dir]
302 * sort may be an array of columsn..
304 * @arg DB_DataObject $x
307 function applySort($x, $sort = '', $dir ='')
310 // Db_DataObject::debugLevel(1);
311 $sort = empty($_REQUEST['sort']) ? $sort : $_REQUEST['sort'];
312 $dir = empty($_REQUEST['dir']) ? $dir : $_REQUEST['dir'];
313 $dir = $dir == 'ASC' ? 'ASC' : 'DESC';
315 $ms = empty($_REQUEST['_multisort']) ? false : $_REQUEST['_multisort'];
317 if (method_exists($x, 'applySort')) {
318 $sorted = $x->applySort(
322 array_keys($this->cols),
323 $ms ? json_decode($ms) : false
327 return $this->multiSort($x);
330 if ($sorted === false) {
333 $sort_ar = explode(',', $sort);
336 foreach($sort_ar as $sort) {
338 if (strlen($sort) && isset($cols[$sort]) ) {
339 $sort_str[] = $x->tableName() .'.'.$sort . ' ' . $dir ;
341 } else if (in_array($sort, array_keys($this->cols))) {
342 $sort_str[] = $sort . ' ' . $dir ;
347 $x->orderBy(implode(', ', $sort_str ));
352 function multiSort($x)
354 //DB_DataObject::debugLevel(1);
355 $ms = json_decode($_REQUEST['_multisort']);
360 foreach($ms->order as $col) {
361 if (!isset($ms->sort->{$col})) {
362 continue; // no direction..
364 $ms->sort->{$col} = $ms->sort->{$col} == 'ASC' ? 'ASC' : 'DESC';
366 if (strlen($col) && isset($cols[$col]) ) {
367 $sort_str[] = $x->tableName() .'.'.$col . ' ' . $ms->sort->{$col};
369 } else if (in_array($col, array_keys($this->cols))) {
370 $sort_str[] = $col. ' ' . $ms->sort->{$col};
375 $x->orderBy(implode(', ', $sort_str ));
385 * POST method Roo/TABLENAME.php
386 * -- updates the data..
389 * _debug - forces debugging on.
390 * _get - forces a get request
391 * _ids - multiple update of records.
392 * {colid} - forces fetching
395 function post($tab) // update / insert (?? dleete??)
398 PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($this, 'onPearError'));
401 //DB_DataObject::debugLevel(1);
402 if (!empty($_REQUEST['_debug'])) {
403 DB_DataObject::debugLevel(1);
406 if (!empty($_REQUEST['_get'])) {
407 return $this->get($tab);
410 $_columns = !empty($_REQUEST['_columns']) ? explode(',', $_REQUEST['_columns']) : false;
412 $tab = str_replace('/', '',$tab); // basic protection??
413 $x = DB_DataObject::factory($tab);
414 if (!is_a($x, 'DB_DataObject')) {
415 $this->jerr('invalid url');
417 // find the key and use that to get the thing..
420 $this->jerr('no key');
423 $this->key = $keys[0];
425 // delete should be here...
426 if (isset($_REQUEST['_delete'])) {
427 // do we really delete stuff!?!?!?
428 return $this->delete($x,$_REQUEST);
434 // not sure if this is a good idea here...
436 if (!empty($_REQUEST['_ids'])) {
437 $ids = explode(',',$_REQUEST['_ids']);
438 $x->whereAddIn($this->key, $ids, 'int');
439 $ar = $x->fetchAll();
441 $this->update($x, $_REQUEST);
445 $this->jok("UPDATED");
450 if (!empty($_REQUEST[$this->key])) {
452 if (!$x->get($this->key, $_REQUEST[$this->key])) {
453 $this->jerr("Invalid request");
455 $this->jok($this->update($x, $_REQUEST));
459 $this->jerr("No data recieved for inserting");
462 $this->jok($this->insert($x, $_REQUEST));
469 function insert($x, $req)
473 if (method_exists($x, 'checkPerm') && !$x->checkPerm('A', $this->authUser, $req)) {
474 $this->jerr("PERMISSION DENIED");
477 $_columns = !empty($req['_columns']) ? explode(',', $req['_columns']) : false;
479 if (method_exists($x, 'setFromRoo')) {
480 $res = $x->setFromRoo($req, $this);
481 if (is_string($res)) {
491 if (isset($cols['created'])) {
492 $x->created = date('Y-m-d H:i:s');
494 if (isset($cols['created_dt'])) {
495 $x->created_dt = date('Y-m-d H:i:s');
497 if (isset($cols['created_by'])) {
498 $x->created_by = $this->authUser->id;
502 if (isset($cols['modified'])) {
503 $x->modified = date('Y-m-d H:i:s');
505 if (isset($cols['modified_dt'])) {
506 $x->modified_dt = date('Y-m-d H:i:s');
508 if (isset($cols['modified_by'])) {
509 $x->modified_by = $this->authUser->id;
512 if (isset($cols['updated'])) {
513 $x->updated = date('Y-m-d H:i:s');
515 if (isset($cols['updated_dt'])) {
516 $x->updated_dt = date('Y-m-d H:i:s');
518 if (isset($cols['updated_by'])) {
519 $x->updated_by = $this->authUser->id;
523 if (method_exists($x, 'beforeInsert')) {
524 $x->beforeInsert($_REQUEST, $this);
529 if ($res === false) {
530 $this->jerr($x->_lastError->toString());
532 if (method_exists($x, 'onInsert')) {
533 $x->onInsert($_REQUEST, $this);
535 $ev = $this->addEvent("ADD", $x);
540 // note setFrom might handle this before hand...!??!
541 if (!empty($_FILES) && method_exists($x, 'onUpload')) {
545 $r = DB_DataObject::factory($x->tableName());
546 // let's assume it has a key!!!
548 $r->{$this->key} = $x->{$this->key};
549 $this->loadMap($r, $_columns);
553 $rooar = method_exists($r, 'toRooArray');
554 //print_r(var_dump($rooar)); exit;
555 return $rooar ? $r->toRooArray($_REQUEST) : $r->toArray();
559 function update($x, $req)
561 if (method_exists($x, 'checkPerm') && !$x->checkPerm('E', $this->authUser, $_REQUEST)) {
562 $this->jerr("PERMISSION DENIED");
566 // only done if we recieve a lock_id.
567 // we are very trusing here.. that someone has not messed around with locks..
568 // the object might want to check in their checkPerm - if locking is essential..
569 $lock_warning = false;
570 $lock = DB_DataObjecT::factory('Core_locking');
571 if (is_a($lock,'DB_DataObject')) {
573 $lock->on_id = $x->{$this->key};
574 $lock->on_table= $x->tableName();
575 if (!empty($_REQUEST['_lock_id'])) {
576 $lock->whereAdd('id != ' . ((int)$_REQUEST['_lock_id']));
578 $lock->whereAdd('person_id !=' . $this->authUser->id);
582 if ($lock->find(true)) {
583 // it's locked by someone else..
584 $p = $lock->person();
585 $lock_warning = "Record was locked by " . $p->name . " at " .$lock->created.
586 " - Your changes have been saved - you may like to warn them if " .
587 " they are editing now";
589 // check the users lock.. - no point.. ??? - if there are no other locks and it's not the users, then they can
590 // edit it anyways...
599 $_columns = !empty($req['_columns']) ? explode(',', $req['_columns']) : false;
604 // this lot is generic.. needs moving
605 if (method_exists($x, 'setFromRoo')) {
606 $res = $x->setFromRoo($req, $this);
607 if (is_string($res)) {
613 $ev = $this->addEvent("EDIT", $x);
614 $ev->audit($x, $old);
620 if (isset($cols['modified'])) {
621 $x->modified = date('Y-m-d H:i:s');
623 if (isset($cols['modified_dt'])) {
624 $x->modified_dt = date('Y-m-d H:i:s');
626 if (isset($cols['modified_by'])) {
627 $x->modified_by = $this->authUser->id;
630 if (isset($cols['updated'])) {
631 $x->updated = date('Y-m-d H:i:s');
633 if (isset($cols['updated_dt'])) {
634 $x->updated_dt = date('Y-m-d H:i:s');
636 if (isset($cols['updated_by'])) {
637 $x->updated_by = $this->authUser->id;
640 if (method_exists($x, 'beforeUpdate')) {
641 $x->beforeUpdate($old, $req, $this);
644 //DB_DataObject::DebugLevel(1);
645 $res = $x->update($old);
646 if ($res === false) {
647 $this->jerr($x->_lastError->toString());
650 if (method_exists($x, 'onUpdate')) {
651 $x->onUpdate($old, $req, $this);
656 $this->jerr($lock_warning);
660 $r = DB_DataObject::factory($x->tableName());
661 // let's assume it has a key!!!
662 $r->{$this->key}= $x->{$this->key};
663 $this->loadMap($r, $_columns);
666 $rooar = method_exists($r, 'toRooArray');
667 //print_r(var_dump($rooar)); exit;
668 return $rooar ? $r->toRooArray($_REQUEST) : $r->toArray();
671 * Delete a number of records.
672 * calls $delete_obj->beforeDelete($array_of_dependant_dataobjects)
676 function delete($x, $req)
678 // do we really delete stuff!?!?!?
679 if (empty($req['_delete'])) {
680 $this->jerr("Delete Requested with no value");
682 // build a list of tables to queriy for dependant data..
687 $all_links = $GLOBALS['_DB_DATAOBJECT']['LINKS'][$x->_database];
688 foreach($all_links as $tbl => $links) {
689 foreach($links as $col => $totbl_col) {
690 $to = explode(':', $totbl_col);
691 if ($to[0] != $x->tableName()) {
695 $affects[$tbl .'.' . $col] = true;
700 // echo '<PRE>';print_r($affects);exit;
701 //DB_Dataobject::debugLevel(1);
704 $clean = create_function('$v', 'return (int)$v;');
706 $bits = array_map($clean, explode(',', $req['_delete']));
708 // print_r($bits);exit;
710 // let's assume it has a key!!!
713 $x->whereAdd($this->key .' IN ('. implode(',', $bits) .')');
715 $this->jerr("Nothing found to delete");
718 while ($x->fetch()) {
724 if (method_exists($x, 'checkPerm') && !$x->checkPerm('D', $this->authUser)) {
725 $this->jerr("PERMISSION DENIED");
729 foreach($affects as $k=> $true) {
730 $ka = explode('.', $k);
732 $chk = DB_DataObject::factory($ka[0]);
733 if (!is_a($chk,'DB_DataObject')) {
734 $this->jerr('Unable to load referenced table, check the links config: ' .$ka[0]);
736 $chk->{$ka[1]} = $xx->{$this->key};
738 if (count($chk->keys())) {
739 $matches = $chk->count();
741 //DB_DataObject::DebugLevel(1);
742 $matches = $chk->count($ka[1]);
746 $match_ar[] = clone($chk);
751 $has_beforeDelete = method_exists($xx, 'beforeDelete');
752 // before delte = allows us to trash dependancies if needed..
755 if ( method_exists($xx, 'beforeDelete') ) {
756 if ($xx->beforeDelete($match_ar, $this) === false) {
757 $errs[] = "Delete failed ({$xx->id})\n".
758 (isset($xx->err) ? $xx->err : '');
764 foreach($affects as $k=> $true) {
765 $ka = explode('.', $k);
766 $chk = DB_DataObject::factory($ka[0]);
767 if (!is_a($chk,'DB_DataObject')) {
768 $this->jerr('Unable to load referenced table, check the links config: ' .$ka[0]);
770 $chk->{$ka[1]} = $xx->$pk;
771 $matches = $chk->count();
772 $match_total += $matches;
774 $match_ar[] = clone($chk);
784 if (!empty($match_ar)) {
787 $o = $chk->fetchAll();
789 $desc = $chk->tableName(). '.' . $key .'='.$xx->$key ;
790 if (method_exists($chk, 'toEventString')) {
791 $desc .= ' : ' . $o[0]->toEventString();
794 $this->jerr("Delete Dependant records ($match_total found), " .
795 "first is ( $desc )");
802 $this->addEvent("DELETE", $x);
807 $this->jerr(implode("\n<BR>", $errs));
809 $this->jok("Deleted");
817 function loadMap($do, $filter=false, $distinct = false)
819 //DB_DataObject::debugLevel(1);
821 $this->countWhat = false;
827 $mods = explode(',',$this->appModules);
829 $ff = HTML_FlexyFramework::get();
836 $tabdef = $do->table();
837 if (isset($tabdef['passwd'])) {
838 // prevent exposure of passwords..
839 unset($tabdef['passwd']);
842 $xx = array_keys($tabdef);
843 $do->selectAdd(); // we need thsi as normally it's only cleared by an empty selectAs call.
845 $selectAs = array(array( $xx , '%s', false));
847 $has_distinct = false;
848 if ($filter || $distinct) {
850 //echo '<PRE>' ;print_r($filter);exit;
852 if ($distinct && $distinct == $c) {
853 $has_distinct = 'DISTINCT( ' . $do->tableName() .'.'. $c .') as ' . $c;
854 $this->countWhat = 'DISTINCT ' . $do->tableName() .'.'. $c .'';
857 if (!$filter || in_array($c, $filter)) {
863 $selectAs = empty($cols) ? array() : array(array( $cols , '%s', false)) ;
869 $this->cols = array();
870 $this->colsJoinName =array();
872 $this->cols[$k] = $do->tableName(). '.' . $k;
880 foreach($map as $ocl=>$info) {
882 list($tab,$col) = explode(':', $info);
883 // what about multiple joins on the same table!!!
884 $xx = DB_DataObject::factory($tab);
885 if (!is_a($xx, 'DB_DataObject')) {
888 // this is borked ... for multiple jions..
889 $do->joinAdd($xx, 'LEFT', 'join_'.$ocl.'_'. $col, $ocl);
890 $tabdef = $xx->table();
891 $table = $xx->tableName();
892 if (isset($tabdef['passwd'])) {
894 unset($tabdef['passwd']);
897 $xx = array_keys($tabdef);
900 if ($filter || $distinct) {
903 $tn = sprintf($ocl.'_%s', $c);
904 // echo '<PRE>'; var_dump($tn);
905 if ($distinct && $tn == $distinct) {
906 $has_distinct = 'DISTINCT( ' . 'join_'.$ocl.'_'.$col.'.'.$k .') as ' . $tn ;
907 $this->countWhat = 'DISTINCT join_'.$ocl.'_'.$col.'.'.$k;
912 if (!$filter || in_array($tn, $filter)) {
917 $selectAs[] = array($cols, $ocl.'_%s', 'join_'.$ocl.'_'. $col);
922 $selectAs[] = array($xx, $ocl.'_%s', 'join_'.$ocl.'_'. $col);
928 $this->cols[sprintf($ocl.'_%s', $k)] = $tab.'.'.$k;
929 $this->colsJname[sprintf($ocl.'_%s', $k)] = 'join_'.$ocl.'_'.$col.'.'.$k;
936 $do->selectAdd($has_distinct);
939 // we do select as after everything else as we need to plop distinct at the beginning??
941 // echo '<PRE>';print_r($this->colsJname);exit;
942 foreach($selectAs as $ar) {
943 $do->selectAs($ar[0], $ar[1], $ar[2]);
949 * generate the meta data neede by queries.
952 function meta($x, $data)
954 // this is not going to work on queries where the data does not match the database def..
955 // for unknown columns we send them as stirngs..
957 $cols = array_keys($data[0]);
962 //echo '<PRE>';print_r($this->cols); exit;
963 $options = &PEAR::getStaticProperty('DB_DataObject','options');
964 $reader = $options["ini_{$x->_database}"] .'.reader';
965 if (!file_exists( $reader )) {
969 $rdata = unserialize(file_get_contents($reader));
971 // echo '<PRE>';print_r($rdata);exit;
974 foreach($cols as $c ) {
975 if (!isset($this->cols[$c]) || !isset($rdata[$this->cols[$c]]) || !is_array($rdata[$this->cols[$c]])) {
979 $add = $rdata[$this->cols[$c]];
984 'totalProperty' => 'total',
985 'successProperty' => 'success',
994 function setFilters($x, $q)
996 // if a column is type int, and we get ',' -> the it should be come an inc clause..
997 // DB_DataObject::debugLevel(1);
998 if (method_exists($x, 'applyFilters')) {
999 // DB_DataObject::debugLevel(1);
1000 $x->applyFilters($q, $this->authUser, $this);
1002 $q_filtered = array();
1004 foreach($q as $key=>$val) {
1006 // value is an array..
1007 if (is_array($val) ) {
1011 if ($key[0] == '!') {
1013 $key = substr($key,1);
1016 if (!in_array( $key, array_keys($this->cols))) {
1020 // support a[0] a[1] ..... => whereAddIn(
1023 foreach($val as $k=>$v) {
1024 if (!is_numeric($k)) {
1028 // FIXME: note this is not typesafe for anything other than mysql..
1030 if (!is_numeric($v) || !is_long($v)) {
1039 $x->whereAddIn($pref . (
1040 isset($this->colsJname[$key]) ?
1041 $this->colsJname[$key] :
1042 ($x->tableName(). '.'.$key)),
1043 $ar, $quote ? 'string' : 'int');
1051 if ($key[0] == '!' && in_array(substr($key, 1), array_keys($this->cols))) {
1053 $key = substr($key, 1) ;
1056 isset($this->colsJname[$key]) ?
1057 $this->colsJname[$key] :
1058 $x->tableName(). '.'.$key ) . ' != ' .
1059 (is_numeric($val) ? $val : "'". $x->escape($val) . "'")
1069 // Events and remarks -- fixme - move to events/remarsk...
1070 case 'on_id': // where TF is this used...
1071 if (!empty($q['query']['original'])) {
1072 // DB_DataObject::debugLevel(1);
1073 $o = (int) $q['query']['original'];
1075 $x->whereAdd("(on_id = $oid OR
1076 on_id IN ( SELECT distinct(id) FROM Documents WHERE original = $o )
1086 $q_filtered[$key] = $val;
1089 // subjoined columns = check the values.
1090 // note this is not typesafe for anything other than mysql..
1092 if (isset($this->colsJname[$key])) {
1094 if (!is_numeric($val) || !is_long($val)) {
1097 $x->whereAdd( "{$this->colsJname[$key]} = " . ($quote ? "'". $x->escape($val) ."'" : $val));
1106 $x->setFrom($q_filtered);
1111 // nice generic -- let's get rid of it.. where is it used!!!!
1113 // Person / Group / most of my queries noww...
1114 if (!empty($q['query']['name'])) {
1115 $x->whereAdd($x->tableName().".name LIKE '". $x->escape($q['query']['name']) . "%'");
1118 // - projectdirectory staff list - persn queuy
1123 function onPearError($err)
1126 $out = $err->toString();
1129 //print_R($bt); exit;
1131 foreach($err->backtrace as $b) {
1132 $ret[] = $b['file'] . '(' . $b['line'] . ')@' . @$bt['class'] . '::' . @$bt['function'];
1134 //convert the huge backtrace into something that is readable..
1135 $out .= "\n" . implode("<BR>", $ret);