RooTrait.php
[Pman.Core] / RooTrait.php
1 <?php
2
3 trait Pman_Core_RooTrait {
4     
5     var $validTables = false; 
6     
7     var $key;
8     
9     var $transObj = false;
10     
11     var $debugEnabled = true;
12     
13     function init() 
14     {
15         if (isset($this->_hasInit)) {
16             return;
17         }
18         
19         $this->_hasInit = true;
20         
21         $boot = HTML_FlexyFramework::get();
22         
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']; 
31         
32         if (!empty($ff->Pman['local_autoauth']) && 
33             ($_SERVER['SERVER_ADDR'] == '127.0.0.1') &&
34             ($_SERVER['REMOTE_ADDR'] == '127.0.0.1') 
35         ) {
36             $this->isDev = true;
37         }
38         
39     }
40     
41     function checkDebug($req = false)
42     {
43         $req =  $req === false  ? $_REQUEST : $req;
44         if (isset($req['_debug']) 
45                 && 
46                 $this->authUser
47                 &&
48                 (
49                     (
50                         method_exists($this->authUser,'canDebug')
51                         &&
52                         $this->authUser->canDebug()
53                     )
54                 ||
55                     (  
56                     
57                         method_exists($this->authUser,'groups') 
58                         &&
59                         is_a($this->authUser, 'Pman_Core_DataObjects_Person')
60                         &&
61                         in_array('Administrators', $this->authUser->groups('name'))
62                     )
63                 )
64                 
65             ){
66             DB_DAtaObject::debuglevel((int)$req['_debug']);
67         }
68         
69     }
70     
71     function dataObject($tab)
72     {
73         if (is_array($this->validTables) &&  !in_array($tab, $this->validTables)) {
74             $this->jerr("Invalid url - not listed in validTables");
75         }
76         
77         $tab = str_replace('/', '',$tab); // basic protection??
78         
79         $x = DB_DataObject::factory($tab);
80         
81         if (!is_a($x, 'DB_DataObject')) {
82             $this->jerr('invalid url - no dataobject');
83         }
84     
85         return $x;
86     }
87     
88     
89     /*
90      * From Pman.php
91      */
92     
93     static $permitError = false;
94     
95     function onPearError($err)
96     {
97         static $reported = false;
98         if ($reported) {
99             return;
100         }
101         
102         if (Pman::$permitError) {
103              
104             return;
105             
106         }
107         
108         $reported = true;
109         $out = $err->toString();
110         
111         $ret = array();
112         $n = 0;
113         
114         foreach($err->backtrace as $b) {
115             $ret[] = @$b['file'] . '(' . @$b['line'] . ')@' .   @$b['class'] . '::' . @$b['function'];
116             if ($n > 20) {
117                 break;
118             }
119             $n++;
120         }
121         //convert the huge backtrace into something that is readable..
122         $out .= "\n" . implode("\n",  $ret);
123      
124         print_R($out);exit;
125         
126         $this->jerr($out);
127         
128     }
129     
130     function addEvent($act, $obj = false, $remarks = '') 
131     {
132         if (!empty(HTML_FlexyFramework::get()->Pman['disable_events'])) {
133             return;
134         }
135         
136         $au = $this->getAuthUser();
137        
138         $e = DB_DataObject::factory('Events');
139         $e->init($act,$obj,$remarks); 
140          
141         $e->event_when = date('Y-m-d H:i:s');
142         
143         $eid = $e->insert();
144         
145         // fixme - this should be in onInsert..
146         $wa = DB_DataObject::factory('core_watch');
147         if (method_exists($wa,'notifyEvent')) {
148             $wa->notifyEvent($e); // trigger any actions..
149         }
150         
151         $e->onInsert(isset($_REQUEST) ? $_REQUEST : array() , $this);
152         
153         return $e;
154         
155     }
156     
157     function getAuthUser()
158     {
159         die('Get auth user is not implement.');
160     }
161 }