RooTrait.php
[Pman.Core] / RooTrait.php
index c859cdf..1bb4ed6 100644 (file)
@@ -135,97 +135,50 @@ trait Pman_Core_RooTrait {
         
     }
     
-    function jok($str)
-    {
-        if ($this->transObj ) {
-            $this->transObj->query( connection_aborted() ? 'ROLLBACK' :  'COMMIT');
-        }
-        
-        return parent::jok($str);
-    }
     
     
-    function jerr($str, $errors=array(), $content_type = false)
+    function addEvent($act, $obj = false, $remarks = '') 
     {
-        if ($this->transObj) {
-            $this->transObj->query('ROLLBACK');
-        }
         
-        return $this->jerror('ERROR', $str,$errors,$content_type);
-    }
-    
-    function jerror($type, $str, $errors=array(), $content_type = false) // standard error reporting..
-    {
-        if ($type !== false) {
-            $this->addEvent($type, false, $str);
+        if (!empty(HTML_FlexyFramework::get()->Pman['disable_events'])) {
+            return;
         }
+        
+        $au = $this->getAuthUser();
+       
+        $e = DB_DataObject::factory('Events');
+        $e->init($act,$obj,$remarks); 
          
-        $cli = HTML_FlexyFramework::get()->cli;
-        if ($cli) {
-            echo "ERROR: " .$str . "\n";
-            exit;
-        }
+        $e->event_when = date('Y-m-d H:i:s');
         
+        $eid = $e->insert();
         
-        if ($content_type == 'text/plain') {
-            header('Content-Disposition: attachment; filename="error.txt"');
-            header('Content-type: '. $content_type);
-            echo "ERROR: " .$str . "\n";
-            exit;
-        } 
+        // fixme - this should be in onInsert..
+        $wa = DB_DataObject::factory('core_watch');
+        if (method_exists($wa,'notifyEvent')) {
+            $wa->notifyEvent($e); // trigger any actions..
+        }
         
-        require_once 'Services/JSON.php';
-        $json = new Services_JSON();
         
-        $retHTML = isset($_SERVER['CONTENT_TYPE']) && 
-                preg_match('#multipart/form-data#i', $_SERVER['CONTENT_TYPE']);
+        $e->onInsert(isset($_REQUEST) ? $_REQUEST : array() , $this);
         
-        if ($retHTML){
-            if (isset($_REQUEST['returnHTML']) && $_REQUEST['returnHTML'] == 'NO') {
-                $retHTML = false;
-            }
-        } else {
-            $retHTML = isset($_REQUEST['returnHTML']) && $_REQUEST['returnHTML'] !='NO';
-        }
+        return $e;
         
-        if ($retHTML) {
-            header('Content-type: text/html');
-            echo "<HTML><HEAD></HEAD><BODY>";
-            echo  $json->encodeUnsafe(array(
-                    'success'=> false, 
-                    'errorMsg' => $str,
-                    'message' => $str, // compate with exeption / loadexception.
-
-                    'errors' => $errors ? $errors : true, // used by forms to flag errors.
-                    'authFailure' => !empty($errors['authFailure']),
-                ));
-            echo "</BODY></HTML>";
-            exit;
+    }
+    
+    function getAuthUser()
+    {
+        if (!empty($this->authUser)) {
+            return $this->authUser;
         }
+        $ff = HTML_FlexyFramework::get();
+        $tbl = empty($ff->Pman['authTable']) ? 'Person' : $ff->Pman['authTable'];
         
-        if (isset($_REQUEST['_debug'])) {
-            echo '<PRE>'.htmlspecialchars(print_r(array(
-                'success'=> false, 
-                'data'=> array(), 
-                'errorMsg' => $str,
-                'message' => $str, // compate with exeption / loadexception.
-                'errors' => $errors ? $errors : true, // used by forms to flag errors.
-                'authFailure' => !empty($errors['authFailure']),
-            ),true));
-            exit;
-                
+        $u = DB_DataObject::factory( $tbl );
+        if (!$u->isAuth()) {
+            return false;
         }
-        
-        echo $json->encode(array(
-            'success'=> false, 
-            'data'=> array(), 
-            'errorMsg' => $str,
-            'message' => $str, // compate with exeption / loadexception.
-            'errors' => $errors ? $errors : true, // used by forms to flag errors.
-            'authFailure' => !empty($errors['authFailure']),
-        ));
-        
-        exit;
-        
+        $this->authUser =$u->getAuthUser();
+        return $this->authUser ;
     }
 }