Pman/Images.php
[Pman.Base] / Pman.php
index 33bd600..4a79931 100644 (file)
--- a/Pman.php
+++ b/Pman.php
@@ -24,6 +24,7 @@
 class Pman extends HTML_FlexyFramework_Page 
 {
     var $appName= "";
+    var $appLogo= "";
     var $appShortName= "";
     var $appVersion = "1.8";
     var $version = 'dev';
@@ -64,6 +65,8 @@ class Pman extends HTML_FlexyFramework_Page
         // 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;
@@ -77,6 +80,9 @@ class Pman extends HTML_FlexyFramework_Page
             $this->isDev = true;
         }
         
+        
+        
+        
     }
     
     function get($base) 
@@ -118,6 +124,15 @@ class Pman extends HTML_FlexyFramework_Page
         HTML_FlexyFramework::get()->generateDataobjectsCache($this->isDev);
         
         //header('Content-type: application/xhtml+xml; charset=utf-8');
+        
+        
+        
+        if ($this->company->logo_id) {
+            $im = DB_DataObject::Factory('Images');
+            $im->get($this->company->logo_id);
+            $this->appLogo = $this->baseURL . '/Images/Thumb/400x100/'. $this->company->logo_id .'/' . $im->filename;
+        }
+        
         header('Content-type: text/html; charset=utf-8');
          
     }
