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');
101 static $permitError = false;
103 function onPearError($err)
105 static $reported = false;
110 if (Pman::$permitError) {
117 $out = $err->toString();
122 foreach($err->backtrace as $b) {
123 $ret[] = @$b['file'] . '(' . @$b['line'] . ')@' . @$b['class'] . '::' . @$b['function'];
129 //convert the huge backtrace into something that is readable..
130 $out .= "\n" . implode("\n", $ret);
140 if ($this->transObj ) {
141 $this->transObj->query( connection_aborted() ? 'ROLLBACK' : 'COMMIT');
144 return parent::jok($str);
148 function jerr($str, $errors=array(), $content_type = false)
150 if ($this->transObj) {
151 $this->transObj->query('ROLLBACK');
154 return $this->jerror('ERROR', $str,$errors,$content_type);
157 function jerror($type, $str, $errors=array(), $content_type = false) // standard error reporting..
159 if ($type !== false) {
160 $this->addEvent($type, false, $str);
163 $cli = HTML_FlexyFramework::get()->cli;
165 echo "ERROR: " .$str . "\n";
170 if ($content_type == 'text/plain') {
171 header('Content-Disposition: attachment; filename="error.txt"');
172 header('Content-type: '. $content_type);
173 echo "ERROR: " .$str . "\n";
177 require_once 'Services/JSON.php';
178 $json = new Services_JSON();
180 $retHTML = isset($_SERVER['CONTENT_TYPE']) &&
181 preg_match('#multipart/form-data#i', $_SERVER['CONTENT_TYPE']);
184 if (isset($_REQUEST['returnHTML']) && $_REQUEST['returnHTML'] == 'NO') {
188 $retHTML = isset($_REQUEST['returnHTML']) && $_REQUEST['returnHTML'] !='NO';
192 header('Content-type: text/html');
193 echo "<HTML><HEAD></HEAD><BODY>";
194 echo $json->encodeUnsafe(array(
197 'message' => $str, // compate with exeption / loadexception.
199 'errors' => $errors ? $errors : true, // used by forms to flag errors.
200 'authFailure' => !empty($errors['authFailure']),
202 echo "</BODY></HTML>";
206 if (isset($_REQUEST['_debug'])) {
207 echo '<PRE>'.htmlspecialchars(print_r(array(
211 'message' => $str, // compate with exeption / loadexception.
212 'errors' => $errors ? $errors : true, // used by forms to flag errors.
213 'authFailure' => !empty($errors['authFailure']),
219 echo $json->encode(array(
223 'message' => $str, // compate with exeption / loadexception.
224 'errors' => $errors ? $errors : true, // used by forms to flag errors.
225 'authFailure' => !empty($errors['authFailure']),