RooTrait.php
[Pman.Core] / RooTrait.php
1 <?php
2
3 trait Pman_Core_RooTrait {
4     
5     function init() 
6     {
7         if (isset($this->_hasInit)) {
8             return;
9         }
10         
11         $this->_hasInit = true;
12         
13         $boot = HTML_FlexyFramework::get();
14         
15         $this->appName= $boot->appName;
16         $this->appNameShort= $boot->appNameShort;
17         $this->appModules= $boot->enable;
18         $this->isDev = empty($boot->Pman['isDev']) ? false : $boot->Pman['isDev'];
19         $this->appDisable = $boot->disable;
20         $this->appDisabled = explode(',', $boot->disable);
21         $this->version = $boot->version; 
22         $this->uiConfig = empty($boot->Pman['uiConfig']) ? false : $boot->Pman['uiConfig']; 
23         
24         if (!empty($ff->Pman['local_autoauth']) && 
25             ($_SERVER['SERVER_ADDR'] == '127.0.0.1') &&
26             ($_SERVER['REMOTE_ADDR'] == '127.0.0.1') 
27         ) {
28             $this->isDev = true;
29         }
30         
31     }
32     
33     function checkDebug($req = false)
34     {
35         $req =  $req === false  ? $_REQUEST : $req;
36         if (isset($req['_debug']) 
37                 && 
38                 $this->authUser
39                 &&
40                 (
41                     (
42                         method_exists($this->authUser,'canDebug')
43                         &&
44                         $this->authUser->canDebug()
45                     )
46                 ||
47                     (  
48                     
49                         method_exists($this->authUser,'groups') 
50                         &&
51                         is_a($this->authUser, 'Pman_Core_DataObjects_Person')
52                         &&
53                         in_array('Administrators', $this->authUser->groups('name'))
54                     )
55                 )
56                 
57             ){
58             DB_DAtaObject::debuglevel((int)$req['_debug']);
59         }
60         
61     }
62     
63     function checkDebugPost()
64     {
65         return (!empty($_GET['_post']) || !empty($_GET['_debug_post'])) && 
66                     $this->authUser && 
67                     method_exists($this->authUser,'groups') &&
68                     in_array('Administrators', $this->authUser->groups('name')); 
69         
70     }
71     
72     function dataObject($tab)
73     {
74         if (is_array($this->validTables) &&  !in_array($tab, $this->validTables)) {
75             $this->jerr("Invalid url - not listed in validTables");
76         }
77         
78         $tab = str_replace('/', '',$tab); // basic protection??
79         
80         $x = DB_DataObject::factory($tab);
81         
82         if (!is_a($x, 'DB_DataObject')) {
83             $this->jerr('invalid url - no dataobject');
84         }
85     
86         return $x;
87         
88     }
89     
90     /*
91      * From Pman.php
92      */
93     
94     static $permitError = false;
95     
96     function onPearError($err)
97     {
98         static $reported = false;
99         if ($reported) {
100             return;
101         }
102         
103         if (Pman::$permitError) {
104              
105             return;
106             
107         }
108         
109         $reported = true;
110         $out = $err->toString();
111         
112         $ret = array();
113         $n = 0;
114         
115         foreach($err->backtrace as $b) {
116             $ret[] = @$b['file'] . '(' . @$b['line'] . ')@' .   @$b['class'] . '::' . @$b['function'];
117             if ($n > 20) {
118                 break;
119             }
120             $n++;
121         }
122         //convert the huge backtrace into something that is readable..
123         $out .= "\n" . implode("\n",  $ret);
124      
125         print_R($out);exit;
126         
127         $this->jerr($out);
128         
129     }
130 }