@@ -137,11 +152,11 @@ class Pman extends HTML_FlexyFramework_Page
     {
          
         $this->company = DB_DataObject::Factory('Companies');
-        if ($this->company) { // non-core pman projects
-            return; 
+        if (!is_a($this->company, 'DB_DataObject')) { // non-core pman projects
+            return false
         }
         $this->company->get('comptype', 'OWNER');
-        
+        return $this->company;
     }
     
     
@@ -429,6 +444,11 @@ class Pman extends HTML_FlexyFramework_Page
      */
     function jerrAuth()
     {
+        $au = $this->authUser();
+        if ($au) {
+            // is it an authfailure?
+            $this->jerr("Permission denied to view this resource", array('authFailure' => true));
+        }
         $this->jerr("Not authenticated", array('authFailure' => true));
     }
      
@@ -615,6 +635,14 @@ class Pman extends HTML_FlexyFramework_Page
      */
     function moduleJavascriptFilesInfo($mod)
     {
+        
+        static $cache = array();
+        
+        if (isset($cache[$mod])) {
+            return $cache[$mod];
+        }
+        
+        
         $ff = HTML_FlexyFramework::get();
         
         $base = dirname($_SERVER['SCRIPT_FILENAME']);
@@ -652,24 +680,24 @@ class Pman extends HTML_FlexyFramework_Page
         $tmtime = file_exists($this->rootDir.'/_translations_/'. $smod.'.js')
             ? filemtime($this->rootDir.'/_translations_/'. $smod.'.js') : 0;
         
-        return (object) array(
-            'smod' => $smod,
-            'files' => $files,
-            'filesmtime' => $arfiles,
-            'maxtime' => $maxtime,
-            'compile' => $compile,
+        $cache[$mod]  = (object) array(
+            'smod' =>               $smod, // module name without '/'
+            'files' =>              $files, // list of all files.
+            'filesmtime' =>         $arfiles,  // map of mtime=>file
+            'maxtime' =>            $maxtime, // max mtime
+            'compile' =>            $this->isDev ? false : $compile,
             'translation_file' =>   $base .'/_translations_/' . $smod .  '.js',
-            'translation_mtime' =>   $tmtime,
-            'output' => $output,
-            'translation_data' => preg_replace('/\.js$/', '.__translation__.js', $output),
-            'translation_base' => dirname($dir) . '/',
-            'basedir' => $basedir,
-            'baseurl' => $baseurl,
+            'translation_mtime' =>  $tmtime,
+            'output' =>             $output,
+            'translation_data' =>   preg_replace('/\.js$/', '.__translation__.js', $output),
+            'translation_base' =>   $dir .'/', //prefix of filename (without moudle name))
+            'basedir' =>            $basedir,   
+            'baseurl' =>            $baseurl,
+            'module_dir' =>         $dir,  
         );
+        return $cache[$mod];
     }
-    
-    
-    
+     
     
     /**
      *  moduleJavascriptList: list the javascript files in a module
@@ -705,7 +733,7 @@ class Pman extends HTML_FlexyFramework_Page
         }
         
         $info = $this->moduleJavascriptFilesInfo($mod);
-        print_R($info);
+       
         
           
         if (empty($info->files)) {
@@ -719,18 +747,24 @@ class Pman extends HTML_FlexyFramework_Page
         // suggestions...
         //  public_cache_dir =   /var/www/myproject_cache
         //  public_cache_url =   /myproject_cache    (with Alias apache /myproject_cache/ /var/www/myproject_cache/)
-       
-          
+        
+        // bit of debugging
+        if (!$info->compile) {
+            echo "<!-- Javascript compile turned off (isDev on, or public_cache_dir not set) -->\n";
+            return $info->files;
+        }
         // where are we going to write all of this..
         // This has to be done via a 
-        if ( $info->compile && !file_exists($info->basedir.'/'.$info->output)) {
+        if (!file_exists($info->basedir.'/'.$info->output)) {
             require_once 'Pman/Core/JsCompile.php';
             $x = new Pman_Core_JsCompile();
             
             $x->pack($info->filesmtime,$info->basedir.'/'.$info->output, $info->translation_base);
         }
         
-        if ($info->compile && file_exists($info->basedir.'/'.$info->output) && filesize($info->basedir.'/'.$info->output)) {
+        if (file_exists($info->basedir.'/'.$info->output) &&
+                filesize($info->basedir.'/'.$info->output)) {
+            
             $ret =array(
                 $info->baseurl.'/'. $info->output,
               
@@ -746,7 +780,7 @@ class Pman extends HTML_FlexyFramework_Page
         // give up and output original files...
         
          
-        return $files;
+        return $info->files;
 
         
     }
@@ -763,16 +797,17 @@ class Pman extends HTML_FlexyFramework_Page
      * 
      * @param {String} action  - group/name of event
      * @param {DataObject|false} obj - dataobject action occured on.
-     * @param {String} any remarks 
+     * @param {String} any remarks
+     * @return {false|DB_DataObject} Event object.,
      */
     
     function addEventOnce($act, $obj = false, $remarks = '') 
     {
-        $au = $this->getAuthUser();
+        
         $e = DB_DataObject::factory('Events');
         $e->init($act,$obj,$remarks); 
         if ($e->find(true)) {
-            return;
+            return false;
         }
         return $this->addEvent($act, $obj, $remarks);
     }
@@ -783,21 +818,27 @@ class Pman extends HTML_FlexyFramework_Page
      * @param {String} action  - group/name of event
      * @param {DataObject|false} obj - dataobject action occured on.
      * @param {String} any remarks
-     * @return {Number} Event id.,
+     * @return {DB_DataObject} Event object.,
      */
     
     function addEvent($act, $obj = false, $remarks = '') 
     {
         $au = $this->getAuthUser();
+       
         $e = DB_DataObject::factory('Events');
         $e->init($act,$obj,$remarks); 
          
         $e->event_when = date('Y-m-d H:i:s');
         
         $eid = $e->insert();
+        
+        $wa = DB_DataObject::factory('core_watch');
+        $wa->notifyEvent($e); // trigger any actions..
+        
+        
         $ff  = HTML_FlexyFramework::get();
         if (empty($ff->Pman['event_log_dir'])) {
-            return $eid;
+            return $e;
         }
         $file = $ff->Pman['event_log_dir']. date('/Y/m/d/'). $eid . ".php";
         if (!file_exists(dirname($file))) {
@@ -808,8 +849,8 @@ class Pman extends HTML_FlexyFramework_Page
             'GET' => empty($_GET) ? array() : $_GET,
             'POST' => empty($_POST) ? array() : $_POST,
         ), true));
-        
-        return $eid;
+         
+        return $e;
         
     }
     // ------------------ DEPERCIATED ---