3 trait Pman_Core_RooTrait {
5 var $validTables = false;
11 var $debugEnabled = true;
15 if (isset($this->_hasInit)) {
19 $this->_hasInit = true;
21 $boot = HTML_FlexyFramework::get();
23 $this->appName= $boot->appName;
24 $this->appNameShort= $boot->appNameShort;
25 $this->appModules= $boot->enable;
26 $this->isDev = empty($boot->Pman['isDev']) ? false : $boot->Pman['isDev'];
27 $this->appDisable = $boot->disable;
28 $this->appDisabled = explode(',', $boot->disable);
29 $this->version = $boot->version;
30 $this->uiConfig = empty($boot->Pman['uiConfig']) ? false : $boot->Pman['uiConfig'];
32 if (!empty($ff->Pman['local_autoauth']) &&
33 ($_SERVER['SERVER_ADDR'] == '127.0.0.1') &&
34 ($_SERVER['REMOTE_ADDR'] == '127.0.0.1')
41 function checkDebug($req = false)
43 $req = $req === false ? $_REQUEST : $req;
44 if (isset($req['_debug'])
50 method_exists($this->authUser,'canDebug')
52 $this->authUser->canDebug()
57 method_exists($this->authUser,'groups')
59 is_a($this->authUser, 'Pman_Core_DataObjects_Person')
61 in_array('Administrators', $this->authUser->groups('name'))
66 DB_DAtaObject::debuglevel((int)$req['_debug']);
71 function checkDebugPost()
73 return (!empty($_GET['_post']) || !empty($_GET['_debug_post'])) &&
75 method_exists($this->authUser,'groups') &&
76 in_array('Administrators', $this->authUser->groups('name'));
80 function dataObject($tab)
82 if (is_array($this->validTables) && !in_array($tab, $this->validTables)) {
83 $this->jerr("Invalid url - not listed in validTables");
86 $tab = str_replace('/', '',$tab); // basic protection??
88 $x = DB_DataObject::factory($tab);
90 if (!is_a($x, 'DB_DataObject')) {
91 $this->jerr('invalid url - no dataobject');
97 function selectSingle($x, $id, $req=false)
99 $_columns = !empty($req['_columns']) ? explode(',', $req['_columns']) : false;
101 if (!is_array($id) && empty($id)) {
103 if (method_exists($x, 'toRooSingleArray')) {
104 $this->jok($x->toRooSingleArray($this->getAuthUser(), $req));
107 if (method_exists($x, 'toRooArray')) {
108 $this->jok($x->toRooArray($req));
111 $this->jok($x->toArray());
115 $this->loadMap($x, array(
116 'columns' => $_columns,
119 if ($req !== false) {
120 $this->setFilters($x, $req);
123 // DB_DataObject::DebugLevel(1);
126 $x->setFrom($req['lookup'] );
128 if (!$x->find(true)) {
129 if (!empty($id['_id'])) {
131 $this->jok($x->toArray());
136 } else if (!$x->get($id)) {
137 $this->jerr("selectSingle: no such record ($id)");
140 // ignore perms if comming from update/insert - as it's already done...
141 if ($req !== false && !$this->checkPerm($x,'S')) {
142 $this->jerr("PERMISSION DENIED - si");
144 // different symantics on all these calls??
145 if (method_exists($x, 'toRooSingleArray')) {
146 $this->jok($x->toRooSingleArray($this->authUser, $req));
148 if (method_exists($x, 'toRooArray')) {
149 $this->jok($x->toRooArray($req));
152 $this->jok($x->toArray());
161 static $permitError = false;
163 function onPearError($err)
165 static $reported = false;
170 if (Pman::$permitError) {
177 $out = $err->toString();
182 foreach($err->backtrace as $b) {
183 $ret[] = @$b['file'] . '(' . @$b['line'] . ')@' . @$b['class'] . '::' . @$b['function'];
189 //convert the huge backtrace into something that is readable..
190 $out .= "\n" . implode("\n", $ret);
198 function addEvent($act, $obj = false, $remarks = '')
200 if (!empty(HTML_FlexyFramework::get()->Pman['disable_events'])) {
204 $au = $this->getAuthUser();
206 $e = DB_DataObject::factory('Events');
207 $e->init($act,$obj,$remarks);
209 $e->event_when = date('Y-m-d H:i:s');
213 // fixme - this should be in onInsert..
214 $wa = DB_DataObject::factory('core_watch');
215 if (method_exists($wa,'notifyEvent')) {
216 $wa->notifyEvent($e); // trigger any actions..
219 $e->onInsert(isset($_REQUEST) ? $_REQUEST : array() , $this);
225 function getAuthUser()
227 die('Get auth user is not implement.');