Pman/Images.php
[Pman.Base] / Pman.php
index d6bf088..65a7348 100644 (file)
--- a/Pman.php
+++ b/Pman.php
@@ -52,35 +52,26 @@ class Pman extends HTML_FlexyFramework_Page
     {
         if (isset($this->_hasInit)) {
             return;
-            
         }
         $this->_hasInit = true;
-        /*
-        if (method_exists('HTML_FlexyFramework', 'get')) {
-        */    
-            $boot = HTML_FlexyFramework::get();
-           // echo'<PRE>';print_R($boot);exit;
-            $this->appName= $boot->appName;
-            $this->appNameShort= $boot->appNameShort;
-            $this->appModules= $boot->enable;
-            $this->isDev = true; //empty($opts['isDev']) ? '' : $opts['isDev'];
-            $this->appDisable = $boot->disable;
-            $this->version = $boot->version;
-        /*    
-        } else {
-            // BC!!!
-           
-            $opts = PEAR::getStaticProperty('Pman', 'options');  
-            
-            $this->isDev = true; //empty($opts['isDev']) ? '' : $opts['isDev'];
-            
-            $this->appName= empty($opts['appName']) ? '' : $opts['appName'];
-            $this->appNameShort= empty($opts['appNameShort']) ? '' : $opts['appNameShort'];
-            $this->appModules= $opts['enable'];
-            $this->appDisable = $opts['disable'];
-            $this->version = isset($opts['version']) ? $this->version : $opts['version'];
+          
+        $boot = HTML_FlexyFramework::get();
+        // echo'<PRE>';print_R($boot);exit;
+        $this->appName= $boot->appName;
+        $this->appNameShort= $boot->appNameShort;
+        $this->appModules= $boot->enable;
+        $this->isDev = empty($boot->Pman['isDev']) ? false : $boot->Pman['isDev'];
+        $this->appDisable = $boot->disable;
+        $this->version = $boot->version;
+        
+        if (!empty($ff->Pman['local_autoauth']) && 
+            ($_SERVER['SERVER_ADDR'] == '127.0.0.1') &&
+            ($_SERVER['REMOTE_ADDR'] == '127.0.0.1') 
+        ) {
+            $this->isDev = true;
         }
-        */
+        
+
     }
     
     function get($base) 
@@ -116,6 +107,9 @@ class Pman extends HTML_FlexyFramework_Page
         }
         // getting this to work with xhtml is a nightmare
         // = nbsp / <img> issues screw everyting up.
+         //var_dump($this->isDev);
+        // force regeneration on load for development enviroments..
+        HTML_FlexyFramework::get()->generateDataobjectsCache($this->isDev);
         
         //header('Content-type: application/xhtml+xml; charset=utf-8');
         header('Content-type: text/html; charset=utf-8');
@@ -142,7 +136,10 @@ class Pman extends HTML_FlexyFramework_Page
     }
     function staticGetAuthUser()
     {
-        $u = DB_DataObject::factory('Person');
+        $ff = HTML_FlexyFramework::get();
+        $tbl = empty($ff->Pman['authTable']) ? 'Person' : $ff->Pman['authTable'];
+        
+        $u = DB_DataObject::factory($tbl);
         if (!$u->isAuth()) {
             return false;
         }
@@ -153,8 +150,10 @@ class Pman extends HTML_FlexyFramework_Page
         if (!empty($this->authUser)) {
             return $this->authUser;
         }
+        $ff = HTML_FlexyFramework::get();
+        $tbl = empty($ff->Pman['authTable']) ? 'Person' : $ff->Pman['authTable'];
         
-        $u = DB_DataObject::factory('Person');
+        $u = DB_DataObject::factory( $tbl );
         if (!$u->isAuth()) {
             return false;
         }
@@ -446,6 +445,13 @@ class Pman extends HTML_FlexyFramework_Page
         exit;
         
     }
+    /**
+     * output data for grids or tree
+     * @ar {Array} ar Array of data
+     * @total {Number|false} total number of records (or false to return count(ar)
+     * @extra {Array} extra key value list of data to pass as extra data.
+     * 
+     */
     function jdata($ar,$total=false, $extra=array())
     {
         // should do mobile checking???
@@ -455,9 +461,10 @@ class Pman extends HTML_FlexyFramework_Page
         $extra=  $extra ? $extra : array();
         require_once 'Services/JSON.php';
         $json = new Services_JSON();
-        echo $json->encode(array('success' =>  true, 'total'=> $total, 'data' => $ar) + $extra);
+        echo $json->encode(array('success' =>  true, 'total'=> $total, 'data' => $ar) + $extra);    
         exit;
         
+        
     }
     
     
@@ -481,8 +488,15 @@ class Pman extends HTML_FlexyFramework_Page
         array_unshift($mods,   'Core');
         $mods = array_unique($mods);
         
+        
+        $disabled =  explode(',', $this->appDisable ? $this->appDisable: '');
+        
         foreach($mods as $mod) {
             // add the css file..
+            if (in_array($mod, $disabled)) {
+                continue;
+            }
+            
             
             $files = $this->moduleJavascriptList($mod.'/widgets');
             foreach($files as $f) {
@@ -523,23 +537,41 @@ class Pman extends HTML_FlexyFramework_Page
     
     function moduleJavascriptList($mod)
     {
+        
+        $ff = HTML_FlexyFramework::get();
+        
         $dir =   $this->rootDir.'/Pman/'. $mod;
             
         $path =    $this->rootURL."/Pman/$mod/";
         $base = dirname($_SERVER['SCRIPT_FILENAME']);
-        $cfile = realpath($base .'/_compiled_/' . $mod . '.js');
-        $lfile = realpath($base .'/_translations_/' . $mod . '.js');
+        $cfile = realpath($base .'/_compiled_/' . $mod);
+        $lfile = realpath($base .'/_translations_/' . $mod .  '.js');
         //    var_dump($cfile);
         if (!file_exists($dir)) {
+        
             return array();
         }
         $dh = opendir($dir);
         $maxtime = 0;
         $ctime = 0;
+        $files = array();
         if (file_exists($cfile)) {
            // $ctime = max(filemtime($cfile), filectime($cfile));
             // otherwise use compile dfile..
-            $files = array( $this->rootURL."/_compiled_/". basename($cfile));
+            $maxm = 0;
+            $ar = glob($cfile . '/' . $mod . '*.js');
+            // default to first..
+            $cfile = basename($ar[count($ar) -1]);
+            foreach($ar as $fn) {
+                if (filemtime($fn) > $maxm) {
+                    $cfile = basename($fn);
+                    $maxm = filemtime($fn);
+                }
+                
+            }
+            
+             
+            $files = array( $this->rootURL. "/_compiled_/".$mod . "/" . $cfile);
             if (file_exists($lfile)) {
                 array_push($files, $this->rootURL."/_translations_/$mod.js");
             }
@@ -547,7 +579,9 @@ class Pman extends HTML_FlexyFramework_Page
         }
         // works out if stuff has been updated..
         // technically the non-dev version should output compiled only?!!?
+        
         while (false !== ($f = readdir($dh))) {
+           // var_dump($f);
             if (!preg_match('/\.js$/', $f)) {
                 continue;
             }
@@ -556,6 +590,9 @@ class Pman extends HTML_FlexyFramework_Page
             $maxtime = max(filemtime($dir . '/'. $f), $maxtime);
             $files[] = $path . $f;
         }
+        if (empty($files)) {
+            return $files;
+        }
        // var_dump(array($maxtime , $ctime)); 
         //if ($maxtime > $ctime) {
             $lsort = create_function('$a,$b','return strlen($a) > strlen($b) ? 1 : -1;');
@@ -563,6 +600,7 @@ class Pman extends HTML_FlexyFramework_Page
            // if (file_exists($lfile)) {
            //     array_unshift($files, $this->rootURL."/_translations_/$mod.js");
             //}
+            //var_dump($files);
             return $files;
        // }
         
@@ -581,15 +619,37 @@ class Pman extends HTML_FlexyFramework_Page
     function addEvent($act, $obj = false, $remarks = '') {
         $au = $this->getAuthUser();
         $e = DB_DataObject::factory('Events');
+        
+        if (is_a($e, 'PEAR_Error')) {
+            return; // no event table!
+        }
         $e->person_name = $au ? $au->name : '';
         $e->person_id = $au ? $au->id : '';
         $e->event_when = date('Y-m-d H:i:s');
-        $e->ipaddr = $_SERVER["REMOTE_ADDR"];
+        $e->ipaddr = isset($_SERVER["REMOTE_ADDR"]) ? $_SERVER["REMOTE_ADDR"] : 'cli';
         $e->action = $act;
         $e->on_table = $obj ? $obj->tableName() : '';
-        $e->on_id  = $obj ? $obj->id : 0;
+        
+        $pk = $obj ? $obj->keys()  : false;
+    
+        $e->on_id  = $obj && $pk ? $obj->{$pk[0]}: 0;
         $e->remarks = $remarks;
-        $e->insert();
+        $eid = $e->insert();
+        $ff  = HTML_FlexyFramework::get();
+        if (empty($ff->Pman['event_log_dir'])) {
+            return;
+        }
+        $file = $ff->Pman['event_log_dir']. date('/Y/m/d/'). $eid . ".php";
+        if (!file_exists(dirname($file))) {
+            mkdir(dirname($file),0700,true);
+        }
+        file_put_contents($file, var_export(array(
+            'REQUEST_URI' => $_SERVER['REQUEST_URI'],
+            'GET' => empty($_GET) ? array() : $_GET,
+            'POST' => empty($_POST) ? array() : $_POST,
+        ), true));
+        
+        
         
     }